[implementations-list] partially function application and prefix keys for Vi commands that take movement commands as arguments

John J. Foerch jjfoerch at earthlink.net
Tue Oct 13 17:42:39 CEST 2009


On Tue, Oct 13, 2009 at 01:15:03AM -0700, Bayle Shanks wrote:
> I saw that in July, people were talking about alternative ways to
> program commands like "d" that take other commands (like "w") as
> arguments. Here's another proposal; make "d" a prefix key, and bind
> "d"->"w" to a partially applied "delete-cmd" function, with its first
> argument fixed to 'viper-forward-word. Use Elisp functions to create
> these bindings en masse, to remove the tedium of explicitly writing
> out bindings for each pair of movement command and
> movement-argument-taking command.
> 
> Attached is elisp code that demonstrates this.
> 
> The advantage is that you work within emacs's keymap system rather
> than replacing it. Apologies if this has already been discussed.


If you want to take a look at how I approached this problem in modal-mode,
I think I ended up with an elegant solution.

  http://jjfoerch.com/git/modal-mode/modal-mode.el

First, there are "text object" modes.  A text object mode's job is to
install a keymap which remaps movement commands to special commands which
create "text objects".

To take the `d' key as an example:

 * in command mode, the d key is bound to enable a mode called
   1off-kill-mode

 * 1off-kill-mode does two things:
   * enable text-object-mode
   * register a post-command-hook to disable self

 * now the user can hit any movement key.  because command-remaps were
   used instead of explicit bindings, modal-mode does not even need to be
   concerned with what keys the user prefers to use for giving text
   objects.

 * after the user has hit a text-object key, the post-command-hook that we
   registered earlier carries out its action (deletion in this case) on
   the text-object, and disables 1off-kill-mode.


If any of that wasn't clear, read the source. ;)

Cheers

-- 
John Foerch



More information about the implementations-list mailing list