Generalized Abstraction

An Emacs Survival Guide

Thursday, October 29 2020
  1. Managing the Learning Curve
  2. Customize As Much As You Want

I expect the learning curve with Emacs is a core reason why people tend to not use it with the same exhuberance with which other text editing software and IDEs are utilized. While it has become less common for modern developers to use classic editors like Emacs and Vim, Emacs has even less of a following than its "evil" rival. It really is a shame too, because Emacs is truly the classic workhorse in just about every possible way.

I won't lie, it took me a while to get on the Emacs train. Over the years, I've always had a general preferencee for simplicity over complexity. It's great to have a lot of nice features, but ultimately I'm looking for a simple tool to edit text. This is where apps like SublimeText, BBEdit and TextWrangler, Notepad++, Kedit, and similar really shine. The interfaces aren't bulky, you can edit text, and, well, what else do you really want? Maybe a little more.

When I'm progamming, it's definitely nice to have a linter. As much as I prefer statically-typed, compiled languages and I know a portion of the development process includes getting put in my place by the compiler, it's helpful to have a tool to catch errors during development. Similarly, when I'm writing research papers or blog posts, it's definitely nice to have a spell checker. It's not that I can't spell, but rather I type pretty fast and that's just naturally conducive to typos.

And, since my projects rarely consist of a single file, it's nice to have some sort of tool to manage the project as a whole. Searching within the project, version control tools, being able to quickly open and close a set of files, etc.

As it turns out, there are actually a lot of tools which offer value. And in fact, while there are many of these tools which are available out-of-the-box, the beauty of Emacs is that as a user, you have the ability to customize to your heart's content.

Managing the Learning Curve

While it is true that Emacs can be complicated, we also have the ability to get information in real time as we need it. Let's identify some basic functionality.

The most important command is going to be our trap door command, C-g which is how you cancel. Suppose you start opening a file and you see the find file interface in the mini-buffer, but you don't actually want to find the file – you just hit C-g.

ActionCommandLisp Function
Open a fileC-x C-ffind-file
Save a fileC-x C-ssave-buffer
Move to the beginning of the lineC-abeginning-of-visual-line
Move to the end of the lineC-eend-of-visual-line
Move down by paragraphC-vscroll-down-command
Undo ModificationC-/ or C-x uundo
Move up by paragraphM-vscroll-up-command
Quit EmacsC-x C-csave-buffers-kill-terminal

The first point to mention is the command notation. For example, if I want to open a file, I use C-x C-f which means to execute ctrl+x followed by ctrl+f. This is called a binding or key binding and means that we are associating the command sequence C-x C-f to a lisp function find-file.

Suppose we wanted to customize one of our key bindings; we can easily do this by writing a line of lisp code which we store in an initialization file. As an example, I tend to use the command to move backwards and forwards by a single word a great deal. Out of the box, this is bound to M-f for move forward by one word and M-b for move back by one word. However, given how I tend to hold my fingers over the keyboard (I actually re-map the caps lock to ctrl), I find these bindings rather uncomfortable. Additionally, as a Mac user, I have grown accustomed to using 'option' along with the left and right keys to accomplish this. I also tend to use Command along with the left and right keys to move to the beginning and end of the lines. I don't want to stop using C-a and C-e, but I do want to add some additional key bindings.

(global-set-key (kbd "s-<left>") 'beginning-of-visual-line)
(global-set-key (kbd "s-<right>") 'end-of-visual-line)
(global-set-key (kbd "M-<left>") 'backward-word)
(global-set-key (kbd "M-<right>") 'forward-word)

In order to reference the OSX "Command" key, we use s, so CMD with the left arrow key is expressed by s-<left>.

Customize As Much As You Want

Suppose Emacs doesn't do something you want it to do out of the box – no problem, you can extend the functionality. This is really one of the aspects of Emacs that givess the user so much flexibility if you have the time and determination to learn a little bit of Elisp code.