emacs-devel
[Top][All Lists]
Advanced

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

Re: bug/feature - emacs doesn't tell you about keys with multiple prefi


From: Stefan Monnier
Subject: Re: bug/feature - emacs doesn't tell you about keys with multiple prefixes
Date: Mon, 17 Mar 2003 11:35:28 -0500

>     In accessible-keymaps (used by where-is-internal), there is an explicit 
> check
>     to remove any duplicate keymaps (i.e. the same keymap appearing under 
> another
>     prefix).
> 
> I don't remember the reason for this.  Perhaps the idea was that it is
> supposed to tell you all the keymaps, not all the prefixes.
> Preventing cycles is also necessary.
> 
> There could be an optional 3rd arg ALLOW-DUPLICATES which, if non-nil,
> means that it only rejects actual cycles (where the prefix already
> recorded for the same keymap is an initial segment of the new prefix).

Grepping through Emacs' code I discovered that accessible-keymap
is never called from elisp and that it's only ever called from
where-is-internal, so I think we can safely change its
behavior without adding a new argument.

How about the patch below ?


        Stefan


Index: src/keymap.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/keymap.c,v
retrieving revision 1.277
diff -c -b -r1.277 keymap.c
*** src/keymap.c        16 Mar 2003 00:06:59 -0000      1.277
--- src/keymap.c        17 Mar 2003 16:32:29 -0000
***************
*** 1659,1676 ****
  {
    Lisp_Object tem;
  
!   cmd = get_keyelt (cmd, 0);
    if (NILP (cmd))
      return;
  
!   tem = get_keymap (cmd, 0, 0);
!   if (CONSP (tem))
!     {
!       cmd = tem;
!       /* Ignore keymaps that are already added to maps.  */
!       tem = Frassq (cmd, maps);
!       if (NILP (tem))
        {
          /* If the last key in thisseq is meta-prefix-char,
             turn it into a meta-ized keystroke.  We know
             that the event we're about to append is an
--- 1659,1689 ----
  {
    Lisp_Object tem;
  
!   cmd = get_keymap (get_keyelt (cmd, 0), 0, 0);
    if (NILP (cmd))
      return;
  
!   /* Look for and break cycles.  */
!   while (!NILP (tem = Frassq (cmd, maps)))
      {
+       Lisp_Object prefix = XCAR (tem);
+       int lim = XINT (Flength (XCAR (tem)));
+       if (lim <= XINT (Flength (thisseq)))
+       { /* This keymap was already seen with a smaller prefix.  */
+         int i = 0;
+         while (i < lim && EQ (Faref (prefix, make_number (i)),
+                               Faref (thisseq, make_number (i))))
+           i++;
+         if (i >= lim)
+           /* `prefix' is a prefix of `thisseq' => there's a cycle.  */
+           return;
+       }
+       /* This occurrence of `cmd' in `maps' does not correspond to a cycle,
+        but maybe `cmd' occurs again further down in `maps', so keep
+        looking.  */
+       maps = XCDR (Fmemq (tem, maps));
+     }
+ 
    /* If the last key in thisseq is meta-prefix-char,
       turn it into a meta-ized keystroke.  We know
       that the event we're about to append is an
***************
*** 1694,1701 ****
            {
              tem = append_key (thisseq, key);
              nconc2 (tail, Fcons (Fcons (tem, cmd), Qnil));
-           }
-       }
      }
  }
  
--- 1707,1712 ----





reply via email to

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