Entropic Thoughts

Why You Should Buy Into the Emacs Platform

Why You Should Buy Into the Emacs Platform

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 core1 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 editor2 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 Magit3 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.

This List

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

Emacs
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 engine4 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.
Troubleshooting
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-report with 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 experience5 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> <e> <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 emulation6 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.

Keyfreq
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.
Versor

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 dimensions7 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
Comint

Emacs has a built-in mode called comint, which probably stands for something like “command interaction”. That it does is launch a command-line application (like python or psql) and then has some features to interact with it, like throwing expressions at it from your text file, or browsing its history, or whatever.

The neat thing is that this turns even the most basic, un-human-friendly command line interface into a super high-level, nice thing to work with, nearly for free! It’s very cool.

tramp

Despite the funny name, tramp means serious business. It’s an adapter layer that speaks a bunch of different network protocols and essentially lets you treat a remote filesystem as if it was local. I can’t explain just how amazing it feels to enter a path on a remote machine in the “open file” dialog, and then when the file is opened, the sidebar shows the files in the same directory on that remote machine. As if it was a local directory.

It is even cooler when combined with a two-pane file manager such as Sunrise, described below. Now I can manage files on all machines I have remote access to as though they were part of one, huge, networked file system.

Text Editing (general)

Interactive insert-char
It took me some time to learn to appreciate the insert-char function. 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

emacs-undo-tree.png

Figure 1: An example of the edit tree after I have done some config changes.

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.

Smerge
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”.
Synosaurus
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
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.
Paredit/Smartparens
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.
Outshine

Sometimes you don’t want to split your code into multiple files, for whatever reason. The traditional Emacs solution to this has been to insert page breaks (ascii form feed character, 0x0c) to denote sections of code, with the obvious associated navigational commands.

Outshine reads the comments in your code, and if they follow the Org convention of headlines, actually lets you split up your code into sections, with sub-sections, and sub-sub sections and so on. These sections are foldable, naturally. It’s a very neat way to organise stuff once you get used to it.

Programming Language-Specific

ESS
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.
Intero
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

Org
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
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.
Calc

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 caculator8 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.

Dired

The directory editor is a solid file manager built in Emacs. There are two really cool things I have discovered about it so far: one is that when the already powerful features of dired fails you, you can ask for a directory listing to become writeable, in which case it will look like a regular text file, where you get the full text processing power of Emacs to edit the directory listing to look the way you want it to, and then commit the changes. Dired will update the file system to produce the directory listing you want.

The other is that dired appears trivially extendable, so it is used as the base mode for a bunch of other useful things, among which I use dired-sidebar (compact file browser) and sunrise-commander (orthodox file manager built in Emacs on top of dired). By extending dired, these modes get the powerful file managing capabilities of dired for free.