emacs-diffs
[Top][All Lists]
Advanced

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

master b49cca7012: Make :filters run in the correct buffer in describe-b


From: Lars Ingebrigtsen
Subject: master b49cca7012: Make :filters run in the correct buffer in describe-buffer-bindings
Date: Sun, 17 Apr 2022 12:06:32 -0400 (EDT)

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

    Make :filters run in the correct buffer in describe-buffer-bindings
    
    * lisp/help.el (describe-map-tree): Take an optional buffer parameter.
    (describe-map): Ditto, and use it to run `lookup-key' in the
    correct buffer.  This fixes problems of filters being run in the
    wrong buffer (bug#39149).
    
    * src/keymap.c (Fdescribe_buffer_bindings): Pass in BUFFER to
    describe-map-tree.
---
 lisp/help.el | 22 +++++++++++++++-------
 src/keymap.c | 20 ++++++++++----------
 2 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/lisp/help.el b/lisp/help.el
index 9cde65f797..0d516cf9f6 100644
--- a/lisp/help.el
+++ b/lisp/help.el
@@ -1274,7 +1274,8 @@ Otherwise, return a new string."
 
 (defvar help--keymaps-seen nil)
 (defun describe-map-tree (startmap &optional partial shadow prefix title
-                                   no-menu transl always-title mention-shadow)
+                                   no-menu transl always-title mention-shadow
+                                   buffer)
   "Insert a description of the key bindings in STARTMAP.
 This is followed by the key bindings of all maps reachable
 through STARTMAP.
@@ -1300,7 +1301,10 @@ maps to look through.
 
 If MENTION-SHADOW is non-nil, then when something is shadowed by
 SHADOW, don't omit it; instead, mention it but say it is
-shadowed."
+shadowed.
+
+If BUFFER, lookup keys while in that buffer.  This only affects
+things like :filters for menu bindings."
   (let* ((amaps (accessible-keymaps startmap prefix))
          (orig-maps (if no-menu
                         (progn
@@ -1341,7 +1345,8 @@ shadowed."
                 (setq sub-shadows (cons (cdr (car tail)) sub-shadows)))
               (setq tail (cdr tail))))
           (describe-map (cdr elt) elt-prefix transl partial
-                        sub-shadows no-menu mention-shadow)))
+                        sub-shadows no-menu mention-shadow
+                        buffer)))
       (setq maps (cdr maps)))
     ;; Print title...
     (when (and print-title
@@ -1419,13 +1424,13 @@ Return nil if the key sequence is too long."
           (t nil))))
 
 (defun describe-map (map &optional prefix transl partial shadow
-                         nomenu mention-shadow)
+                         nomenu mention-shadow buffer)
   "Describe the contents of keymap MAP.
 Assume that this keymap itself is reached by the sequence of
 prefix keys PREFIX (a string or vector).
 
-TRANSL, PARTIAL, SHADOW, NOMENU, MENTION-SHADOW are as in
-`describe-map-tree'."
+TRANSL, PARTIAL, SHADOW, NOMENU, MENTION-SHADOW and BUFFER are as
+in `describe-map-tree'."
   ;; Converted from describe_map in keymap.c.
   (let* ((suppress (and partial 'suppress-keymap))
          (map (keymap-canonicalize map))
@@ -1476,7 +1481,10 @@ TRANSL, PARTIAL, SHADOW, NOMENU, MENTION-SHADOW are as in
                                 ((and mention-shadow (not (eq tem definition)))
                                  (setq this-shadowed t))
                                 (t nil))))
-                    (eq definition (lookup-key tail (vector event) t))
+                    (eq definition (if buffer
+                                       (with-current-buffer buffer
+                                         (lookup-key tail (vector event) t))
+                                     (lookup-key tail (vector event) t)))
                     (push (list event definition this-shadowed) vect))))
             ((eq (car tail) 'keymap)
              ;; The same keymap might be in the structure twice, if
diff --git a/src/keymap.c b/src/keymap.c
index 83c54e2630..da0a52bd2c 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -2867,7 +2867,7 @@ You type        Translation\n\
       CALLN (Ffuncall,
             Qdescribe_map_tree,
             Vkey_translation_map, Qnil, Qnil, prefix,
-            msg, nomenu, Qt, Qnil, Qnil);
+            msg, nomenu, Qt, Qnil, Qnil, buffer);
     }
 
   /* Print the (major mode) local map.  */
@@ -2881,7 +2881,7 @@ You type        Translation\n\
       CALLN (Ffuncall,
             Qdescribe_map_tree,
             start1, Qt, shadow, prefix,
-            msg, nomenu, Qnil, Qnil, Qnil);
+            msg, nomenu, Qnil, Qnil, Qnil, buffer);
       shadow = Fcons (start1, shadow);
       start1 = Qnil;
     }
@@ -2894,7 +2894,7 @@ You type        Translation\n\
       CALLN (Ffuncall,
             Qdescribe_map_tree,
             start1, Qt, shadow, prefix,
-            msg, nomenu, Qnil, Qnil, Qnil);
+            msg, nomenu, Qnil, Qnil, Qnil, buffer);
       shadow = Fcons (start1, shadow);
     }
   else
@@ -2917,7 +2917,7 @@ You type        Translation\n\
          CALLN (Ffuncall,
                 Qdescribe_map_tree,
                 start1, Qt, shadow, prefix,
-                msg, nomenu, Qnil, Qnil, Qnil);
+                msg, nomenu, Qnil, Qnil, Qnil, buffer);
          shadow = Fcons (start1, shadow);
        }
 
@@ -2950,7 +2950,7 @@ You type        Translation\n\
          CALLN (Ffuncall,
                 Qdescribe_map_tree,
                 maps[i], Qt, shadow, prefix,
-                msg, nomenu, Qnil, Qnil, Qnil);
+                msg, nomenu, Qnil, Qnil, Qnil, buffer);
          shadow = Fcons (maps[i], shadow);
          SAFE_FREE ();
        }
@@ -2968,7 +2968,7 @@ You type        Translation\n\
              CALLN (Ffuncall,
                     Qdescribe_map_tree,
                     start1, Qt, shadow, prefix,
-                    msg, nomenu, Qnil, Qnil, Qnil);
+                    msg, nomenu, Qnil, Qnil, Qnil, buffer);
            }
          else
            {
@@ -2976,7 +2976,7 @@ You type        Translation\n\
              CALLN (Ffuncall,
                     Qdescribe_map_tree,
                     start1, Qt, shadow, prefix,
-                    msg, nomenu, Qnil, Qnil, Qnil);
+                    msg, nomenu, Qnil, Qnil, Qnil, buffer);
            }
 
          shadow = Fcons (start1, shadow);
@@ -2987,7 +2987,7 @@ You type        Translation\n\
   CALLN (Ffuncall,
         Qdescribe_map_tree,
         current_global_map, Qt, shadow, prefix,
-        msg, nomenu, Qnil, Qt, Qnil);
+        msg, nomenu, Qnil, Qt, Qnil, buffer);
 
   /* Print the function-key-map translations under this prefix.  */
   if (!NILP (KVAR (current_kboard, Vlocal_function_key_map)))
@@ -2996,7 +2996,7 @@ You type        Translation\n\
       CALLN (Ffuncall,
             Qdescribe_map_tree,
             KVAR (current_kboard, Vlocal_function_key_map), Qnil, Qnil, prefix,
-            msg, nomenu, Qt, Qnil, Qnil);
+            msg, nomenu, Qt, Qnil, Qnil, buffer);
     }
 
   /* Print the input-decode-map translations under this prefix.  */
@@ -3006,7 +3006,7 @@ You type        Translation\n\
       CALLN (Ffuncall,
             Qdescribe_map_tree,
             KVAR (current_kboard, Vinput_decode_map), Qnil, Qnil, prefix,
-            msg, nomenu, Qt, Qnil, Qnil);
+            msg, nomenu, Qt, Qnil, Qnil, buffer);
     }
   return Qnil;
 }



reply via email to

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