tags: personal journal

Nicholas' journal. I also write a programming blog and a tumble log.

Dec 26, 2009
The Power That is GNU Emacs, Written By Somebody With A Different Personality

(This is me envisioning myself having the experiences that this guy had. Disclaimer: I use Vim, but, to be fair, I use it on a Mac.)

Do you have friends that always, no matter what you do, have some opinion about how you could be doing it better? You probably do, since you're probably a nerd, since you're reading a blog post on text editors. I certainly have these sorts of friends. In fact, I started using Emacs back when my friend -- one of those friends -- started talking about how great it was. I was a Vim user, but Emacs, said my friend, was so superior that it could actually emulate lesser editors like Vim.

This proposition intrigued me. Why would an Emacs user spend hours of his or her time to emulate Vim? Was it sheer masochism? Some absurd display of talent? Or did I detect a hidden longing for the Other?

In any case, this guy just wouldn't stop badgering me about Emacs, so I downloaded it just to shut him up. Started it up, and -- wouldn't you know it -- the backspace key didn't work. It turns out that ctrl-H is bound to "provide help" rather than "delete a character" -- somewhat oddly, for an editor which has existed since the time when "ctrl-H for backspace" was fairly standard behaviour. Anyway, I say "provide help", but not, of course, the kind of help that I could actually use to configure the keyboard. For that I turned to my old friend Google. Within .004 seconds I had over 3 million pages telling me how to fix the problem. But the solution was pretty freaking weird:

(global-set-key "\C-h" 'delete-backward-char)

This is of course a programming language, and you use it in exactly the same way you would use Vim's scripting extensions. Emacs scripting is better though, for two reasons. Firstly, it is legitimately more powerful than Vim's scripting language -- though not for any of the scripts that I have actually written. Secondly, and far more importantly, Emacs uses a Lisp dialect. Lisp is both very old and very arcane, and is for some reason surrounded by a reverent mysticism that other languages of the same era, such as COBOL, just don't enjoy. Well-known writers such as Paul Graham call it a "secret weapon", inspiring people to, for example, write famous web sites in Lisp, and then to re-write them in Python when they realise that there is no reasonable standard library or community support for any Lisp except the one built into a certain text editor.

Back to Emacs. I felt amazed. I had just written a program. I was customising the very core of the editor -- in fact, every time I pressed a key, Emacs ran code that I could modify. And not modify by learning C, but modify by learning Lisp! This was kind of like modifying Vim with Vimscript, except slower. And, indeed, Emacs was slow as a dog. It started up way too slowly for me to run "emacs" each time I wanted to edit something, which is what I had been doing with Vim.

To get around the slowness problem I once again used Google, rather than Emacs' built-in help, because pressing ctrl-H just deleted things now. It turns out that the best way to avoid the speed issues is to start Emacs in the background and just let it run the entire time. Rather like what Microsoft did with Internet Explorer 4, but, you know... cool.

Emacs has a great mode to deal with revision control, called "vc-mode". And I really should have stopped with that, but now I had the Emacs religion. I started thinking about what other things I could run in Emacs. It turns out that lots of things we do nowadays are text-based. Such as IRC, and... um, well, that's about it really. Instant messaging, unless you want to video chat or include inline pictures. Email, unless you want to send as HTML, view attachments, or drag and drop anything. Web browsing is right out. You can use it to write a "to-do" list, though. No problem at all.

Since I'm a programmer, I wrote heaps of scripts for Emacs. I wrote one that removes carriage returns, because I don't use "tr" any more, because I never leave Emacs. I'm not quite sure what the last bit does, because I clagged it from some site on the Net. I also wrote a thing to resize my windows for me, and something else to allow me to load custom "session configurations". I hadn't ever done any of these things in Vim, despite being a hardcore Vim user for several years. I'm not sure why.

I am enjoying my developing relationship with my little friend (by which I mean Emacs), and can't wait to see what the future holds!

People I like: liedra.net | spacepants.org | puzzling.org | benno.id.au | tristesse.org | hardy.dropbear.id.au | marauder.com.au | xeny.net | progsoc.org/~curious | oneofthoseblogsonthethemeof.wordpress.com