summaryrefslogtreecommitdiff
path: root/lisp/help-fns.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2022-10-03 21:32:01 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-10-03 21:32:01 +0200
commit71735be475f0e5e72727c567e7344df805206cd5 (patch)
tree903f73c5d9c3d2d6b2700f94ac147618967b20c3 /lisp/help-fns.el
parent4975f6fa535a17c83f1680570671959f1ec452fa (diff)
downloademacs-71735be475f0e5e72727c567e7344df805206cd5.tar.gz
Improve help-fns--insert-menu-bindings formatting
* lisp/help-fns.el (help-fns--insert-menu-bindings): Make this work better for menus that turn out to not be reachable after all -- i.e., don't insert " and " before the heading in certain cases.
Diffstat (limited to 'lisp/help-fns.el')
-rw-r--r--lisp/help-fns.el67
1 files changed, 37 insertions, 30 deletions
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 2bb3e63487c..cbf8ff1f59b 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -588,36 +588,43 @@ the C sources, too."
keys))
(defun help-fns--insert-menu-bindings (menus heading)
- (seq-do-indexed
- (lambda (menu i)
- (insert
- (cond ((zerop i) "")
- ((= i (1- (length menus))) " and ")
- (t ", ")))
- (let ((map (lookup-key global-map (seq-take menu 1)))
- (start (point)))
- (seq-do-indexed
- (lambda (entry level)
- (when (symbolp map)
- (setq map (symbol-function map)))
- (when-let ((elem (assq entry (cdr map))))
- (when heading
- (insert heading)
- (setq heading nil start (point)))
- (when (> level 0)
- (insert
- (if (char-displayable-p ?→)
- " → "
- " => ")))
- (if (eq (nth 1 elem) 'menu-item)
- (progn
- (insert (nth 2 elem))
- (setq map (cadddr elem)))
- (insert (nth 1 elem))
- (setq map (cddr elem)))))
- (cdr (seq-into menu 'list)))
- (put-text-property start (point) 'face 'help-key-binding)))
- menus))
+ (let ((strings nil))
+ ;; First collect all the printed representations of menus.
+ (dolist (menu menus)
+ (let ((map (lookup-key global-map (seq-take menu 1)))
+ (string nil))
+ (seq-do-indexed
+ (lambda (entry level)
+ (when (symbolp map)
+ (setq map (symbol-function map)))
+ (when-let ((elem (assq entry (cdr map))))
+ (when (> level 0)
+ (push (if (char-displayable-p ?→)
+ " → "
+ " => ")
+ string))
+ (if (eq (nth 1 elem) 'menu-item)
+ (progn
+ (push (nth 2 elem) string)
+ (setq map (cadddr elem)))
+ (push (nth 1 elem) string)
+ (setq map (cddr elem)))))
+ (cdr (seq-into menu 'list)))
+ (when string
+ (push string strings))))
+ ;; Then output them.
+ (when strings
+ (when heading
+ (insert heading)
+ (seq-do-indexed
+ (lambda (string i)
+ (insert
+ (cond ((zerop i) "")
+ ((= i (1- (length menus))) " and ")
+ (t ", ")))
+ (insert (propertize (string-join (nreverse string))
+ 'face 'help-key-binding)))
+ strings)))))
(defun help-fns--compiler-macro (function)
(pcase-dolist (`(,type . ,handler)