]> git.eshelyaron.com Git - emacs.git/commitdiff
Eldoc: Run eldoc-display-functions with original buffer (bug#78530)
authorYuan Fu <casouri@gmail.com>
Fri, 23 May 2025 00:57:37 +0000 (17:57 -0700)
committerEshel Yaron <me@eshelyaron.com>
Thu, 24 Jul 2025 07:59:20 +0000 (09:59 +0200)
Also bump eldoc version so Eglot can require the new version
later.

* lisp/emacs-lisp/eldoc.el (eldoc--invoke-strategy): Run the
hook with the original buffer as the current buffer. This way
we're certain that the buffer-local value of
'eldoc-display-functions' is used.
(eldoc-display-functions): Update docstring.

(cherry picked from commit b85d9048f4a32c7c50894e991423d021d9f95317)

lisp/emacs-lisp/eldoc.el

index f9f746ae026e74f7c42ca841a77dfa6d09789267..74af5bdcbd64e6ebd1b7cbc155c4b08f5acaa178 100644 (file)
@@ -5,7 +5,7 @@
 ;; Author: Noah Friedman <friedman@splode.com>
 ;; Keywords: extensions
 ;; Created: 1995-10-06
-;; Version: 1.15.0
+;; Version: 1.16.0
 ;; Package-Requires: ((emacs "26.3"))
 
 ;; This is a GNU ELPA :core package.  Avoid functionality that is not
@@ -479,7 +479,11 @@ documentation.  For commonly recognized properties, see
 `eldoc-documentation-functions'.
 
 INTERACTIVE says if the request to display doc strings came
-directly from the user or from ElDoc's automatic mechanisms'.")
+directly from the user or from ElDoc's automatic mechanisms'.
+
+The display functions always run in the source buffer which initiated
+the documentation request.  If the source buffer is killed, the display
+functions just won't run.")
 
 (defvar eldoc--doc-buffer nil "Buffer displaying latest ElDoc-produced docs.")
 
@@ -863,7 +867,8 @@ the docstrings eventually produced, using
          (want 0)
          ;; The doc strings and corresponding options registered so
          ;; far.
-         (docs-registered '()))
+         (docs-registered '())
+         (orig-buffer (current-buffer)))
     (cl-labels
         ((register-doc
           (pos string plist origin)
@@ -871,12 +876,14 @@ the docstrings eventually produced, using
             (push (cons pos (cons string `(:origin ,origin ,@plist)))
                   docs-registered)))
          (display-doc
-          ()
-          (run-hook-with-args
-           'eldoc-display-functions (mapcar #'cdr
-                                            (setq docs-registered
-                                                  (sort docs-registered)))
-           interactive))
+           ()
+           (when (buffer-live-p orig-buffer)
+             (with-current-buffer orig-buffer
+               (run-hook-with-args
+                'eldoc-display-functions (mapcar #'cdr
+                                                 (setq docs-registered
+                                                       (sort docs-registered)))
+                interactive))))
          (make-callback
           (method origin)
           (let ((pos (prog1 howmany (cl-incf howmany))))