Andrew Burke

On Twitter

On Facebook

Baby Steps With EMACS
Posted on: 2007-04-07

I've been using EMACS as my text editor of choice for several years now. When I started using the UNIX shell in OS X I had been reading The Pragmatic Programmers, who suggested getting to know one text editor really well. I had recently had a very bad experience with a bloated IDE that leaked dozens of megabytes every time I tried to load a text file, so I was very interested in small and fast text editors.

I had tried VI, but had a number of really ugly early experiences with typing while not in Insert mode, and so settled on EMACS. It helped that I had recently read In The Beginning Was The Command Line in which Neal Stephenson effuses about EMACS.

I know that, given its early history, it's kind of ironic that I use EMACS for its small footprint and high speed - but it is a small nimble application compared to, say, Eclipse. I now have EMACS built into my muscle memory, so while all the cool kids are using TextMate, I'm still rolling along with ten terminal windows, half of which are running EMACS.

Although I chose EMACS partially because of the vaunted extendibility and customizability, I haven't really done much special with it besides installing modes for Ruby, Java, JavaScript, and PHP, and letting Sacha " 'Livin' La Vida EMACS" Chua install some handy extensions. It's a bit like a financial planner who only drives from the burbs to downtown but has an F350 pickup truck "just in case".

Well, I've finally started getting off-road: I've started adding my own keyboard shortcuts. It's not writing Nethack in Elisp yet, but it's a start, and I understand that there's no turning back.

First, in the Ruby mode, I set CTRL-C f to toggle selective display at 3 columns - that way I can easily shrink a class file to just show the defs and the top-level comments. It's code folding without all the overhead. The folding function is from minor emacs wizardry and I set up the shortcut myself:

(defun jao-toggle-selective-display ()
  (interactive)
  (set-selective-display (if selective-display nil 3)))

(global-set-key "C-cf" 'jao-toggle-selective-display)

Then tonight I finally got tired of typing Meta-X comment-region and Meta-X uncomment-region in full, so I assigned them to CTRL-C r and CTRL-C R in my .emacs file. Now I can comment out whole chunks of code with one keystroke, and uncomment them just as easily:

(global-set-key "C-cr" 'comment-region)
(global-set-key "C-cR" 'uncomment-region)

Hmmm... offroad!

Previous: Back in Santa Cruz Next: Analgesic Code: Backtrack
Check out my iOS app:
Remembaryicon72

Remembary: The Connected Diary

Other Blog Posts: