Xah Lee has a nice post on using Emacs aliases to increase productivity. He uses aliases for two purposes:
- To change the behavior of Emacs
For example, he has the alias(defalias 'yes-or-no-p 'y-or-n-p)
This gets rid of the annoying “Please answer yes or no” silliness that Emacs insists on for some questions. This was one of the first things I did when setting up my
.emacs
file and I’ve never been sorry. - As shortcuts for longer, harder-to-remember commands
For example he has(defalias 'dtw 'delete-trailing-whitespace)
In this vein, I have long used
(defalias 'qrr 'query-replace-regexp)
because I can never remember if it’s
query-regexp-replace
orquery-replace-regexp
. Besides, it’s a lot shorter and easier to type. Another example of this sort that Lee uses is to make alias shortcuts for the different modes that he uses. Thus, he has such shortcuts as(defalias 'hm 'html-mode) (defalias 'tm 'text-mode) (defalias 'wsm 'whitespace-mode)
and so on.
You might think that the mode changing aliases aren’t that useful given that they are usually invoked automatically by the file name extension of the file you are editing but sometimes you want to temporarily turn off a mode. For example, as I’ve mentioned previously, it’s sometimes convenient to turn off paredit mode if you have some major restructuring to do. It’s a major pain to have to type 【Meta+x】 paredit-mode
to turn it off and then again to turn it back on. It’s much easier and faster to just type 【Meta +x】 pm
.
Lee keeps all his aliases in a separate file, which makes them easy to find and maintain. I like to keep mine in my init.el
file near whatever they are redefining as that makes more sense to me but I can see the advantages to a separate file. What do you like to do?