Executing commands with abbreviations, reloaded

Posted: July 26, 2007 in Emacs
Tags: ,

Yesterday I posted a command that executes emacs commands by giving an abbreviation. Today I’ve built a complete global minor mode around it. Here’s the file’s description:

This file includes the command `exec-abbrev-cmd’ which lets you execute a
command by giving it in an abbreviated form, where the abbreviation takes
the first character of each word in the command name. For example “g” is an
abbreviation for the command `gnus’, “eb” is an abbreviation for
`emms-browser’ and “omm” is an abbreviation for `outline-minor-mode’. Of
course it is possible, that an abbreviation matches several commands,
e.g. “g” matches not only `gnus’ but `grep’, `gdb’ and some more. In such
cases you will be queried, which command to use.

To have this functionality quickly accessible you might want to bind it to
some key. That’s what I use:

(add-to-list 'load-path "~/elisp") ;; Where is exec-abbrev-cmd.el?
(require 'exec-abbrev-cmd)         ;; Load it.
(global-set-key (kbd "C-x x") 'exec-abbrev-cmd)

Now you’ll say, “Wow, what a nice feature!”, but it’s even getting better.
Let’s say you often invoke `customize-face’ with `C-x x cf RET’ and then
choosing from the completion list between `copy-file’ and `customize-face’.
Always `copy-file’ is selected first, because it’s lexicographically before
`customize-face’. As a solution to this problem there’s
`exec-abbrev-cmd-mode’, a global minor mode that does bookkeeping how often
you invoke a command with `exec-abbrev-cmd’, so that the list of commands
you have to choose from is sorted by the frequency of command invokation.
After a while in most cases `C-x x <abbrev> RET RET’ will do what you want.

If you want to enable this feature put this in your ~/.emacs:

(exec-abbrev-cmd-mode 1)

Have fun!

You can get exec-abbrev-cmd.el from my elisp darcs repository.

UPDATE: I moved all my projects to Git repositories. Have a look at my homepage for more infos on exec-abbrev-cmd.el.

  1. hsu says:

    Cool! I was going to ask you how could I have my personal functions coming before than emacs’s, and bookkeeping solves that in a nice way (because they are more used)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s