From bea3cc161c0a803dcf574f32ee555dccf565a5ce Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 4 Jun 2022 14:58:46 +0200 Subject: [PATCH] fix: find-function-search-for-symbol moving cursor For symbols defined in the current buffer, for Emacs 29+ users. --- core/core-editor.el | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/core/core-editor.el b/core/core-editor.el index 8bb87c3da..3c9b63194 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -555,7 +555,27 @@ files, so this replace calls to `pp' with the much faster `prin1'." (button-type-put var-bt 'action (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