Joining The Church Of Emacs
A summary of how I configured my Emacs
Published on 03 October 2022
Last updated on 28 October 2022

All your computing are belong to us

Emacs, which stands for "Eight Megabytes and Constantly Swapping" is a 46 year-old text editing program.

Everything about Emacs, from its UI to the action performed when you press the Enter key, is hackable. You are encouraged to extend the behavior of the Emacs program by writing functions in the programming language it speaks: Emacs Lisp.

In practice, this means you have over 2000 commands at your disposal, out of the box.

For example, the align-regexp command allows you to vertically align a region of text based on a regular expression rule. Say you have the following badly-formatted mess:

one = 1
fortyTwo = 42
elite = 1337

Calling align-regexp = after selecting the above snippet will yield:

one      = 1
fortyTwo = 42
elite    = 1337

This makes for a long-running Emacs joke; the idea that typing M-x literally-anything will result in exactly what you want is very amusing. In fact, while writing this article I got tired of typing out the markdown syntax for links, so I searched in the list of commands for "markdown link" and, lo and behold, markdown-insert-link exists and is even bound to SPC c l (more on this later). The following comic sums this up perfectly:

Real Programmers, by xkcd

Ultimately, Emacs was built around empowering end users, not just developers and plugin authors, to do any kind of computing they want, without ever leaving Emacs1.

I'm using Linux. A library that Emacs uses to communicate with Intel hardware.

― Erwin, #emacs, Freenode.

Emacs Lisp

At this point, I've been using Emacs for a little over two months. During that time, I haven't written much Emacs Lisp because I haven't needed to program Emacs myself; almost everything that I needed to do was available in the form of a package.

MELPA, Milkypostman’s Emacs Lisp Package Archive, is a repository of over 5000 automatically updated and curated Emacs Lisp packages. With access to so many extensions, configuring my Emacs consisted of customizing a few built-in properties and aggressively yanking other people's code — just like I've done with VS Code.

In a way, the "real power" of Emacs is lost on me. There are many aspects of my workflow which would benefit from automation. However, as with all automation endeavors, how do you know if the cost of writing that script is less than the total time spent doing the task manually?

Still, using Emacs means you most probably can program that niche script, if you really want to. And even better, someone might've come up with a snippet to do it already.

Eye Candy

Honestly, I'm not a very good hacker. Because I care about the way user-facing programs look and feel. And while Emacs is very attractive to the tinkerer in me, its UI philosophy is in stark contrast to anything made in the last few decades.

Emacs Default
The default Emacs greeting window

Back in 2020, a lively thread was started on the emacs-devel mailing list in reaction to a Redditor asking "Why is Emacs so square?". Somewhere in the chain of replies, one can find the following message, by the original author of GNU Emacs:

Perhaps we should implement a mode that puts cosmetics on Emacs so it will appeal to those who judge by the surface of things.

— Richard Stallman

You can read more about this drama, the view of Emacs developers around UI/UX, and the challenge of making Emacs accessible to a wider audience in the excellent article Making Emacs Popular Again, by the LWN.net computing news site.

No big deal. Emacs is ridiculously malleable and I'm not the first person to attempt revamping the UI.

Spacemacs
Spacemacs, a popular Emacs distribution.
DOOM Emacs
DOOM, a faster alternative to Spacemacs.
NANO Emacs
N Λ N O, a very lightweight and modular configuration by Nicolas P. Rougier.

With a good idea of what's possible, I sought to customize Emacs to my liking. I was determined to make it look OK. First, I removed the title and menu bars, the scroll bar, and any cruft that cluttered my 14" laptop screen.

Next, I wrote a custom dark color scheme, which was surprisingly simple. In a nutshell, every UI element has a corresponding face; a set of properties that controls its background color, its font-weight, its size and so on. Consequently, writing an Emacs theme felt a lot like writing CSS.

Finally, I needed to get rid of the ugly status bar, or in Emacs-speak, the modeline. However, handling how the modeline renders each piece of information available user-facing was a complex undertaking and I didn't have enough knowledge of how Emacs works to accomplish what I wanted.

For example, N Λ N O's modeline code alone is more than 500 lines. For comparison, my entire configuration is under 400 lines of Emacs Lisp. Writing a fancy and functional modeline would shatter my complexity budget.

Instead, I "borrowed" DOOM's modeline, which was luckily published as a standalone package on MELPA. With that, I had something that indeed looked OK, at least to me.

My Emacs
The source document of this article opened in my Emacs.

I don't like Emacs' strong dependence on modifier keys. By default, opening a file is C-x C-f (i.e. Ctrl+X followed by Ctrl+F) which I find to be very awkward. Instead, I appreciate (Neo)Vim's modal editing approach better.

Modal text editing means for example that instead of typing C-n to move the cursor down one line, you only type j. The downside of this is the introduction of distinct modes. In "normal" mode, pressing j would indeed move the cursor down one line, but in "insert" mode the "j" character would be typed instead. In (Neo)Vim, switching to "normal" mode is done by pressing ESC while i sends you back into "insert" mode. There are other modes as well, such as "visual" (for making selections) and "terminal" (for terminal emulation).

There is a popular Emacs package called Evil, which provides Vim2 emulation. This makes Emacs an almost drop-in replacement for (Neo)Vim, which was important to me as I was a very avid Neovim user before deciding to switch teams.

Evil worked well for a while. Then I started to notice its keybindings weren't working consistently across all of Emacs. I had my leader key set to Space which meant I could configure it to open a file by typing SPC f from anywhere. A big improvement over C-x C-f. This approach of using the Space key for keybindings was popularized by Spacemacs. Yes, the word "space" in "Spacemacs" supposedly refers to the Space key.

It turns out there are many solutions to my problem with Emacs modifier keys, other than Evil. God Mode for example works by straight out removing Ctrl and Alt from all keybindings. So that C-x C-f becomes x f. This was nice and all, but I wanted something more Vim-like. And I was in luck.

Meow is yet another modal editing mode for Emacs. Here is why I decided to go with it:

  • Inspired by God Mode, any keybinding of the form C-a C-b C-c is by default routed3 to SPC a b c. This meant I wouldn't have to re-bind every single Emacs command in order to avoid modifiers.

  • Meow's modal editing model is very much an improvement over classic Vim. It applies many of the ideas recently introduced by Kakoune. Read this blog article for a more thorough comparison of Vim and Meow.

  • Meow was designed for consistency with Emacs. Unlike Evil, it provides built-in support for using Space as the leader key. Now my SPC f keybinding works everywhere.

What was lost in this little transition is my Vim muscle memory. On the upside, I found myself to be using fewer keystrokes to achieve the same results. And in any case, one could not expect to use Vi modal editing everywhere, and where it is supported, but it's often not the default.

It's Magit!

Magit is an Emacs package that provides a text-based interface to Git. Unlike most GUI interfaces to Git, it exposes everything from the common to the most advanced Git features with a few keystrokes. I can type SPC v (for Version control) to bring up the Magit interface:

Magit buffer
A Magit buffer open to the bottom of my window

As you can see, it displays the latest local and remote commits, untracked files, and (un)staged changes. You can stage individual sections of a file by simply scrolling to them and pressing s; something that is much less ergonomic in command-line Git and is done through Interactive Staging.

Next, press h to bring out a view of all possible actions supported by Magit:

Magit help
The Magit help buffer

This is a high-level view of everything you can do in (Ma)git. Pressing any of the suggested keys will bring out further menus where Magit will narrow down your action all while showing you all available options, at every step.

This transformed my Git workflow from reading the man pages and copying commands from Stack Overflow, to completing my way through the Magit buffer. It also helped me discover many cool features I wasn't aware of, such as Auto-squashing; exactly like one discovers functions by scrolling LSP auto-completions.

Org-anize all the things

Emacs comes with support for a document format called Org:

[Org is] a GNU Emacs major mode for keeping notes, authoring documents, computational notebooks, literate programming, maintaining to-do lists, planning projects, and more — in a fast and effective plain-text system.

I use Org for managing notes and to-do lists. Interestingly, the Org file format includes syntax for scheduling to-do items, managing priorities, setting deadlines, enforcing habits, and so on. All in plain text. With this information, Org Mode can scan all your Org files to generate an Agenda view:

Org Agenda example
Actionable Agendas, from the Org Mode website.

Next, I use the proprietary but very convenient Dropbox service to sync my Org files with my Android phone. And luckily for me, I don't have to run Emacs inside Termux. Because the Orgzly application provides a touch-screen-friendly interface to my Org files, and can send push notifications for upcoming to-do items.

This is very basic usage of Org Mode. If you're more curious about how some of the more demanding work schedules look like in Org Mode, I recommend reading Get Things Done With Emacs by Nicolas P. Rougier.

Closing words

This was a summary of my experience with configuring and using Emacs. I tried to focus on what sets Emacs apart from other text editors and IDEs. And what I found to be so special about it. Throughout the last two years, I have used Vim, Neovim, VS Code, Jetbrains IDEs, DOOM Emacs, Spacemacs and now vanilla Emacs.

It is certainly true that Emacs isn't a very popular IDE. Only 5.33% of respondents in the 2021 Stack Overflow Developer Surgery claimed to use the thing. Despite that, there is a rich community around Emacs, comprised of people determined to carry it through the 21st century. The fact that this software project existed continuously for nearly half a century is a testament to the stubbornness of the hackers involved with it. This gives Emacs a unique sense of timelessness.

It's a tale as old as time: a stubborn, shell-dwelling, and melodramatic vimmer -- tormented by Vimscript and his boundless productivity -- makes a formal request to the netherworld for a transfer. They agree. The terms? He must lure more unsuspecting souls into a life of eternal bikeshedding. Now he runs the place.

— Henrik Lissner, author of DOOM Emacs


1

Assuming that your computation is expressible in the Emacs Lisp programming language.

2

Vi refers to the original version of the text editor commonly known as Vim. In fact, Vim stands for "Vi IMproved". Neovim is a more modern project which uses the programming language Lua instead of the often dreaded Vimscript for writing extensions. Neovim is compatible with Vim v8.

3

There are more rules to deal with keybindings that use Alt. For example C-x M-t is SPC x m t and C-M-x is SPC g x.