fix: find-function-search-for-symbol moving cursor

For symbols defined in the current buffer, for Emacs 29+ users.
This commit is contained in:
Henrik Lissner 2022-06-04 14:58:46 +02:00
parent f96c666460
commit bea3cc161c
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -555,7 +555,27 @@ files, so this replace calls to `pp' with the much faster `prin1'."
(button-type-put (button-type-put
var-bt 'action var-bt 'action
(lambda (button) (lambda (button)
(helpful-variable (button-get button 'apropos-symbol))))))) (helpful-variable (button-get button 'apropos-symbol))))))
(when EMACS29+
;; REVIEW This should be reported upstream to Emacs.
(defadvice! doom--find-function-search-for-symbol-save-excursion-a (fn &rest args)
"Suppress cursor movement by `find-function-search-for-symbol'.
Addresses an unwanted side-effect in `find-function-search-for-symbol' on Emacs
29 where the cursor is moved to a variable's definition if it's defined in the
current buffer."
:around #'find-function-search-for-symbol
(let (buf pos)
(letf! (defun find-library-name (library)
(let ((filename (funcall find-library-name library)))
(with-current-buffer (find-file-noselect filename)
(setq buf (current-buffer)
pos (point)))
filename))
(prog1 (apply fn args)
(when (buffer-live-p buf)
(with-current-buffer buf (goto-char pos)))))))))
;;;###package imenu ;;;###package imenu