From dc9337aacd682b6346b7918ec9b3067e3a06269b Mon Sep 17 00:00:00 2001 From: Stephen Berman Date: Mon, 6 Jun 2022 16:11:50 +0200 Subject: [PATCH] Allow using xref buttons in non-*Help* buffers * lisp/help-mode.el (help-buffer): Allow using the xref buttons in non-*Help* buffers (bug#8147) (but display the result in a *Help* buffer). --- lisp/help-mode.el | 17 ++++++++--------- test/lisp/help-mode-tests.el | 5 ----- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lisp/help-mode.el b/lisp/help-mode.el index 2fcb8b9f3e6..a50524253ba 100644 --- a/lisp/help-mode.el +++ b/lisp/help-mode.el @@ -515,17 +515,16 @@ restore it properly when going back." ;;;###autoload (defun help-buffer () "Return the name of a buffer for inserting help. -If `help-xref-following' is non-nil, this is the name of the -current buffer. Signal an error if this buffer is not derived -from `help-mode'. +If `help-xref-following' is non-nil and the current buffer is +derived from `help-mode', this is the name of the current buffer. + Otherwise, return \"*Help*\", creating a buffer with that name if it does not already exist." - (buffer-name ;for with-output-to-temp-buffer - (if (not help-xref-following) - (get-buffer-create "*Help*") - (unless (derived-mode-p 'help-mode) - (error "Current buffer is not in Help mode")) - (current-buffer)))) + (buffer-name ;for with-output-to-temp-buffer + (if (and help-xref-following + (derived-mode-p 'help-mode)) + (current-buffer) + (get-buffer-create "*Help*")))) (defvar describe-symbol-backends `((nil ,#'fboundp ,(lambda (s _b _f) (describe-function s))) diff --git a/test/lisp/help-mode-tests.el b/test/lisp/help-mode-tests.el index b5bdf6b8d49..04241f31383 100644 --- a/test/lisp/help-mode-tests.el +++ b/test/lisp/help-mode-tests.el @@ -41,11 +41,6 @@ (should (equal (buffer-name (current-buffer)) (help-buffer)))))) -(ert-deftest help-mode-tests-help-buffer-current-buffer-error () - (with-temp-buffer - (let ((help-xref-following t)) - (should-error (help-buffer))))) - (ert-deftest help-mode-tests-make-xrefs () (with-temp-buffer (insert "car is a built-in function in ‘C source code’. -- 2.39.2