Skip to content

Instantly share code, notes, and snippets.

Created March 8, 2009 07:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/75589 to your computer and use it in GitHub Desktop.
Save anonymous/75589 to your computer and use it in GitHub Desktop.
;; EmacsLisp開発環境をSLIMEのそれに近づけてみる
;; http://fixdap.com/p/slimy-hackathon-01/25211/
;; ・SLIMEのコマンドに対応するelispのコマンドがあるかどうかを調べる。なければ作る。
;; (例: slime-load-file <-> load-file)
;; ・キーバインドをそれっぽくする。
(require 'ielm) ; REPL
(require 'eldoc)
(add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)
;; Emacs23のeldocなら対応する仮引数がハイライトされる => slime-autodoc.el
;; http://d.hatena.ne.jp/rubikitch/20090207/1233936430
;; http://zchan.homeunix.net/pub/Nevada.APP/Build/emacs-23.0.60/lisp/emacs-lisp/eldoc.el
(require 'trace)
(require 'disass)
(eval-when-compile (require 'cl))
(defun compile-and-load-file ()
(interactive)
(byte-compile-file (or (buffer-file-name)
(error "ファイル名がありません: %s" (selected-buffer)))
t))
(defun ielm-closing-return ()
(interactive)
(goto-char (point-max))
(save-excursion
(narrow-to-region (process-mark (get-buffer-process (current-buffer))) (point))
(while (ignore-errors (save-excursion (backward-up-list 1)) t)
(insert ")")))
(ielm-return))
(defun apropos-all (pattern)
(interactive (list (apropos-read-pattern "symbol")))
(apropos pattern t))
(defvar *elisp-macroexpand-require-cl-function* t)
;; (setq *elisp-macroexpand-require-cl-function* t)
;; (setq *elisp-macroexpand-require-cl-function* nil)
;; *** EmacsLispで使えるCommonLispマクロはマクロ展開に専用の関数があるのでややこしい
;;; 例: *elisp-macroexpand-require-cl-function* の値を設定して
;;; 下のS式のそれぞれ "do*" "dotimes" あたりで elisp-macroexpand-{1,all}
;; (do* ((c 0 (1+ c)) (acc nil (cons c acc))) ((>= c 10) (nreverse acc)))
;; (let ((acc nil)) (dotimes (i 10 (nreverse acc)) (push i acc)))
(defun elisp-macroexpand-1 (&optional repeatedly)
(interactive "P")
(let ((form (car (save-excursion
(read-from-string
(buffer-substring (progn
(unless (char-equal (following-char) ?\()
(up-list -1))
(point))
(progn
(forward-list)
(point)))
;; もしくは (thing-at-point 'list)
))))
(print-circle t)
(temp-buffer-setup-hook '(emacs-lisp-mode))
;; 色付けがなぜ効かない?
(temp-buffer-show-hook '(font-lock-fontify-buffer)))
(if (null form) (return-from elisp-macroexpand-1))
(with-output-to-temp-buffer " *ELISP macroexpantion*"
(princ (with-temp-buffer
(if *elisp-macroexpand-require-cl-function*
(cl-prettyexpand form repeatedly)
(cl-prettyprint (funcall (if repeatedly
#'cl-macroexpand-all
#'macroexpand)
form)))
(buffer-string))))))
(defun elisp-macroexpand-all ()
(interactive)
(elisp-macroexpand-1 t))
(dolist (keymap (list emacs-lisp-mode-map
lisp-interaction-mode-map
ielm-map))
(define-key keymap "\C-c\C-m" 'elisp-macroexpand-1)
(define-key keymap "\C-c\M-m" 'elisp-macroexpand-all))
;;; (slime-repl-mode . ielm-mode)
'((slime-repl-bol . move-beginning-of-line) ; C-a (<home>)
(slime-repl-eol . move-end-of-line) ; C-e
(slime-indent-and-complete-symbol . comint-dynamic-complete) ; TAB
(slime-repl-newline-and-indent . nil) ; C-j
(slime-repl-return . ielm-return) ; RET (<return>)
(slime-space . nil) ; SPC
(slime-handle-repl-shortcut . nil) ; ,
(slime-repl-forward-input . comint-next-input) ; <C-down>
(slime-repl-closing-return . 'ielm-closing-return) ; <C-return> (M-RET)
(slime-repl-backward-input . comint-previous-input) ; <C-up>
(slime-eval-last-expression . eval-last-sexp) ; C-x C-e
(slime-interactive-eval . eval-expression) ; C-c C-e (C-c :)
(slime-interrupt . nil) ; C-c C-b .. C-c C-c
(slime-describe-function . describe-function) ; C-c C-e
(slime-complete-symbol . lisp-complete-symbol) ; C-c TAB (M-TAB)
(slime-compile-and-load-file . compile-and-load-file) ; C-c C-k
(slime-load-file . load-file) ; C-c C-l
(slime-macroexpand-1 . elisp-macroexpand-1) ; C-c RET
(slime-repl-next-prompt . comint-next-prompt) ; C-c C-n
(slime-repl-clear-output . comint-delete-output) ; C-c C-o
(slime-repl-previous-prompt . comint-previous-prompt) ; C-c C-p
(slime-eval-region . eval-region) ; C-c C-r
(slime-complete-form . nil) ; C-c C-s
(slime-toggle-trace-fdefinition . trace-function) ; C-c C-t
(slime-repl-kill-input . comint-kill-input) ; C-c C-u
(slime-nop . undefined) ; C-c C-z
(slime-close-all-parens-in-sexp . slime-close-all-parens-in-sexp) ; C-c C-] (そのまま使えそう)
(slime-list-callers . nil) ; C-c <
(slime-list-callees . nil) ; C-c >
(slime-edit-value . set-variable) ; C-c E
(slime-inspect . nil) ; C-c I
(slime-sync-package-and-default-directory . nil) ; C-c ~
(slime-eval-defun . eval-defun) ; C-M-x (eval-defun-{1,2}?)
(slime-pop-find-definition-stack . nil) ; M-,
(slime-edit-definition . find-function-at-point) ; M-.
(slime-repl-next-input . comint-next-input) ; M-n
(slime-repl-previous-input . comint-previous-input) ; M-p
(slime-repl-previous-matching-input . comint-previous-matching-input) ; M-r
(slime-repl-next-matching-input . comint-next-matching-input) ; M-s
(slime-next-location . nil) ; C-M-.
(slime-eval-last-expression-display-output . eval-last-sexp-print-value) ; C-x M-e
(slime-edit-definition-other-frame . find-function-other-frame) ; C-x 5 .
(slime-edit-definition-other-window . find-function-other-frame) ; C-x 4 .
;; slime-***-presentation (C-c C-v *)
(slime-who-specializes . nil) ; C-c C-w C-a
(slime-who-binds . nil) ; C-c C-w C-b
(slime-who-calls . nil) ; C-c C-w C-c
(slime-who-macroexpands . nil) ; C-c C-w RET
(slime-who-references . nil) ; C-c C-w C-r
(slime-who-sets . nil) ; C-c C-w C-s
(slime-calls-who . nil) ; C-c C-w C-w
(slime-who-specializes . nil) ; C-c C-w a
(slime-who-binds . nil) ; C-c C-w b
(slime-who-calls . nil) ; C-c C-w c
(slime-who-macroexpands . nil) ; C-c C-w m
(slime-who-references . nil) ; C-c C-w r
(slime-who-sets . nil) ; C-c C-w s
(slime-calls-who . nil) ; C-c C-w w
(slime-apropos . apropos) ; C-c C-d C-a (C-c C-d a)
(slime-describe-symbol . nil) ; C-c C-d C-d (C-c C-d d)
(slime-describe-function . describe-function) ; C-c C-d C-f (C-c C-d f)
(slime-apropos-package . nil) ; C-c C-d C-p (C-c C-d p)
(slime-apropos-all . apropos-all) ; C-c C-d C-z (C-c C-d z)
(slime-hyperspec-lookup . nil) ; C-c C-d h
(common-lisp-hyperspec-format . nil) ; C-c C-d ~ (C-c C-d C-~)
(slime-list-connections . nil) ; C-c C-x c
(slime-list-threads . nil) ; C-c C-x t
(slime-restore-window-configuration . undefined) ; C-c M-0
(slime-disassemble-symbol . disassemble) ; C-c M-d
(slime-quit . keyboard-quit) ; C-c M-g
(slime-macroexpand-all . elisp-macroexpand-all) ; C-c M-m
(slime-repl-clear-buffer . nil) ; C-c M-o
(slime-repl-set-package . nil) ; C-c M-p
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment