emacs-devel
[Top][All Lists]
Advanced

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

Re: M-g in dired


From: Juri Linkov
Subject: Re: M-g in dired
Date: Tue, 01 Nov 2005 11:16:43 +0200
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

> Would you like to try modifying that code so it detects the other case?

I think the most appropriate place to modify is `shadow_lookup'.
The second part of the patch below changes it to return nil
when one of prefix keys is found in the keymap with higher priority.
This allows to find a shorter key in the local keymap rather than in
the global keymap.  For example, looking for "M-g n" in two keymaps

    (lookup-key dired-mode-map [134217831 110]) => 1
    (lookup-key global-map [134217831 110]) => next-error

will return nil, because lookup-key in dired-mode-map returns a number,
since "M-g" in dired-mode-map is bound to `dired-goto-file'.

However, this change also requires one change in the value returned by
`lookup-key'.  Currently, it returns a number even when it can't find
a key definition and the tested key sequence is two keys or longer.
So, for example, in dired-mode-map where "C-x `" is undefined,
`lookup-key' returns 1:

    (lookup-key dired-mode-map [24 96]) => 1

It seems this is not correct.  And the documentation says nothing about
such case.  The first part of the patch changes `lookup-key' to return
nil, e.g.:

    (lookup-key dired-mode-map [24 96]) => nil

I can't estimate if there is a code that relies on the current
return value of `lookup-key'.  If so, then perhaps a new special
argument could be added to `lookup-key' to change the semantic of
the return value?

Index: src/keymap.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/keymap.c,v
retrieving revision 1.307
diff -c -r1.307 keymap.c
*** src/keymap.c        12 Sep 2005 10:26:35 -0000      1.307
--- src/keymap.c        1 Nov 2005 09:16:18 -0000
***************
*** 1262,1269 ****
  
        keymap = get_keymap (cmd, 0, 1);
        if (!CONSP (keymap))
!       RETURN_UNGCPRO (make_number (idx));
! 
        QUIT;
      }
  }
--- 1262,1273 ----
  
        keymap = get_keymap (cmd, 0, 1);
        if (!CONSP (keymap))
!       {
!         if (!NILP (cmd))
!           RETURN_UNGCPRO (make_number (idx));
!         else
!           return Qnil;
!       }
        QUIT;
      }
  }
***************
*** 2377,2383 ****
    for (tail = shadow; CONSP (tail); tail = XCDR (tail))
      {
        value = Flookup_key (XCAR (tail), key, flag);
!       if (!NILP (value) && !NATNUMP (value))
        return value;
      }
    return Qnil;
--- 2381,2389 ----
    for (tail = shadow; CONSP (tail); tail = XCDR (tail))
      {
        value = Flookup_key (XCAR (tail), key, flag);
!       if (NATNUMP (value))
!       return Qnil;
!       if (!NILP (value))
        return value;
      }
    return Qnil;

-- 
Juri Linkov
http://www.jurta.org/emacs/





reply via email to

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