[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
find-function-or-variable
From: |
Burton Samograd |
Subject: |
find-function-or-variable |
Date: |
Mon, 12 Nov 2012 19:49:20 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Hi,
I wrote up the following elisp to help with navigating the Emacs code
base. The code makes find-function and find-variable more convenient to
use by binding the new function 'find-function-or-variable' to
'M-.'. Invoking this will push the current location and take you to the
source definition of the function or variable under the point. You can
pop and return the old location by invoking 'M-*'. There is also some
code to setup these keybindings when entering emacs-lisp-mode.
(defvar find-function-or-variable-ring-size 16)
(defvar find-function-or-variable-ring
(make-ring find-function-or-variable-ring-size))
(defun find-function-or-variable ()
"Go to the definition of the Emacs lisp function or variable
that is under the point. The location where this function is
invoked will be saved on a ring and can be returned to using
pop-find-function-or-variable-location."
(interactive)
(let* ((thing (thing-at-point 'symbol))
(symbol (and thing (intern thing)))
(marker (make-marker)))
(when symbol
(set-marker marker (point))
(ring-insert find-function-or-variable-ring marker)
(if (functionp symbol)
(find-function symbol)
(find-variable symbol)))))
(defun pop-find-function-or-variable-location ()
"Pop and return to the previous location that
find-function-or-variable was invoked."
(interactive)
(when (ring-empty-p find-function-or-variable-ring)
(error "No previous find-function or find-variable locations to return
to."))
(let ((marker (ring-remove find-function-or-variable-ring)))
(switch-to-buffer (or (marker-buffer marker)
(error "The marked buffer has been deleted")))
(goto-char (marker-position marker))
(set-marker marker nil nil)))
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(local-set-key "\M-." 'find-function-or-variable)
(local-set-key "\M-*" 'return-from-find-function-or-variable)))
--
Burton Samograd
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- find-function-or-variable,
Burton Samograd <=