[Top][All Lists]

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

Re: Proposal: Remap interactive commands via keymaps

From: Kim F. Storm
Subject: Re: Proposal: Remap interactive commands via keymaps
Date: 04 Jan 2002 12:25:32 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1

"Eli Zaretskii" <address@hidden> writes:

> > From: address@hidden (Kim F. Storm)
> > Date: 03 Jan 2002 23:56:41 +0100
> > 
> > Suppose that in the x-mode minor mode, I want all keys bound to
> > self-insert-command to insert the typed character followed by an `x',
> > i.e. to execute the following command instead:
> > 
> >     (defun x-self-insert-command ()
> >         (interactive)
> >         (insert (this-command-keys) "x"))
> > 
> > Rather than rebinding all the self-insert-command keys in x-mode's
> > minor mode keymap, we can achieve exactly the same functionality
> > with a single binding:
> > 
> >     (define-key x-mode-map [self-insert-command] 'x-self-insert-command)
> How is this different from substitute-key-definition?  What am I
> missing?

I suppose you ask how is this different from

        (substitute-key-definition 'self-insert-command
         'x-self-insert-command x-mode-map global-map)

Well, firstly it is different in the sense that the x-mode minor mode
keymap only need to have *one* entry mapping self-insert-command to
x-self-insert-command.  With substitute-key-definition, the keymap
need to have bindings for *all* keys which are already bound to

Secondly, substitute-key-definition depends on being able to specify 
the OLDMAP - so rather than being a logical mapping which works 
no matter what keys are used to execute a given command, it only
works for the keys which invoke that command in that specific OLDMAP.

Suppose you have a minor mode y-mode active which - say - binds \r
to self-insert-command (just for the example), and y-mode is active, 
then you don't get the x-mode behaviour when you hit RET.

Also, with my proposal, M-x self-insert-command will also be

As another example, suppose you want to `advice' the command
View-scroll-page-forward  (normally run by SPC in view-mode).
With substitute-key-definition, I would do something like

        (substitute-key-definition 'View-scroll-page-forward
         'x-View-scroll-page-forward x-mode-map view-mode-map)

However, doing this means that if x-mode is active in a buffer
but view-mode is not active, SPC will still run x-View-scroll-page-forward,
whereas with my proposal SPC will not be explicitly mapped in x-mode-map,
so it will run its normal binding.

So where substitute-key-definition makes explicit - and possibly
incomplete - bindings, my proposal makes *logical* bindings
which will honour other minor mode maps.

Kim F. Storm <address@hidden> http://www.cua.dk

reply via email to

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