2009/09/05

Clojure のセットアップ

Clojure をセットアップする。 Debian にはパッケージがあったので apt-get する。 Emacs + SLIME のために git clone を2つ。

sudo apt-get install clojure
cd ~/letter/clojure/lib
git clone git://github.com/jochu/clojure-mode.git
git clone git://github.com/jochu/swank-clojure.git

~/.emacs に clojure-mode と swank-clojure の設定を追加。

(setq slime-net-coding-system 'utf-8-unix)
;;;; Clojure
;; clojure-mode
(add-path "~/letter/clojure/lib/clojure-mode")
(require 'clojure-mode)
;; swank-clojure
(add-path "~/letter/clojure/lib/swank-clojure/src/emacs")
(setq swank-clojure-jar-path "~/letter/clojure/git/clojure/clojure.jar")
(require 'swank-clojure-autoload)
(setq swank-clojure-extra-classpaths
(list "~/letter/clojure/git/clojure-contrib/clojure-contrib.jar"))

SLIME 自体の設定は省略、と思ったけどついでにのせておこう。

~/.emacs

;;;;;SLIME
(setq common-lisp-hyperspec-root "file:/usr/share/doc/hyperspec/")
(add-path "~/letter/lisp/clbuild/source/slime")
(add-path "~/letter/lisp/clbuild/source/slime/contrib")
;;(setq slime-communication-style :fd-handler)
;;(setq slime-communication-style :spawn)
;;(setq slime-communication-style :sigio)
(setq slime-net-coding-system 'utf-8-unix)
(setq slime-lisp-implementations
`((sbcl ("sbcl") :coding-system utf-8-unix)
(ccl ("/home/ancient/local/opt/ccl/lx86cl64")
:coding-system utf-8-unix)
;; (ccl ("/home/ancient/letter/lisp/clbuild/clbuild"
;; "--implementation" "ccl" "lisp")
;; :coding-system utf-8-unix)
(deb-sbcl ("/usr/bin/sbcl") :coding-system utf-8-unix)
(clisp ("/home/ancient/letter/lisp/clbuild/clbuild"
"--implementation" "clisp" "lisp")
:coding-system utf-8-unix)
(abcl ("/home/ancient/letter/lisp/abcl/abcl")
:coding-system utf-8-unix)
(acl ("/home/ancient/local/opt/acl81_express/alisp")
:coding-system utf-8-unix)
(cmucl ("lisp"))))
(require 'slime-autoloads)
;;(add-hook 'lisp-mode-hook
;; (lambda ()
;; (cond ((not (featurep 'slime))
;; (require 'slime)
;; (normal-mode)))))
(setq slime-truncate-lines nil)
(setq slime-enable-evaluate-in-emacs t)
(defun my-slime-complete-form ()
(interactive)
(condition-case nil
(slime-complete-form)
(error
(save-excursion
(insert
(multiple-value-bind (ops arg-indices points)
(slime-enclosing-form-specs)
(run-hook-with-args 'slime-autodoc-hook ops arg-indices points)
(multiple-value-bind (cache-key retrieve-form)
(slime-compute-autodoc-rpc-form ops arg-indices points)
(slime-eval retrieve-form))))))))
(add-hook
'slime-mode-hook
(lambda ()
(global-set-key [(control ?\;)] 'slime-selector)
(define-key slime-mode-map "\C-c\C-s" 'my-slime-complete-form)
(define-key slime-repl-mode-map "\C-c\C-s" 'my-slime-complete-form)
(loop for (key command) in
'(([(control ?c) ?\;] slime-insert-balanced-comments)
([(control ?u) (control ?c) ?\;] slime-remove-balanced-comments)
([(control ?c) ?\;] slime-insert-balanced-comments)
("\C-m" newline-and-indent)
("\C-i" slime-indent-and-complete-symbol))
do (define-key slime-mode-map key command))))
(add-to-list 'auto-mode-alist '("\\.asd$" . common-lisp-mode))
(eval-after-load "slime"
'(progn
(slime-setup '(slime-repl
slime-asdf
slime-fancy
slime-indentation
slime-references
slime-tramp
slime-banner))
(setq slime-complete-symbol*-fancy t)
(setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol)
(setq lisp-indent-function 'cl-indent:function)
;; g000001 さん作
(progn
(defun gcode-lookup ()
"カーソル位置のシンボルをGoogle Codeで検索(lisp決め打ち)"
(interactive)
(browse-url
(format "http://www.google.com/codesearch?q=%s+lang:%s+file:\\.%s$&hl=ja&num=20"
(thing-at-point 'symbol) "lisp" "lisp")))
(define-key slime-mode-map
[(control ?c) (control ?d) ?g] 'gcode-lookup))))

C-- M-x slime clojure

0 件のコメント: