lispxmp - 敢えて言おう lisp-interaction-mode はカスであると
過激なタイトルだがあまり真に受けないようにw
eval-last-sexpフェチ発見。俺も含めてけっこうレアかもしれないな。
俺はさらにその考え方を推し進めてeval-last-sexpの評価結果を右横に書き込むようにしている。いわゆるxmpである。rubyistでxmpfilterを使っている人ならおなじみ。
以下のコードを評価すればemacs-lisp-modeでC-c C-eを押せばlispxmp-emacs-lispが実行できる。C-x C-eと同じような感覚で実行できるようにC-c C-eだ。ついでにSLIMEでもできるようにしてある。
(defun %lispxmp-doit (eval-last-sexp-function) (let ((comment-start ";")) (comment-kill nil) (comment-indent) (save-excursion (let ((current-prefix-arg t)) (call-interactively eval-last-sexp-function))) (insert " => "))) (defun lispxmp-emacs-lisp () (interactive) (%lispxmp-doit 'eval-last-sexp)) (defun lispxmp-slime () (interactive) (%lispxmp-doit 'slime-eval-last-expression)) (define-key emacs-lisp-mode-map "\C-c\C-e" 'lispxmp-emacs-lisp) (define-key slime-mode-map "\C-c\C-e" 'lispxmp-slime)
実行例はこんな感じ。
(+ 1 3) ; => 4 (#o4, #x4) (find-file-noselect "~/.emacs") ; => #<buffer .emacs>