[slime-devel] Proper way to bind keys in *slime-description* buffers only
MON KEY
monkey at sandpframing.com
Thu Mar 10 20:24:43 UTC 2011
On Thu, Mar 10, 2011 at 12:53 AM, Sebastian Tennant
<sebyte at smolny.plus.com> wrote:
> Quoth Helmut Eller <heller at common-lisp.net>:
>> * Sebastian Tennant [2011-03-09 08:21] writes:
>>
>>> Hi lispers,
>>>
>>> What's the correct way to bind keys in *slime-description* buffers only?
>>
>> Those buffers are just in fundamental-mode so there is no easy way to do
>> that.
IMO its made more difficult than necessary b/c of slime-eval-describe...
Here is one possibility for achieving the functionality OP requested:
(defun slime-description-view-source-file ()
(interactive)
;; bail if we're not in "*slime description*" buffer
(when (string-equal (buffer-name (current-buffer))
(slime-buffer-name :description))
(let (if-matched)
(save-excursion
(goto-char (point-min))
(and (search-forward-regexp "^[[:blank:]]*?Source file:
\\(/.*\\)$" nil t)
(setq if-matched (match-string 1))))
(and if-matched
(not (or
;; e.g. SBCL's /tmp/file3HfzPd
(null (file-name-extension if-matched))
;; Don't try to look at compiled files
;; Are there other extensions?
(member (file-name-extension if-matched) '("fasl" "fsl"))
;; Paranoia for e.g. /tmp/file3HfzPd
(string-match-p "^/t.?mp" if-matched)))
;; Make sure there is actually a file with that name.
(file-exists-p if-matched)
;; Visiting it in `view-mode' prevents inadverdent edits
(view-file-other-window if-matched)))))
;;; ==============================
;;
;; Following call `slime-eval-describe' when generating/entering the
;; "*slime description*" buffer:
;; `slime-describe-function' `slime-describe-symbol'
;; `slime-documentation' `slime-disassemble-symbol'
;;
;; The call chain has this general form:
;;
;; `slime-eval-describe'
;; `-> `slime-show-description'
;; `-> `slime-with-popup-buffer'
;; `-> `slime-make-popup-buffer'
;;
;; :NOTE `slime-make-popup-buffer' has a `kill-all-local-variables'
;;
;;; ==============================
;;; ==============================
;; We add a new hook variable `*slime-show-description-hook*'
;; Functions added to this hook will automatically be made
;; buffer-local on entry to *slime description*, IOW there is likely
;; little efficacy in doing passing a non-nil value for `add-hook's
;; LOCAL arg e.g.:
;; (add-hook '*slime-show-description-hook* '<MY-FOO> t t)
;;
(defvar *slime-show-description-hook* nil)
;;
;; We add a new function which sets some buffer local variables on
;; entry to the *slime description* buffer
(defun slime-setup-show-description-buffer-locals ()
(when (get-buffer (slime-buffer-name :description))
(with-current-buffer (get-buffer (slime-buffer-name :description))
(set (make-local-variable '*slime-local-show-description-hook*)
'*slime-show-description-hook*)
(run-hooks (buffer-local-value
'*slime-local-show-description-hook* (current-buffer))))))
;;
;; We redefine `slime-show-description' by adding a call to
;; `slime-setup-show-description-buffer-locals'. Note, the added call
;; must happen _after_ `slime-with-popup-buffer'.
;;
;; We local bind the `slime-description-view-source-file' command
;; - I prefer C-c C-f for its mnemomoic congruence with C-x C-f
;; - Uncomment the local-set-key on "\t" if that is what is wanted.
(defun slime-show-description (string package)
(let ((bufname (slime-buffer-name :description)))
(slime-with-popup-buffer (bufname :package package
:connection t
:select slime-description-autofocus)
(princ string)
(goto-char (point-min)))
;; Additions begin here. Note, functions run on the hook will
;; need to recognize `buffer-read-only' if they intend modfifying
;; the *slime description* buffer contents...
(with-current-buffer (get-buffer bufname)
(slime-setup-show-description-buffer-locals)
;; (local-set-key "\t" 'slime-description-view-source-file) )))
(local-set-key "\C-c\C-f" 'slime-description-view-source-file))))
--
/s_P\
More information about the slime-devel
mailing list