From c889540cec266e51dc4ae97d36581cc1328edc5c Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Thu, 22 May 2025 17:57:37 -0700 Subject: [PATCH] Eldoc: Run eldoc-display-functions with original buffer (bug#78530) 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 | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el index f9f746ae026..74af5bdcbd6 100644 --- a/lisp/emacs-lisp/eldoc.el +++ b/lisp/emacs-lisp/eldoc.el @@ -5,7 +5,7 @@ ;; Author: Noah Friedman ;; 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)))) -- 2.39.5