Do not buttonize key bindings outside of *Help* buffers

* etc/NEWS: Mention the new variable.

* lisp/apropos.el (apropos-describe-plist): Bind the new
variable (bug#52053).
* lisp/button.el (button-describe): Bind the new variable.

* lisp/help-fns.el (describe-function, describe-variable)
(describe-face, describe-symbol, describe-syntax)
(describe-categories, describe-keymap, describe-mode)
(describe-widget): Bind the new variable.

* lisp/help-macro.el (make-help-screen): Bind the new variable.

* lisp/help.el (help-buffer-under-preparation): New variable
that is bound to t by commands that create a *Help* buffer.
(substitute-command-keys): Use the new variable:
help-link-key-to-documentation is supposed to have an effect
only "in *Help* buffers". Fixes bug#52053.
(view-lossage, describe-bindings, describe-key): Bind the new
variable.

* lisp/repeat.el (describe-repeat-maps): Bind the new variable.

* lisp/international/mule-cmds.el (describe-input-method)
(describe-language-environment): Bind the new variable.

* lisp/international/mule-diag.el (describe-character-set)
(describe-coding-system, describe-font, describe-fontset)
((list-fontsets): Bind the new variable.
This commit is contained in:
Gregory Heytings 2021-11-29 15:13:31 +01:00 committed by Lars Ingebrigtsen
parent d8dd705e9d
commit 49422d2e69
9 changed files with 670 additions and 637 deletions

View file

@ -992,6 +992,9 @@ that should be displayed, and the xwidget that asked to display it.
This function is used to control where and if an xwidget stores
cookies set by web pages on disk.
** New variable 'help-buffer-under-preparation'.
This variable is bound to t during the preparation of a *Help* buffer.
* Changes in Emacs 29.1 on Non-Free Operating Systems

View file

@ -1322,6 +1322,7 @@ as a heading."
(defun apropos-describe-plist (symbol)
"Display a pretty listing of SYMBOL's plist."
(let ((help-buffer-under-preparation t))
(help-setup-xref (list 'apropos-describe-plist symbol)
(called-interactively-p 'interactive))
(with-help-window (help-buffer)
@ -1332,7 +1333,7 @@ as a heading."
(put-text-property (+ (point-min) 7) (- (point) 14)
'face 'apropos-symbol)
(insert (apropos-format-plist symbol "\n "))
(princ ")")))
(princ ")"))))
(provide 'apropos)

View file

@ -604,7 +604,8 @@ When called from Lisp, pass BUTTON-OR-POS as the button to describe, or a
buffer position where a button is present. If BUTTON-OR-POS is nil, the
button at point is the button to describe."
(interactive "d")
(let* ((button (cond ((integer-or-marker-p button-or-pos)
(let* ((help-buffer-under-preparation t)
(button (cond ((integer-or-marker-p button-or-pos)
(button-at button-or-pos))
((null button-or-pos) (button-at (point)))
((overlayp button-or-pos) button-or-pos)))

View file

@ -249,7 +249,8 @@ handling of autoloaded functions."
;; calling that.
(let ((describe-function-orig-buffer
(or describe-function-orig-buffer
(current-buffer))))
(current-buffer)))
(help-buffer-under-preparation t))
(help-setup-xref
(list (lambda (function buffer)
@ -1078,7 +1079,8 @@ it is displayed along with the global value."
(if (symbolp v) (symbol-name v))))
(list (if (equal val "")
v (intern val)))))
(let (file-name)
(let (file-name
(help-buffer-under-preparation t))
(unless (buffer-live-p buffer) (setq buffer (current-buffer)))
(unless (frame-live-p frame) (setq frame (selected-frame)))
(if (not (symbolp variable))
@ -1461,6 +1463,7 @@ If FRAME is omitted or nil, use the selected frame."
(interactive (list (read-face-name "Describe face"
(or (face-at-point t) 'default)
t)))
(let ((help-buffer-under-preparation t))
(help-setup-xref (list #'describe-face face)
(called-interactively-p 'interactive))
(unless face
@ -1531,7 +1534,7 @@ If FRAME is omitted or nil, use the selected frame."
(terpri))))
(terpri)
(help-fns--run-describe-functions
help-fns-describe-face-functions f frame))))))
help-fns-describe-face-functions f frame)))))))
(add-hook 'help-fns-describe-face-functions
#'help-fns--face-custom-version-info)
@ -1602,6 +1605,7 @@ current buffer and the selected frame, respectively."
(if found (symbol-name v-or-f)))))
(list (if (equal val "")
(or v-or-f "") (intern val)))))
(let ((help-buffer-under-preparation t))
(if (not (symbolp symbol))
(user-error "You didn't specify a function or variable"))
(unless (buffer-live-p buffer) (setq buffer (current-buffer)))
@ -1638,7 +1642,7 @@ current buffer and the selected frame, respectively."
;; Don't record the `describe-variable' item in the stack.
(setq help-xref-stack-item nil)
(help-setup-xref (list #'describe-symbol symbol) nil))
(goto-char (point-min)))))
(goto-char (point-min))))))
;;;###autoload
(defun describe-syntax (&optional buffer)
@ -1647,6 +1651,7 @@ The descriptions are inserted in a help buffer, which is then displayed.
BUFFER defaults to the current buffer."
(interactive)
(setq buffer (or buffer (current-buffer)))
(let ((help-buffer-under-preparation t))
(help-setup-xref (list #'describe-syntax buffer)
(called-interactively-p 'interactive))
(with-help-window (help-buffer)
@ -1655,7 +1660,7 @@ BUFFER defaults to the current buffer."
(describe-vector table 'internal-describe-syntax-value)
(while (setq table (char-table-parent table))
(insert "\nThe parent syntax table is:")
(describe-vector table 'internal-describe-syntax-value))))))
(describe-vector table 'internal-describe-syntax-value)))))))
(defun help-describe-category-set (value)
(insert (cond
@ -1672,6 +1677,7 @@ The descriptions are inserted in a buffer, which is then displayed.
If BUFFER is non-nil, then describe BUFFER's category table instead.
BUFFER should be a buffer or a buffer name."
(interactive)
(let ((help-buffer-under-preparation t))
(setq buffer (or buffer (current-buffer)))
(help-setup-xref (list #'describe-categories buffer)
(called-interactively-p 'interactive))
@ -1724,7 +1730,7 @@ BUFFER should be a buffer or a buffer name."
(insert (+ i ?\s) ": " elt "\n"))))
(while (setq table (char-table-parent table))
(insert "\nThe parent category table is:")
(describe-vector table 'help-describe-category-set))))))
(describe-vector table 'help-describe-category-set)))))))
(defun help-fns-find-keymap-name (keymap)
"Find the name of the variable with value KEYMAP.
@ -1778,7 +1784,8 @@ keymap value."
(unless (and km (keymapp (symbol-value km)))
(user-error "Not a keymap: %s" km))
(list km)))
(let (used-gentemp)
(let (used-gentemp
(help-buffer-under-preparation t))
(unless (and (symbolp keymap)
(boundp keymap)
(keymapp (symbol-value keymap)))
@ -1844,6 +1851,7 @@ whose documentation describes the minor mode.
If called from Lisp with a non-nil BUFFER argument, display
documentation for the major and minor modes of that buffer."
(interactive "@")
(let ((help-buffer-under-preparation t))
(unless buffer (setq buffer (current-buffer)))
(help-setup-xref (list #'describe-mode buffer)
(called-interactively-p 'interactive))
@ -1941,7 +1949,7 @@ documentation for the major and minor modes of that buffer."
(with-current-buffer standard-output
(insert ":\n")
(insert fundoc)
(insert (help-fns--list-local-commands)))))))
(insert (help-fns--list-local-commands))))))))
;; For the sake of IELM and maybe others
nil)
@ -1998,7 +2006,8 @@ one of them returns non-nil."
(event-end key))
((eq key ?\C-g) (signal 'quit nil))
(t (user-error "You didn't specify a widget"))))))
(let (buf)
(let (buf
(help-buffer-under-preparation t))
;; Allow describing a widget in a different window.
(when (posnp pos)
(setq buf (window-buffer (posn-window pos))

View file

@ -93,7 +93,8 @@ and then returns."
"Help command."
(interactive)
(let ((line-prompt
(substitute-command-keys ,help-line)))
(substitute-command-keys ,help-line))
(help-buffer-under-preparation t))
(when three-step-help
(message "%s" line-prompt))
(let* ((help-screen ,help-text)

View file

@ -50,6 +50,11 @@
(defvar help-window-old-frame nil
"Frame selected at the time `with-help-window' is invoked.")
(defvar help-buffer-under-preparation nil
"Whether a *Help* buffer is being prepared.
This variable is bound to t during the preparation of a *Help*
buffer.")
(defvar help-map
(let ((map (make-sparse-keymap)))
(define-key map (char-to-string help-char) 'help-for-help)
@ -524,6 +529,7 @@ See `lossage-size' to update the number of recorded keystrokes.
To record all your input, use `open-dribble-file'."
(interactive)
(let ((help-buffer-under-preparation t))
(help-setup-xref (list #'view-lossage)
(called-interactively-p 'interactive))
(with-help-window (help-buffer)
@ -547,7 +553,7 @@ To record all your input, use `open-dribble-file'."
(comment-indent)
(forward-line 1)))
;; Show point near the end of "lossage", as we did in Emacs 24.
(set-marker help-window-point-marker (point)))))
(set-marker help-window-point-marker (point))))))
;; Key bindings
@ -579,6 +585,7 @@ The optional argument BUFFER specifies which buffer's bindings
to display (default, the current buffer). BUFFER can be a buffer
or a buffer name."
(interactive)
(let ((help-buffer-under-preparation t))
(or buffer (setq buffer (current-buffer)))
(help-setup-xref (list #'describe-bindings prefix buffer)
(called-interactively-p 'interactive))
@ -603,7 +610,7 @@ or a buffer name."
;; Hide ^Ls.
(while (search-forward "\n\f\n" nil t)
(put-text-property (1+ (match-beginning 0)) (1- (match-end 0))
'invisible t))))))))
'invisible t)))))))))
(defun where-is (definition &optional insert)
"Print message listing key sequences that invoke the command DEFINITION.
@ -907,7 +914,8 @@ current buffer."
(let ((raw (if (numberp buffer) (this-single-command-raw-keys) buffer)))
(setf (cdar (last key-list)) raw)))
(setq buffer nil))
(let* ((buf (or buffer (current-buffer)))
(let* ((help-buffer-under-preparation t)
(buf (or buffer (current-buffer)))
(on-link
(mapcar (lambda (kr)
(let ((raw (cdr kr)))
@ -1181,6 +1189,7 @@ Otherwise, return a new string."
(delete-char (- end-point (point)))
(let ((key (help--key-description-fontified key)))
(insert (if (and help-link-key-to-documentation
help-buffer-under-preparation
(functionp fun))
;; The `fboundp' fixes bootstrap.
(if (fboundp 'help-mode--add-function-link)

View file

@ -1638,6 +1638,7 @@ If `default-transient-input-method' was not yet defined, prompt for it."
(interactive
(list (read-input-method-name
(format-prompt "Describe input method" current-input-method))))
(let ((help-buffer-under-preparation t))
(if (and input-method (symbolp input-method))
(setq input-method (symbol-name input-method)))
(help-setup-xref (list #'describe-input-method
@ -1661,7 +1662,7 @@ If `default-transient-input-method' was not yet defined, prompt for it."
(let ((elt (assoc input-method input-method-alist)))
(princ (format-message
"Input method: %s (`%s' in mode line) for %s\n %s\n"
input-method (nth 3 elt) (nth 1 elt) (nth 4 elt))))))))))
input-method (nth 3 elt) (nth 1 elt) (nth 4 elt)))))))))))
(defun describe-current-input-method ()
"Describe the input method currently in use.
@ -2162,6 +2163,7 @@ See `set-language-info-alist' for use in programs."
(list (read-language-name
'documentation
(format-prompt "Describe language environment" current-language-environment))))
(let ((help-buffer-under-preparation t))
(if (null language-name)
(setq language-name current-language-environment))
(if (or (null language-name)
@ -2244,7 +2246,7 @@ See `set-language-info-alist' for use in programs."
(insert " " (symbol-name (car aliases)))
(setq aliases (cdr aliases)))
(insert ")\n")))
(setq l (cdr l)))))))))
(setq l (cdr l))))))))))
;;; Locales.

View file

@ -299,6 +299,7 @@ meanings of these arguments."
(defun describe-character-set (charset)
"Display information about built-in character set CHARSET."
(interactive (list (read-charset "Charset: ")))
(let ((help-buffer-under-preparation t))
(or (charsetp charset)
(error "Invalid charset: %S" charset))
(help-setup-xref (list #'describe-character-set charset)
@ -357,7 +358,7 @@ or provided just for backward compatibility." nil)))
(if (nth 2 elt)
(let ((print-length 10) (print-level 2))
(princ (funcall (nth 2 elt) val) (current-buffer))))
(insert ?\n)))))))
(insert ?\n))))))))
;;; CODING-SYSTEM
@ -406,6 +407,7 @@ or provided just for backward compatibility." nil)))
(defun describe-coding-system (coding-system)
"Display information about CODING-SYSTEM."
(interactive "zDescribe coding system (default current choices): ")
(let ((help-buffer-under-preparation t))
(if (null coding-system)
(describe-current-coding-system)
(help-setup-xref (list #'describe-coding-system coding-system)
@ -488,7 +490,7 @@ or provided just for backward compatibility." nil)))
(search-backward (symbol-name (car charsets)))
(help-xref-button 0 'help-character-set (car charsets))
(goto-char (point-max))
(setq charsets (cdr charsets)))))))))))
(setq charsets (cdr charsets))))))))))))
;;;###autoload
(defun describe-current-coding-system-briefly ()
@ -845,7 +847,8 @@ The IGNORED argument is ignored."
(or (and window-system (fboundp 'fontset-list))
(error "No fonts being used"))
(let ((xref-item (list #'describe-font fontname))
font-info)
font-info
(help-buffer-under-preparation t))
(if (or (not fontname) (= (length fontname) 0))
(setq fontname (face-attribute 'default :font)))
(setq font-info (font-info fontname))
@ -1006,6 +1009,7 @@ This shows which font is used for which character(s)."
(list (completing-read
(format-prompt "Fontset" "used by the current frame")
fontset-list nil t)))))
(let ((help-buffer-under-preparation t))
(if (= (length fontset) 0)
(setq fontset (face-attribute 'default :fontset))
(setq fontset (query-fontset fontset)))
@ -1013,7 +1017,7 @@ This shows which font is used for which character(s)."
(called-interactively-p 'interactive))
(with-output-to-temp-buffer (help-buffer)
(with-current-buffer standard-output
(print-fontset fontset t))))
(print-fontset fontset t)))))
(declare-function fontset-plain-name "fontset" (fontset))
@ -1024,6 +1028,7 @@ This shows the name, size, and style of each fontset.
With prefix arg, also list the fonts contained in each fontset;
see the function `describe-fontset' for the format of the list."
(interactive "P")
(let ((help-buffer-under-preparation t))
(if (not (and window-system (fboundp 'fontset-list)))
(error "No fontsets being used")
(help-setup-xref (list #'list-fontsets arg)
@ -1040,12 +1045,13 @@ see the function `describe-fontset' for the format of the list."
(if arg
(print-fontset (car fontsets) nil)
(insert "Fontset: " (car fontsets) "\n"))
(setq fontsets (cdr fontsets))))))))
(setq fontsets (cdr fontsets)))))))))
;;;###autoload
(defun list-input-methods ()
"Display information about all input methods."
(interactive)
(let ((help-buffer-under-preparation t))
(help-setup-xref '(list-input-methods)
(called-interactively-p 'interactive))
(with-output-to-temp-buffer (help-buffer)
@ -1056,7 +1062,7 @@ see the function `describe-fontset' for the format of the list."
(while (re-search-forward
(substitute-command-keys "^ \\([^ ]+\\) (`.*' in mode line)$")
nil t)
(help-xref-button 1 'help-input-method (match-string 1)))))))
(help-xref-button 1 'help-input-method (match-string 1))))))))
(defun list-input-methods-1 ()
(if (not input-method-alist)

View file

@ -515,6 +515,7 @@ See `describe-repeat-maps' for a list of all repeatable commands."
Used in `repeat-mode'."
(interactive)
(require 'help-fns)
(let ((help-buffer-under-preparation t))
(help-setup-xref (list #'describe-repeat-maps)
(called-interactively-p 'interactive))
(let ((keymaps nil))
@ -539,7 +540,7 @@ Used in `repeat-mode'."
(where-is-internal (nth 3 info) map))
", ")))
(princ (format-message " `%s' (bound to %s)\n" command desc))))
(princ "\n"))))))
(princ "\n")))))))
(provide 'repeat)