unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* bypassing defining prefix keys
@ 2007-02-04 19:58 Drew Adams
  2007-02-04 21:19 ` Andreas Schwab
  2007-02-05 19:10 ` Richard Stallman
  0 siblings, 2 replies; 6+ messages in thread
From: Drew Adams @ 2007-02-04 19:58 UTC (permalink / raw)
  To: Emacs-Devel

Perhaps this is a bug report; perhaps it is a request for info. I see a
behavior that I don't much like, but I don't know if that behavior might be
desirable for some other reason.

I have code that binds `S-tab' in all keymaps to a command that completes
key sequences. Then, for instance, you can use `C-x S-tab' to complete `C-x'
to anything in keymap `ctl-x-map'. Or you can use `f1 S-tab' to do more or
less what `f1 f1' does: show the `f1' bindings and their commands, and let
you invoke one - you can think of my key-completion feature as generalizing
what `f1 f1' does for help.

You can also use `S-tab' at the top level, to "complete" to any key. So, for
instance, as an alternative to using `C-x S-tab', you can use `S-tab' and
then pick the completion candidate `C-x'. This shows the possible
completions of `C-x', just as `C-x S-tab' does.

This works fine, for all prefix keys. However, it does not work for, say, `*
S-tab' in Dired mode, because `*' is not actually defined as a prefix key
there. The same problem exists for `%'.

You can still use `S-tab' at the top level of Dired, then pick `*' from the
list of *Completions* (which, in turn, shows the possible completions of
`*'), and then pick, say, `/' to invoke `dired-mark-directories'. But if you
use `* S-tab' then you get the error message "* <backtab> is undefined".

Here's why. In dired.el, instead of defining `*' and `%' as prefix keys, a
shortcut is taken. `*' and `%' are each bound to nil, so that they are
undefined in `dired-mode-map', and then each of the `*-<whatever>' and
`%-<whatever> key sequences is bound directly in `dired-mode-map'. That is:

 (define-key dired-mode-map "*" nil)
 (define-key dired-mode-map "*/" 'dired-mark-directories)
 ...

This explains the behavior I get, but I wonder if `*' and `%' should be
defined this way. Is there a guideline or policy on this? Obviously, it
would be better for my key-completion code if `*' and `%' were defined as
real prefix keys.

This comment appears in dired.el as the rationale for the current
implementation of `%'. Presumably it is meant for `*' as well.

 ;; Make all regexp commands share a `%' prefix:
 ;; We used to get to the submap via a symbol dired-regexp-prefix,
 ;; but that seems to serve little purpose, and copy-keymap
 ;; does a better job without it.

I don't understand the part about `copy-keymap' (which is not used in
dired.el, in any case). What is the `copy-keymap' limitation that is hinted
at here? Is it important that the Dired code avoid defining prefix keys this
way?

Can someone speak to whether this is still the best way for dired.el to
define the `*' and `%' pseudo prefix keys? If it's not the best way, can we
please use real prefix keys? Thx.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: bypassing defining prefix keys
  2007-02-04 19:58 bypassing defining prefix keys Drew Adams
@ 2007-02-04 21:19 ` Andreas Schwab
  2007-02-04 21:27   ` Drew Adams
  2007-02-05 19:10 ` Richard Stallman
  1 sibling, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2007-02-04 21:19 UTC (permalink / raw)
  To: Drew Adams; +Cc: Emacs-Devel

"Drew Adams" <drew.adams@oracle.com> writes:

> Here's why. In dired.el, instead of defining `*' and `%' as prefix keys, a
> shortcut is taken. `*' and `%' are each bound to nil, so that they are
> undefined in `dired-mode-map', and then each of the `*-<whatever>' and
> `%-<whatever> key sequences is bound directly in `dired-mode-map'. That is:
>
>  (define-key dired-mode-map "*" nil)
>  (define-key dired-mode-map "*/" 'dired-mark-directories)
>  ...
>
> This explains the behavior I get, but I wonder if `*' and `%' should be
> defined this way.

Before the remap feature existed you had to remove the existing binding
for "*" (from suppress-keymap) before you could redefine it as a prefix
key.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: bypassing defining prefix keys
  2007-02-04 21:19 ` Andreas Schwab
@ 2007-02-04 21:27   ` Drew Adams
  2007-02-04 22:03     ` Andreas Schwab
  0 siblings, 1 reply; 6+ messages in thread
From: Drew Adams @ 2007-02-04 21:27 UTC (permalink / raw)
  To: Emacs-Devel

> > Here's why. In dired.el, instead of defining `*' and `%' as
> > prefix keys, a shortcut is taken. `*' and `%' are each bound to nil,
> > so that they are undefined in `dired-mode-map', and then each of the
> > `*-<whatever>' and `%-<whatever> key sequences is bound directly in
> > `dired-mode-map'. That is:
> >
> >  (define-key dired-mode-map "*" nil)
> >  (define-key dired-mode-map "*/" 'dired-mark-directories)
> >  ...
> >
> > This explains the behavior I get, but I wonder if `*' and `%' should be
> > defined this way.
>
> Before the remap feature existed you had to remove the existing binding
> for "*" (from suppress-keymap) before you could redefine it as a prefix
> key.

I'm not sure what you're responding to. Yes, any existing binding has been
removed by binding them to nil. And?

`*' and `%' are _not_ then defined as prefix keys. The question is whether
they should be. Is there a good reason not to define them as prefix keys?

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: bypassing defining prefix keys
  2007-02-04 21:27   ` Drew Adams
@ 2007-02-04 22:03     ` Andreas Schwab
  2007-02-04 22:19       ` Drew Adams
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Schwab @ 2007-02-04 22:03 UTC (permalink / raw)
  To: Drew Adams; +Cc: Emacs-Devel

"Drew Adams" <drew.adams@oracle.com> writes:

> `*' and `%' are _not_ then defined as prefix keys.

Of course they are.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: bypassing defining prefix keys
  2007-02-04 22:03     ` Andreas Schwab
@ 2007-02-04 22:19       ` Drew Adams
  0 siblings, 0 replies; 6+ messages in thread
From: Drew Adams @ 2007-02-04 22:19 UTC (permalink / raw)
  To: Emacs-Devel

> > `*' and `%' are _not_ then defined as prefix keys.
>
> Of course they are.

I didn't think that they were, but I guess you're right. I thought their
bindings in `dired-mode-map' were nil, not keymaps, but I see now that I was
wrong.

Guess I'll have to look closer to see why I get the error
"* <backtab> is undefined". Thx.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: bypassing defining prefix keys
  2007-02-04 19:58 bypassing defining prefix keys Drew Adams
  2007-02-04 21:19 ` Andreas Schwab
@ 2007-02-05 19:10 ` Richard Stallman
  1 sibling, 0 replies; 6+ messages in thread
From: Richard Stallman @ 2007-02-05 19:10 UTC (permalink / raw)
  To: Drew Adams; +Cc: emacs-devel

     (define-key dired-mode-map "*" nil)
     (define-key dired-mode-map "*/" 'dired-mark-directories)
     ...

    This explains the behavior I get, but I wonder if `*' and `%' should be
    defined this way. Is there a guideline or policy on this? Obviously, it
    would be better for my key-completion code if `*' and `%' were defined as
    real prefix keys.

Actually this DOES define them as prefix keys; this is a valid way to
do so.  The other method is to define it as a symbol and give the
symbol the submap as a function definition.

It seems your completion command works with one method of doing so and
not with the other.  But it could handle both.

     ;; Make all regexp commands share a `%' prefix:
     ;; We used to get to the submap via a symbol dired-regexp-prefix,
     ;; but that seems to serve little purpose, and copy-keymap
     ;; does a better job without it.

    I don't understand the part about `copy-keymap' (which is not used in
    dired.el, in any case). What is the `copy-keymap' limitation that is hinted
    at here?

I think it is this: with a symbol in the way, `copy-keymap' won't copy
that symbol (since an interned symbol is unique), nor whatever map it
points to.  With no symbol, it will recursively copy the submap.

Why it should be relevant here, I am not sure.  Maybe some other mode does
(or did) `copy-keymap' on `dired-mode-map'.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2007-02-05 19:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-04 19:58 bypassing defining prefix keys Drew Adams
2007-02-04 21:19 ` Andreas Schwab
2007-02-04 21:27   ` Drew Adams
2007-02-04 22:03     ` Andreas Schwab
2007-02-04 22:19       ` Drew Adams
2007-02-05 19:10 ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).