From fd1ca094bc43d8fab859e7b78280f9f9693105f1 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 25 Apr 2022 21:14:24 +0200 Subject: [PATCH] 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 2048e5aa984..89a8c34df91 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 , C-x C-f, . + +This has been changed to: + + It is bound to 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 23cfb04798f..45999801667 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 -- 2.39.2