emacs-diffs
[Top][All Lists]
Advanced

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

master a649034 1/3: Don't show key ranges if shadowed by different comma


From: Stefan Kangas
Subject: master a649034 1/3: Don't show key ranges if shadowed by different commands
Date: Sat, 21 Nov 2020 21:19:09 -0500 (EST)

branch: master
commit a6490343366f2b2331a91dcb693effb3a9dd78f5
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>

    Don't show key ranges if shadowed by different commands
    
    * src/keymap.c (describe_vector): Make sure found consecutive keys
    are either not shadowed or, if they are, that they are shadowed by
    the same command.  (Bug#9293)
    * test/src/keymap-tests.el
    (help--describe-vector/bug-9293-one-shadowed-in-range): New test.
---
 src/keymap.c             | 22 ++++++++++++++++++----
 test/src/keymap-tests.el | 27 +++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/src/keymap.c b/src/keymap.c
index 181dcda..749f4b6 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -3085,6 +3085,7 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, 
Lisp_Object args,
   for (i = from; ; i++)
     {
       bool this_shadowed = 0;
+      Lisp_Object shadowed_by = Qnil;
       int range_beg, range_end;
       Lisp_Object val;
 
@@ -3127,11 +3128,9 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, 
Lisp_Object args,
       /* If this binding is shadowed by some other map, ignore it.  */
       if (!NILP (shadow))
        {
-         Lisp_Object tem;
-
-         tem = shadow_lookup (shadow, kludge, Qt, 0);
+         shadowed_by = shadow_lookup (shadow, kludge, Qt, 0);
 
-         if (!NILP (tem))
+         if (!NILP (shadowed_by))
            {
              if (mention_shadow)
                this_shadowed = 1;
@@ -3186,6 +3185,21 @@ describe_vector (Lisp_Object vector, Lisp_Object prefix, 
Lisp_Object args,
               && !NILP (Fequal (tem2, definition)))
          i++;
 
+      /* Make sure found consecutive keys are either not shadowed or,
+        if they are, that they are shadowed by the same command.  */
+      if (CHAR_TABLE_P (vector) && i != starting_i)
+       {
+         Lisp_Object tem;
+         Lisp_Object key = make_nil_vector (1);
+         for (int j = starting_i + 1; j <= i; j++)
+           {
+             ASET (key, 0, make_fixnum (j));
+             tem = shadow_lookup (shadow, key, Qt, 0);
+             if (NILP (Fequal (tem, shadowed_by)))
+               i = j - 1;
+           }
+       }
+
       /* If we have a range of more than one character,
         print where the range reaches to.  */
 
diff --git a/test/src/keymap-tests.el b/test/src/keymap-tests.el
index 610234c..68a8438 100644
--- a/test/src/keymap-tests.el
+++ b/test/src/keymap-tests.el
@@ -200,6 +200,33 @@ commit 86c19714b097aa477d339ed99ffb5136c755a046."
             (where-is-internal 'execute-extended-command global-map t))
           [#x8000078])))
 
+
+;;;; describe_vector
+
+(ert-deftest help--describe-vector/bug-9293-one-shadowed-in-range ()
+  "Check that we only show a range if shadowed by the same command."
+  (let ((orig-map (let ((map (make-keymap)))
+                    (define-key map "e" 'foo)
+                    (define-key map "f" 'foo)
+                    (define-key map "g" 'foo)
+                    (define-key map "h" 'foo)
+                    map))
+        (shadow-map (let ((map (make-keymap)))
+                      (define-key map "f" 'bar)
+                      map)))
+    (with-temp-buffer
+      (help--describe-vector (cadr orig-map) nil #'help--describe-command
+                             t shadow-map orig-map t)
+      (should (equal (buffer-string)
+                     "
+e              foo
+f              foo  (binding currently shadowed)
+g .. h         foo
+")))))
+
+
+;;;; apropos-internal
+
 (ert-deftest keymap-apropos-internal ()
   (should (equal (apropos-internal "^next-line$") '(next-line)))
   (should (>= (length (apropos-internal "^help")) 100))



reply via email to

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