emacs-diffs
[Top][All Lists]
Advanced

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

master fd1ca094bc: Change the display of menu bindings in *Help*


From: Lars Ingebrigtsen
Subject: master fd1ca094bc: Change the display of menu bindings in *Help*
Date: Mon, 25 Apr 2022 15:14:38 -0400 (EDT)

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

    Change the display of menu bindings in *Help*
    
    * lisp/help-fns.el (help-fns--insert-menu-bindings): New function
    to describe menu entries more fully (bug#52870).
    (help-fns--key-bindings): Use it.
---
 etc/NEWS         | 12 ++++++++++++
 lisp/help-fns.el | 31 ++++++++++++++++++++++++++++---
 2 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 2048e5aa98..89a8c34df9 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -416,6 +416,18 @@ command also works for non-Emoji characters.)
 
 ** Help
 
+---
+*** Commands like 'C-h f' have changed how they describe menu bindings.
+For instance, previously a command might be described as having the
+following bindings:
+
+  It is bound to <open>, C-x C-f, <menu-bar> <file> <new-file>.
+
+This has been changed to:
+
+  It is bound to <open> and C-x C-f.
+  It can also be invoked from the menu: File → Visit New File....
+
 +++
 *** The 'C-h .' command now accepts a prefix argument.
 'C-u C-h .' would previously inhibit displaying a warning message if
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 23cfb04798..4599980166 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -568,9 +568,7 @@ the C sources, too."
                 (insert (concat "It can "
                                 (and keys "also ")
                                 "be invoked from the menu: "))
-                ;; FIXME: Should insert menu names instead of key
-                ;; binding names.
-                (help-fns--insert-bindings menus)
+                (help-fns--insert-menu-bindings menus)
                 (insert ".")
                 (fill-region-as-paragraph start (point))))
             (ensure-empty-lines)))))))
@@ -584,6 +582,33 @@ the C sources, too."
                     (insert (help--key-description-fontified key)))
                   keys))
 
+(defun help-fns--insert-menu-bindings (menus)
+  (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 (> level 0)
+            (insert
+             (if (char-displayable-p ?→)
+                 " → "
+               " => ")))
+          (let ((elem (assq entry (cdr map))))
+            (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))
+
 (defun help-fns--compiler-macro (function)
   (let ((handler (function-get function 'compiler-macro)))
     (when handler



reply via email to

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