0

Emacs is freezing when running the following custom find-function and I'm looking for some assistance, please, to debug it.

I'd like the prefix argument C-u to make the difference between switch-to-buffer-other-window or switch-to-buffer. By removing find-function-read from the interactive statement, that function no longer returns a symbol -- so that is why I am using make-symbol. I did not see an example by Googling that shows how to use an interactive command of "P" and another function such as find-function-read all in the same interactive statement.

(defun my-find-function (arg)
  "Find, in another window, the definition of FUNCTION near point.
See `find-function' for more details."
  (interactive "P")
  (let ((function (make-symbol (format "%s" (car (find-function-read))))))
    (if (eq arg '(4))
      (find-function-do-it function nil 'switch-to-buffer-other-window)
      (find-function-do-it function nil 'switch-to-buffer))))
1

Fixed:

(defun my-find-function (arg)
  "Find, in another window, the definition of FUNCTION near point.
See `find-function' for more details."
  (interactive "p")
  (let* ((thing (thing-at-point 'symbol))
         (function
          (when thing (intern thing))))
    (if (eq arg 4)
      (find-function-do-it function nil 'switch-to-buffer-other-window)
      (find-function-do-it function nil 'switch-to-buffer))))

Note that eq is for numbers and symbols only, not for lists. You can't do this:

(setq x '(1))
(eq x '(1))
;=> nil 
  • 1
    Thank you -- using make-symbol instead of intern is what was making Emacs freeze, and you also hit the nail on the head with needing to use eq with 4, or equal with '(4). Your help is greatly appreciated -- the freezing issues always perplex me because there are no hints to help me debug. – lawlist Dec 27 '14 at 20:08
  • 2
    @lawlist for completeness, make-symbol returns a new uninterned symbol, so find-function would never find it anywhere. – Malabarba Dec 27 '14 at 21:20
  • 1. If the prefix arg is used only for a binary choice, I'd suggest using the raw arg ("P" instead of "p") and then testing for nil vs non-nil. To me, that makes for clearer code (but that's the only advantage, and it's not important). 2. The doc string info about other window applies only with a prefix arg. 3. FUNCTION will be nil if there is no symbol at point. That will raise the error You didn't specify a symbol. Is that what you want? – Drew Dec 27 '14 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.