Skip to content

Instantly share code, notes, and snippets.

@bowbow99
Created October 31, 2012 16:04
Show Gist options
  • Save bowbow99/3987914 to your computer and use it in GitHub Desktop.
Save bowbow99/3987914 to your computer and use it in GitHub Desktop.
#xyzzy lisp なバッファの *buffer-package* を保存時に設定とか
;;;;; set *buffer-package*
(defparameter *lisp-mode-family* '(lisp-mode lisp-interaction-mode)
"lisp-mode な感じのメジャーモードたち(あちこちで定義してる気がする...)")
(defun find-buffer-package-from-magic-comment ()
"-*- ... package: PACKAGE -*- を拾ってくる"
(cdr (assoc "package" (ed::find-file-scan-params) :test #'string-equal)))
(defun set-buffer-package (&optional (package (find-buffer-package-from-magic-comment)))
"lisp-mode などで参照するバッファ毎の現在のパッケージをセットする。"
(interactive "sPackage: "
:default0 (or (find-buffer-package-from-magic-comment)
*buffer-package*))
(check-type package string)
(setf *buffer-package* package))
(defun set-buffer-package-on-save ()
"lisp-mode 等で、-*- .. Package: PACKAGE -*- があればセットする。
*after-save-buffer-hook* 等から実行する用。"
(when (member buffer-mode *lisp-mode-family*)
(let ((package (find-buffer-package-from-magic-comment)))
(when package
(setf *buffer-package* package)))))
(add-hook '*after-save-buffer-hook* 'set-buffer-package-on-save)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment