SLIMEからCommon Lispを使っているとき、Finderでディレクトリを開きたいことがよくあります。SLIME REPLのShortcutを使ってそれを実現してみます。
SLIME REPLのShortcut機能
SLIME REPLにはShortcutというコマンドセットがあります。Shortcutを呼び出すには、REPLプロンプトで","を押してからShortcut名を入力します。Shortcutには、カレントディレクトリの変更などのコマンドが定義されていますが、残念ながらOS側でディレクトリを開くコマンドは定義されていません。そこで、Shortcutを独自定義して、それを使ってFinderでディレクトリを開けるようにしてみます。
Shortcutの独自定義
SLIME REPLのコードは、slime/contrib/slime-repl.elにあります。この中で、Shortcutは、defslime-repl-shortcutというマクロを使って定義されています。これを使って、ディレクトリを開くShortcutを定義することにします。slime/内のファイルを変更したくないので、.emacsに以下のコードを追記します。
;; SLIME open-directory short cut
(defun slime-open-directory (directory)
"open DIRECTORY with Finder"
(interactive (list (read-directory-name "Directory: " nil nil t)))
(let ((dir (expand-file-name directory)))
(call-process "open" nil nil nil dir)
(message "opened: %s" dir)))
(defslime-repl-shortcut nil ("open-directory" "open")
(:handler 'slime-open-directory)
(:one-liner "Open a directory with Finder"))これで、SLIME REPLから"," + openで、任意のディレクトリをFinderを使って開くことができるようになります。
--