(describe-mode): Fix bug#80170

* lisp/help-fns.el (describe-mode--minor-modes): Add argument `buffer`.
(describe-mode): Use it to fix call to `documentation` so the
docstrings are computed in the right buffer and thus show
correctly when bindings are shadowed by minor modes.
This commit is contained in:
Stefan Monnier 2026-02-11 15:53:09 -05:00
parent a1e32130de
commit 451d5c6f05

View file

@ -2242,7 +2242,7 @@ is enabled in the Help buffer."
(insert (format "Minor mode%s enabled in this buffer:" (insert (format "Minor mode%s enabled in this buffer:"
(if (length> local-minors 1) (if (length> local-minors 1)
"s" "")))) "s" ""))))
(describe-mode--minor-modes local-minors)) (describe-mode--minor-modes local-minors nil buffer))
;; Document the major mode. ;; Document the major mode.
(let ((major (buffer-local-value 'major-mode buffer))) (let ((major (buffer-local-value 'major-mode buffer)))
@ -2269,7 +2269,9 @@ is enabled in the Help buffer."
(help-function-def--button-function (help-function-def--button-function
major file-name)))))) major file-name))))))
(insert ":\n\n" (insert ":\n\n"
(help-split-fundoc (documentation major) nil 'doc) (help-split-fundoc (with-current-buffer buffer
(documentation major))
nil 'doc)
(with-current-buffer buffer (with-current-buffer buffer
(help-fns--list-local-commands))) (help-fns--list-local-commands)))
(ensure-empty-lines 1) (ensure-empty-lines 1)
@ -2280,7 +2282,7 @@ is enabled in the Help buffer."
(insert (format "Global minor mode%s enabled:" (insert (format "Global minor mode%s enabled:"
(if (length> global-minor-modes 1) (if (length> global-minor-modes 1)
"s" "")))) "s" ""))))
(describe-mode--minor-modes global-minor-modes t) (describe-mode--minor-modes global-minor-modes t buffer)
(unless describe-mode-outline (unless describe-mode-outline
(when (re-search-forward "^\f") (when (re-search-forward "^\f")
(beginning-of-line) (beginning-of-line)
@ -2297,7 +2299,7 @@ is enabled in the Help buffer."
;; For the sake of IELM and maybe others ;; For the sake of IELM and maybe others
nil))))) nil)))))
(defun describe-mode--minor-modes (modes &optional global) (defun describe-mode--minor-modes (modes &optional global buffer)
(dolist (mode (seq-sort #'string< modes)) (dolist (mode (seq-sort #'string< modes))
(let ((pretty-minor-mode (let ((pretty-minor-mode
(capitalize (capitalize
@ -2338,7 +2340,10 @@ is enabled in the Help buffer."
"no indicator" "no indicator"
(format "indicator%s" (format "indicator%s"
indicator))))) indicator)))))
(insert (or (help-split-fundoc (documentation mode) nil 'doc) (insert (or (help-split-fundoc
(with-current-buffer (or buffer (current-buffer))
(documentation mode))
nil 'doc)
"No docstring")) "No docstring"))
(when describe-mode-outline (when describe-mode-outline
(insert "\n\n"))))) (insert "\n\n")))))