From: Lars Ingebrigtsen Date: Mon, 3 Oct 2022 19:32:01 +0000 (+0200) Subject: Improve help-fns--insert-menu-bindings formatting X-Git-Tag: emacs-29.0.90~1856^2~55 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=71735be475f0e5e72727c567e7344df805206cd5;p=emacs.git 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. --- 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)