Paste number 90573: M-. for elisp

Paste number 90573: M-. for elisp
Pasted by: stassats
When:9 months, 2 weeks ago
Share:Tweet this! | http://paste.lisp.org/+1XVX
Channel:#lisp
Paste contents:
Raw Source | XML | Display As
(defvar *jump-locations* nil)

(defun find-fun-location (name)
  (save-excursion
    (let* ((function (symbol-function name))
           (file-name (find-lisp-object-file-name name function)))
      (when (eq file-name 'C-source)
        (setq file-name (help-C-file-name function 'subr)))
      (find-function-search-for-symbol name nil file-name))))

(defun jump-to-fdefinition (fn)
  (interactive
   (list (or (function-called-at-point)
             (intern (completing-read "Find function: "
                                      obarray 'fboundp t nil nil)))))
  (let ((location (find-fun-location fn)))
    (if (cdr location)
        (progn
          (push (point-marker) *jump-locations*)
          (pop-to-buffer (car location))
          (goto-char (cdr location)))
        (message "Unable to find location"))))

(defun jump-back ()
  (interactive)
  (let ((location (pop *jump-locations*)))
    (when location
      (pop-to-buffer (marker-buffer location))
      (goto-char location)
      (set-marker location nil))))

(require 'ielm)

(dolist (mode (list emacs-lisp-mode-map ielm-map))
  (define-key mode "\M-." 'jump-to-fdefinition)
  (define-key mode "\M-," 'jump-back))

This paste has no annotations.

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.