2011/01/26

現在の optimize 指定を取得する

SBCL 依存だけど sb-ext:describe-compiler-policy または sb-cltl2:declaration-information で取得できる。

(sb-ext:describe-compiler-policy)
;;-> Basic qualities:
;; COMPILATION-SPEED = 1
;; DEBUG = 3
;; SAFETY = 3
;; SPACE = 1
;; SPEED = 1
;; INHIBIT-WARNINGS = 1
;; Dependent qualities:
;; SB-C::CHECK-CONSTANT-MODIFICATION = 1 -> 3 (yes)
;; SB-C::TYPE-CHECK = 1 -> 3 (full)
;; SB-C::CHECK-TAG-EXISTENCE = 1 -> 3 (yes)
;; SB-C::LET-CONVERSION = 1 -> 0 (off)
;; SB-C:VERIFY-ARG-COUNT = 1 -> 3 (yes)
;; SB-C::MERGE-TAIL-CALLS = 1 -> 0 (no)
;; SB-C::INSERT-DEBUG-CATCH = 1 -> 3 (yes)
;; SB-C::RECOGNIZE-SELF-CALLS = 1 -> 0 (no)
;; SB-C::FLOAT-ACCURACY = 1 -> 3 (full)
;; SB-C:INSERT-STEP-CONDITIONS = 1 -> 3 (full)
;; SB-C::COMPUTE-DEBUG-FUN = 1 -> 3 (yes)
;; SB-C::PRESERVE-SINGLE-USE-DEBUG-VARIABLES = 1 -> 3 (yes)
;; SB-C::INSERT-ARRAY-BOUNDS-CHECKS = 1 -> 3 (yes)
;; SB-C::STORE-XREF-DATA = 1 -> 3 (yes)
;; SB-C:STORE-COVERAGE-DATA = 1 -> 0 (no)
;;
;;=>

(sb-cltl2:declaration-information 'optimize)
;;=> ((COMPILATION-SPEED 1) (DEBUG 3) (SAFETY 3) (SPACE 1) (SPEED 1)
;; (INHIBIT-WARNINGS 1) (SB-C::CHECK-CONSTANT-MODIFICATION 1)
;; (SB-C::TYPE-CHECK 1) (SB-C::CHECK-TAG-EXISTENCE 1) (SB-C::LET-CONVERSION 1)
;; (SB-C:VERIFY-ARG-COUNT 1) (SB-C::MERGE-TAIL-CALLS 1)
;; (SB-C::INSERT-DEBUG-CATCH 1) (SB-C::RECOGNIZE-SELF-CALLS 1)
;; (SB-C::FLOAT-ACCURACY 1) (SB-C:INSERT-STEP-CONDITIONS 1)
;; (SB-C::COMPUTE-DEBUG-FUN 1) (SB-C::PRESERVE-SINGLE-USE-DEBUG-VARIABLES 1)
;; (SB-C::INSERT-ARRAY-BOUNDS-CHECKS 1) (SB-C::STORE-XREF-DATA 1)
;; (SB-C:STORE-COVERAGE-DATA 1))

2011/01/15

CLIM ベースの IRC クライアント beirc

今年は CLIM-desktop を流行っているようなので、 @g000001 さんから #Lisp_Scheme できいた、 CLIM ベースのクライアント beirc を使ってみました。

インストールは Quicklisp で。

(ql:quickload "beirc")

起動はレプルから。

(beirc:beirc)

使い方(コマンド)は CLiki のページが詳しいようですが、次の2つのコマンドがあれば何とかなるでしょう。

  • /Connect server nick
  • /Join channel

~/.beirc.lisp に設定情報を書いおけば起動時に自動的にサーバに接続してくれたりします。また日本語まわりの設定もそのファイルに書いておけばいいかと思います。

~/.beirc.lisp

(in-package :beirc)

;; フォント
(require :mcclim-freetype)

;; uim での日本語入力 https://github.com/quek/mcclim-uim
(require :mcclim-uim)

;;; variables.lisp を参照。

;; 自動的に接続するサーバ
(setq *auto-connect-list* '("irc.freenode.net"))
;; 自動的に join するチャンネル
(setq *auto-join-alist* '(("irc.freenode.net" . ("#lisp" "#Lisp_Scheme"))))

;; ニックネーム
(setq *default-nick* "quek")
(setq *default-realname* "Yoshinori Tahara")

(setq *hyperspec-base-url* "file://localhost/usr/share/doc/hyperspec/")
(setq *default-web-browser* "/usr/bin/opera")

ただ、SBCL だとちょっと問題があるので ~/.sbclcr にその対策もかねて、 beirc 起動用の関数を書いておきます。

(defun beirc ()
"beirc を起動す2。"
(require :beirc)
(eval (read-from-string "
(progn (setf beirc:*beirc-user-init-file* \"~/.beirc.lisp\")
(beirc:beirc))
"
)))

mcclim-uim の微妙さをがまんしてもらえれば、普通に使えます。

ところで CLIM-desktop を見ると Backtrace Dialog, Restarts Dialog とか McCLIM の機能としてあるんですね。

2011/01/11

Common Lisp でパッケージのニックネームを変える

rename-package を使う。

(defun set-package-nicknames (package &rest nicknames)
(rename-package package (package-name package) nicknames))

(defpackage :foo
(:nicknames :bar))

(values (package-name :foo) (package-nicknames :foo))
;;=> "FOO"
;; ("BAR")

(set-package-nickname :foo :baz :baha)
;;=> #<PACKAGE "FOO">

(values (package-name :foo) (package-nicknames :foo))
;;=> "FOO"
;; ("BAHA" "BAZ")

(set-package-nickname :foo)
;;=> #<PACKAGE "FOO">

(values (package-name :foo) (package-nicknames :foo))
;;=> "FOO"
;; NIL

2011/01/09

Climacs に Switch To View Other Window と Find File Other Window を実装

勝手に github に fork して Climacs をいじることにしてみた。 McCLIM も github に勝手に fork した。

https://github.com/LaPingvino/Climacs もあるので、そのうち Pull Request できたらいいと思う。

Emacs の switch-to-buffer-other-window と find-file-other-window 相当を実装した。

window-commands.lisp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Commands for switching/find-file in other window

(define-command (com-switch-to-view-other-window :name t :command-table window-table)
((view 'view :default (or (cadr (views *application-frame*)) (any-view))))
"Prompt for a view name and switch to that view in other window.
If the a view with that name does not exist, create a buffer-view
with the name and switch to it. Uses the name of the next
view (if any) as a default."

(when (= 1 (length (windows *application-frame*)))
(com-split-window-horizontally t))
(com-other-window)
(com-switch-to-view view))

(set-key `(com-switch-to-view-other-window ,*unsupplied-argument-marker*)
'window-table
'((#\x :control) (#\4) (#\b)))

(define-command (com-find-file-other-window :name t :command-table window-table)
((filepath 'pathname
:prompt "Find File in other window: "
:prompt-mode :raw
:default (esa-io::directory-of-current-buffer)
:default-type 'pathname
:insert-default t))
"Prompt for a filename then edit that file in other window.
If a buffer is already visiting that file, switch to that
buffer. Does not create a file if the filename given does not
name an existing file."

(when (= 1 (length (windows *application-frame*)))
(com-split-window-horizontally t))
(com-other-window)
(esa-io:com-find-file filepath))

(set-key `(com-find-file-other-window ,*unsupplied-argument-marker*)
'window-table
'((#\x :control) (#\4) (#\f)))

2011/01/06

Climacs での色(フェイス)の設定

climacs:climacs-rv で起動すると黒背景になる。でも、デフォルトの色付が合わない。そんな場合は次のように各 drawing-options を変更する。

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; lisp height
;;;; climacs:climacs-rv で起動するとデフォルトのフェイスが合わないので。
(in-package :drei-lisp-syntax)

(setf
*string-drawing-options* (make-drawing-options :face (make-face :ink +light-salmon+))
*comment-drawing-options* (make-drawing-options :face (make-face :ink +chocolate1+))
*keyword-drawing-options* (make-drawing-options :face (make-face :ink +light-steel-blue+))
*special-variable-drawing-options* (make-drawing-options :face (make-face :ink +light-goldenrod+))
*special-operator-drawing-options* (make-drawing-options
:face (make-face :ink +cyan1+
:style (make-text-style nil :bold nil))))

simple-date-time のパッチをもらった

たまたま #lisp に接続したら Axioplase さんから simple-date-time について質問された。昨日 Axioplase さんから RFC 2822 のフォーマットで出力するパッチのメールをもらった。この件ではいろいろ嬉しい驚きがあった。

  • 数ヶ月ぶりに #lisp したまさにその時に質問されたこと。
  • simple-date-time を使っている人がいたこと。
  • パッチのメールが綺麗な日本語だったこと。

Axioplase さんありがとうございました。

simple-date-time は cl-win32ole を作るときに日時クラスが必要になって、でちっあげたもの。はなはだ効率の悪い実装になっている。アルゴリズムとか無視だし。申し訳ないです。

2011/01/05

Climacs でビットマップフォントを使った時のフォンサイズ変更

ビットマップフォントを使うというより X のフォント描画を使う場合のフォントサイズは clim-clx::*clx-text-sizes* で指定する。

参考: McCLIM (Climacs) でビットマプフォン使って日本語を表示する

;; X のフォント描画を使う場合のフォント設定
(setq clim-clx::*clx-text-family+face-map*
'(:fix
("*-*"
(:roman "medium-r"
:bold "bold-r"
:italic "medium-o"
:bold-italic "bold-o"
:italic-bold "bold-o"))
:sans-serif
("*-*"
(:roman "medium-r"
:bold "bold-r"
:italic "medium-o"
:bold-italic "bold-o"
:italic-bold "bold-o"))
:serif
("*-*"
(:roman "medium-r"
:bold "bold-r"
:italic "medium-i"
:bold-italic "bold-i"
:italic-bold "bold-i"))))

;; ビットマップでのフォントサイズを 2 ずつ大きくする。
(setq clim-clx::*clx-text-sizes*
'(:normal 16
:tiny 10
:very-small 12
:small 14
:large 20
:very-large 22
:huge 26))

X のフォント描画を使う場合は、次が必要になるかと。

;;; ビットマップフォントで日本語表示するために一行追加する。
(in-package :clim-clx)
(defmethod medium-draw-text* ((medium clx-medium) string x y
start end
align-x align-y
toward-x toward-y transform-glyphs)
(declare (ignore toward-x toward-y transform-glyphs))
(with-transformed-position ((sheet-native-transformation (medium-sheet medium))
x y)
(with-clx-graphics (medium)
(when (characterp string)
(setq string (make-string 1 :initial-element string)))
(when (null end) (setq end (length string)))
(multiple-value-bind (text-width text-height x-cursor y-cursor baseline)
(text-size medium string :start start :end end)
(declare (ignore x-cursor y-cursor))
(unless (and (eq align-x :left) (eq align-y :baseline))
(setq x (- x (ecase align-x
(:left 0)
(:center (round text-width 2))
(:right text-width))))
(setq y (ecase align-y
(:top (+ y baseline))
(:center (+ y baseline (- (floor text-height 2))))
(:baseline y)
(:bottom (+ y baseline (- text-height)))))))
(let ((x (round-coordinate x))
(y (round-coordinate y)))
(when (and (<= #x-8000 x #x7FFF)
(<= #x-8000 y #x7FFF))
(multiple-value-bind (halt width)
(xlib:draw-glyphs mirror gc x y string
:start start :end end
:size 16 ; この一行を追加
:translate #'translate)))))))