emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 71735be475: Improve help-fns--insert-menu-bindings formatting


From: Lars Ingebrigtsen
Subject: master 71735be475: Improve help-fns--insert-menu-bindings formatting
Date: Mon, 3 Oct 2022 15:32:23 -0400 (EDT)

branch: master
commit 71735be475f0e5e72727c567e7344df805206cd5
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    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.
---
 lisp/help-fns.el | 67 +++++++++++++++++++++++++++++++-------------------------
 1 file changed, 37 insertions(+), 30 deletions(-)

diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 2bb3e63487..cbf8ff1f59 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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]