emacs-diffs
[Top][All Lists]
Advanced

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

master c0f656617d6: Make sure the binding shown by echo-keystrokes-help


From: Dmitry Gutov
Subject: master c0f656617d6: Make sure the binding shown by echo-keystrokes-help is not shadowed
Date: Sun, 11 Feb 2024 15:35:02 -0500 (EST)

branch: master
commit c0f656617d6848b94413b79b390788565d338fcd
Author: Dmitry Gutov <dmitry@gutov.dev>
Commit: Dmitry Gutov <dmitry@gutov.dev>

    Make sure the binding shown by echo-keystrokes-help is not shadowed
    
    And choose just one binding to display rather than two together.
    (https://lists.gnu.org/archive/html/emacs-devel/2024-02/msg00311.html)
    
    * lisp/help.el (help--append-keystrokes-help): New function.
    
    * src/keyboard.c (syms_of_keyboard): Add a symbol for it.
    (echo_dash): Use them here.
---
 lisp/help.el   | 21 +++++++++++++++++++++
 src/keyboard.c | 13 +++++--------
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/lisp/help.el b/lisp/help.el
index 72a4f8a800d..07eed2861c2 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -2253,6 +2253,27 @@ The `temp-buffer-window-setup-hook' hook is called."
        (with-output-to-temp-buffer " *Char Help*"
          (princ msg)))))
 
+(defun help--append-keystrokes-help (str)
+  (let* ((keys (this-single-command-keys))
+         (bindings (delete nil
+                           (mapcar (lambda (map) (lookup-key map keys t))
+                                   (current-active-maps t)))))
+    (catch 'res
+      (dolist (val help-event-list)
+        (let ((key (vector (if (eql val 'help)
+                               help-char
+                             val))))
+          (unless (seq-find (lambda (map) (and (keymapp map) (lookup-key map 
key)))
+                            bindings)
+            (throw 'res
+                   (concat
+                    str
+                    (substitute-command-keys
+                     (format
+                      " (\\`%s' for help)"
+                      (key-description key))))))))
+      str)))
+
 
 (defun help--docstring-quote (string)
   "Return a doc string that represents STRING.
diff --git a/src/keyboard.c b/src/keyboard.c
index 10cdef67348..4b5e20fb24c 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -594,14 +594,9 @@ echo_dash (void)
                    concat2 (KVAR (current_kboard, echo_string), dash));
 
   if (echo_keystrokes_help)
-    {
-      Lisp_Object help;
-
-      help = build_string (" (\\`C-h' or \\`<f1>' for help)");
-      kset_echo_string (current_kboard,
-                       concat2 (KVAR (current_kboard, echo_string),
-                                calln (Qsubstitute_command_keys, help)));
-    }
+    kset_echo_string (current_kboard,
+                     calln (Qhelp__append_keystrokes_help,
+                            KVAR (current_kboard, echo_string)));
 
   echo_now ();
 }
@@ -12962,6 +12957,8 @@ syms_of_keyboard (void)
 
   DEFSYM (Qhelp_key_binding, "help-key-binding");
 
+  DEFSYM (Qhelp__append_keystrokes_help, "help--append-keystrokes-help");
+
   DEFSYM (Qecho_keystrokes, "echo-keystrokes");
 
   Fset (Qinput_method_exit_on_first_char, Qnil);



reply via email to

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