Happy New Year! Let’s celebrate with an Emacs article.
There are few pieces of software as widely misunderstood as Emacs. Emacs is frequently advertised and discussed as a text editor, but please be clear on this: Emacs is not just a text editor.
Emacs is a platform for developing end-user applications with a text-based core11 This idea of a text-based core is something I’ll return to in a later article when I get the time. It’s a brilliant idea, and certainly not unique to Emacs.. The Emacs platform ships with a few built-in applications, such as: a calculator, a terminal shell, a file manager, a merge tool, and yes, a text editor22 Which is extremely capable – but has a god-awful interface. Fortunately, any Emacs application can be extended and modified dynamically, so this turns out to not be such a big problem in practise..
What I Mean By “Should”
I started using Emacs as a drop-in Vim replacement about a year ago, but the last few months I’ve discovered that there may be more to Emacs than just a better Vim. Once you really dig into Emacs, you discover all these great things that you wish you knew about much earlier; it’s an entire ecosystem hidden from people who don’t regularly use Emacs.
I don’t care what editor you use for source code – you can use Quickbasic for all I care – but look, you have to know that Magit exists. Even if you don’t use Emacs in any other capacity, you may want to use it for Magit33 Or you may not. But at least now you’ve made an informed decision about it.. The same thing goes for a bunch of other applications that run inside Emacs. Saying “I don’t use Emacs” is a little like saying “I don’t use the jvm.” Sure, that may very well be true for a host of reasons, but if the reason is that you didn’t know what the jvm was, then that’s an easily fixable error.
Table of Contents
My mental list of reasons to become familiar with Emacs grows nearly by the day, and I can’t keep track of them all anymore. In other words, this article is mostly a braindump, but it will also serve as an index for possible future in-depth texts about these things.
I was going to just write a sentence or two about each item, but then there were more things to say so I’ve split this list up into categories.
Core Platform and Basic gui
- Well, I have to put this somewhere. The Emacs platform is flexible and easy to write applications for. Without the great design of the platform, none of the things below would be possible. The fact that it’s a gui application running on a command-line engine44 That may sound odd if you’re a hardcore terminal user (like myself) but trust me, it’s a good thing. Think of it a little like having an X11 client running with just terminal windows. You could get by without the X11 client, but it helps sometimes that it’s there. is brilliant.
- Emacs has great built-in capabilities for figuring out what
went wrong. If you experience some slowness in the editor, for example, you
can figure out how to reproduce it and then execute
profiler-start, reproduce it, and ask for a
profiler-reportwith a neat breakdown into what was taking so long. It took me a long time to get used to this because I have seen it in exactly zero other editors.
- God mode
By default, virtually any operation in Emacs requires you to hold down modifier keys like control, shift, meta, super etc. Put simply, God mode is an extension that gives you the option to toggle into a global modifier state: if you press escape, you enter a state where any key press is interpreted as though you held down modifier keys. This provides a modal editing experience55 Nota bene: This makes it sound Vim-like, but that is not the case. The command language of Emacs is nothing like that of Vim, which I still think is vastly superior. However, there are other reasons to prefer God mode. on top of vanilla Emacs.
One of the strong points of God mode is that you still have access to all the regular Emacs keybinds in the “insert mode”. If I’m typing in the middle of a line and want to go to the end of the line, I can either take the God mode route of
<esc>– or I can take the Emacs route of
C-e. I get the choice, and that’s surprisingly convenient.
In my limited experience, God mode also integrates better with the rest of Emacs than Evil mode. That’s why I switched from Evil mode to God mode: I have found the threshold to entry to other parts of Emacs lower when you stay reasonably true to vanilla Emacs.
- Evil mode
Evil mode is very nearly a full Vim emulation66 You will probably have to learn a tiny amount of Emacs to be comfortable with Evil mode, but it is telling that I remember someone saying something to the effect of “If it doesn’t work like in Vim, that’s a bug.” inside Emacs.
If you want nothing but a good text editor, get Emacs and run Evil mode in it. Even if you are already a Vim user, please give Emacs and Evil mode a serious try. I know Vim emulations tend to suck, but Evil mode is really, really good. And you get all the benefits of the Emacs platform.
- This little gem sits in the background and records the commands that are executed by the Emacs cli engine during regular Emacs usage. Then at some point, you can review what commands you execute most often, and create better keyboard shortcuts for those, should you want to.
I haven’t dug too deep into Versor (versatile cursors) yet, but it appears promising. The idea is that we can view the arrow keys as traversing the document in two dimensions77 These dimensions are normally the Cartesian/rectangular coordinates (line; column)., and if we do, there is nothing stopping us from assigning different dimensions to the arrow keys depending on context, see table 1.
Table 1: Ideas for arrow key dimensions in various contexts. Context left-right up-down English prose words paragraphs html documents sibling elements parent-child elements Java code expressions statements
Text Editing (general)
- Interactive insert-char
- It took me some time to learn to appreciate the
insert-charfunction. When called interactively (most commonly by pressing
C-x 8 RET), you get a list of all Unicode characters. You can search through this list for characters to insert (e.g. Latin small letter i with diaeresis) or just write the Unicode character index, and then the return key will insert the character in question.
- Interactive what-cursor-position
- This one is practically the opposite of
the previous one. When called (normally with
C-x =) it displays information about the character currently under the cursor.
- Undo Tree
I don’t know how much of this is built into Emacs, but I do know you get a killer interface to it with Undo Tree. Imagine you do some edits and then you think, “Maybe this wasn’t such a good idea after all,” so you undo your edits. Then you try a different approach, and start to make some new edits. Wham! Your edit tree just branched.
With conventional undo semantics, the other branch of your edit tree just silently disappears. There can only ever be one branch active, and the others can no longer be reached. That is still the basic assumption with Undo Tree, but if you bring up the tree interface, as you can see in figure 1, you can switch active branches much like with version control.
- I’ve never found any version control conflict resolution tool that actually made sense to me. I like SMerge though, because you still have the conflicting file open as a regular file in Emacs and can edit the conflicts manually. All SMerge does is provide highlighting and give you quick aliases for common key sequences, like “delete my version here” or “jump to next conflict”.
- Why not have a thesaurus you can trigger by navigating to a word and pressing a hotkey? The cool word processors on the block do. I still look up synonyms on the web out of habit, but I should be better at using Synosaurus. If nothing else, I can use Synosaurus even without an internet connection.
Structured Text Editing (i.e. programming)
- Htmlize is one of those little things that I never even thought it may exist, but it’s an obvious extension to any source code editor. All it does is export the currently open file as an html document with the current syntax highlighting as inline styles. So a little like taking a screenshot of your code except you can still copy and paste from it.
- Probably the holy grail when it comes to editing text that is structured with balanced delimiters, like parentheses. Paredit lets you treat the current pair of parentheses like a selection that can be extended, shrunk, inverted, you name it. Very cool.
- Emacs Speaks Statistics is a collection of related editing modes for various statistical languages, of which I use R. I’m not sure what this is like compared to the alterantives, but from what I understand it’s one of the better ways to work with R code.
- If anyone ever says Haskell doesn’t have a good ide, it’s because they haven’t used Intero. Sure, it’s very opinionated and comes with all of the bells and whistles, but isn’t that what you expect when you look for an ide? Intero is incredibly competent and comes with integrations for just about everything.
Full Applications Within Emacs
- I don’t know where to start. Org. Does. So. Much. It does outlining (structuring) documents, human-readable markup, producing documents, generating websites such as this one, keeping track of todo lists, priorities, scheduling, deadlines, tracking time, creating bills from effort estimates, budgeting … and it’s built in a modular fashion so while the core is reasonably small, all those things above are easily supported by extensions.
- Notmuch normally refers to the email indexer, but in this article, I’m talking about the Notmuch email client that is built for Emacs. It’s probably the best Notmuch client there is, and it’s even better in combination with Org. I can now press a few keys to create tasks from my email, thus finally getting closer to a true inbox zero.
And, last but not least, the thing that triggered this article to begin with. Learning about Emacs Calc was what made this list too long to keep in my head.
My first impression of Calc was kind of meh. An rpn caculator88 Reverse polish notation, or rpn, is an input method for calculators where, instead of typing
3 * ( 7 + 4 ) RET, you can type
7 RET 4 + 3 *. As soon as you press an operation (like plus), it is performed on the last two numbers the calculator saw – it does not wait for a new number. This way of entering expressions removes the need for parenthesis and rules for order of operations entirely.? Who even wants that? That seems like a stupid, silly idea some geek had at some point and then nobody bothered to change it.
How wrong I was! The Emacs Calc mode is wonderful. It’s incredibly powerful. All the things I used Google or Wolfram Alpha for? Unit conversions, symbolic manipulation, differentiation and integration, that stuff? Emacs Calc does that for me, offline.
Turns out rpn isn’t such a bad idea after all either. I prefer it now that I have given it an honest try, so I got an rpn calculator for my phone too.