Why Emacs
"Emacs is a great operating system, lacking only a decent editor."
– An unknown vi advocate
Try evil?
If you are not using emacs you are seriously missing out.
Explaining Emacs' greatness is quite the task, and probably looks quite different from what you expect. The Editor Wars don't make sense. vi and Emacs are not alternatives. Emacs is not a text editor (though it includes one)!
TLDR
- Emacs is a replacement for your terminal. Instead of using a terminal you use Emacs.
- Emacs provides a single unified interface (including keyboard shortcuts). That emacs does everything isn't a bug, it's a feature.
- The help system is great. What is the keybind for X?
- What configuration options do I have for this package? What does this function do? Answers are often one keyboard shortcut away. Though often there is no better way to understand a function than by interactively calling it (which is tivially easy).
- At it's core Emacs is a lisp interpreter (for elisp).
- 70% of vanilla Emacs is implement in elisp. Usercode can directly interact with Emacs' core.
- Your configuration is just elisp code. The only special thing about your config file (init.el) is that it's automatically executed when emacs starts.
- Emacs is a breathing beast, that you can change while it runs. I can just write
(menu-bar-mode -1)
anywhere and pressC-x C-e
to evaluate that code to instantly reconfigure Emacs to not show the menu bar. The menu bar disappears in realtime. If you never used a good lisp you probably highly undervalue how powerful "interactive programming done right" is. - The immediate connection between elisp code and emacs makes it easy to extend emacs. Just write some code, test it, tweak it, until you are satisfied.
- Lisp is the best programming language.
- Emacs packages rock
- Extensive (~6000 on MELPA alone)
- Often they are the best tool for the job (that I know of). Examples include:
- org-mode
- magit
- gptel
- exwm
I could go on and mention how great emacs shortcuts are, how good the buffer management is, how suprisingly nood friendly Emacs is (e.g. it has great mouse support), but this is the core. Note how I didn't talk about texediting at all.
Emacs probably sucks really hard compared to the ideal pice of software that performs the same tasks. But it's so much better than everything else, that it just seems bizarre.
A Word of Warning: If you now want to give Emacs a shot, do not install spacemacs, doom, or some other such "distribution". The Emacs default configuration sucks hard for sure. I recommend to endure the suckiness at least initally (or try this, but don't let "getting the fix to work" block you from trying Emacs). The problem with spacemacs is that it tries to do everything for you. It installs ~300 packages, and configures them. When something breaks (and it will) you have no clue what's going on. But worse, if you skip building up your understanding of Emacs, you won't be able to make Emacs your own.
Table of Contents
1. Emacs the Unified Interface 🔗
Summary of this video
Is Emacs better than Vim? Is Steam better than Chrome? Is thunderbird better than Xmonad?
All these questions don't make sense. Emacs has a texteditor but it's not a text editor.
Emacs is a terminal replacement. In the terminal you run programs like vim, ssh, diff, mkdir, grep, etc. to perform your work.
Emacs provides a unified interface to do all of the same things. In magit you navigate your changes with the same commands you use to move point when editing a file. Well actually there is a pdf viewer (GUI), and a browser for emacs.
That's not to say that the emacs and terminal workflows are the same. They are very very different. Emacs is buffer based. Everything is a buffer. Even menus. And a buffer (let's ignore exwm for now) are simply text. So basically everything is text. To create a menu you write some text to a file, make it read only, add some styling, and now you have a menu, e.g. to display information about a git repo and manipulate that git repo in the case of magit.
Everything is character based, just like in a terminal.
1.1. exwm 🔗
But there is also exwm, which which you can have special X buffers that can display an X client window. This is a powerful example of how emacs is a unifying interface. Your normal graphical windows are buffers. There are many useful commands that operate on buffers. You can list them, you can search them, you can rename them, you can set buffer local variables, changing the behavior of just this buffer, you can create workspaces that contain only particular buffers, etc.
All this just works on the X buffers too, making exwm IMO the best X window manager, basically without adding any window managing functionality. We can just use the buffer workflows we are already used to.
I expect that makes implementing new features very easy. We just need to write a text processing program.
"There is a package for everything in Emacs" the saying goes. This is core of the emacs philosophy, which is all about providing a unifed interface to all the things you want to do.
But it doesn't stop there. Emacs is really a lisp interpreter at it's core. That mean this single unified interface can be scripted. Extending functionality, even of packages, is easy.
And scrpting has a fast feedback loop, because you can manipulate emacs as it runs by running commands and code interactively. You can incrementally.
2. Emacs the Lisp Interpreter 🔗
Emacs is really at it's core a lisp interpreter. And you get all the advantages of lisp.
Your configuration file is lisp code, that you can also cun interactively as emacs is running, mutating what emacs is at runtime. This is extremely useful for prototyping. You can test your code as you write it.
Of cause we also get macros and structural editing.
3. Emacs Packages are Awesome 🔗
In my experience emacs packages are great. There are very many, and they are very good. Org is not just a way to organize your notes, it's the best way to organize your notes I know of! org-roam is not just a roam like knowledge base system, it's the best roam like knowledge base system I know of! gptel is not just an interface to LLMs, it's the best interface I know of. Magit is not just an interface to git, it's the best inteface to git I know of! Org publish is not just a way to publish a webstite, it's the best way to publish a website I know of. exwm is not just an X window manager, it's the best window manager I know of!
4. Writing Plugins for Emacs and Obsidian - An Annecdote 🔗
The nice thing about emacs is that you can start writing code anywhere, immediately execute it, observe what it does, and then change it to your liking. So that's what I did when writing my typst mathblock to html export plugin, immediately after I figured out what shape my function needs to have, such that I can plug it into the org exporter. (The function needs to take in the math blocks as text and that's basically it.)
In Obsidian (and I expect VScode is similar) it took probably over 15 minutes just to setup a directory such that it conforms to how a package should look, and setting up hotreloading of changes. I didn't think about my program at. Sure that inital hurdle get's significantly smaller the next time, but it never gets to the emacs level where I can write (menu-bar-mode -1)
and then execute it with C-x C-e
.
But that's not the core probelm. The problem was that writing the Obsidian plugin just wasn't a good experience (I did not know typescript though when I started). But I also basically didn't know elsip (though I did know some clojure), when writing the emacs plugin, but I still managed to finish it in 4h.
I never finished the obsidian plugin. The obsidian plugin was about implementing a command that would move headlines or bullet list items within the tree of headlines in a structurally correct way. Move this heading before the previous one. Indent this heading one level. Indent this heading and all subheadings one level. Insert a heading after the current heading, and move the cursor there. You know, basic structural editing functinality on articles. The punchline? All of this is already build into org-mode.
Switching from emacs with org-roam to obsidian made me miserable because I knew how good things could be. I start with Emacs, then switched to Obsidian for 2 years, and then switched back to emacs. After forgetting how emacs feels, I can now say that it feels superior in every why I came to belive is important. It's even easier
5. Misc 🔗
5.1. Mouse Support 🔗
As a sidenote. Emacs is actually suprisingly mousefriendly.
- Open a random menu and unually all the options are clickable with the mouse.
- There is an entire interface for configuring basically every option of emacs (including all the options for packages), called customize, which can totally use just use with your mouse. That is both browsing and setting options has mouse support.
- The menu bar lets you run most of the important commands by selecting them with the mouse.
- You can split and resize windows with the mouse.
- Heck even the modeline has mousesupport.
Surely it exists, but right now I literally can't think of anything that you can't do with a mouse (ignoring text entry).
Maybe this seems minor, but in Xmonad you basically don't have any mouse support by default for window management functionality, and you need to run xmobar in unsafe mode for it to even be able to capture mouse events.
6. Emacs the bad 🔗
Emacs sucks at displaying inline videos. It's literally impossible. Images is basically the only visual media content that it can display. What I do instead is to have an html export of my document open side by side. Now my document can contain Unity WebGL builds.
The emacs default keybinding are very bad. You need to press control all the time, contorting your fingers. There is no question that vim like modal editing is much better default experience. I just maped LeftAlt and RightAlt to Ctrl and LeftAlt respectively.
elisp can be slow. 70% of vanilla emacs is implemented in elisp. Vanilla starts up really fast no problem. But if you install many packages you get a startup of multiple seconds. You don't want to open and close emacs all the time. There is native elsip compilation in development but this would give at most a 5x speedup, making it still much slower than vim. Though there are other workarounds like lazy package loading.
Usually this is a non-issue though. You just leave emacs running. Remote files can easily be edited with with tramp, meaning you can edit remote files over an ssh connection without needing to run emacs in the terminal. Again this unifies the interface. Editing remote files, feels basically exactly like editing local files. Invoking shell commands automatically executes them on the remote.
So this section seems a bit silly. I am trying to say how emacs is bad, but every issue seems to have a solution which seems like a strict improvement over the default. Even if emacs had a super fast startup you'd still want to use tramp.
There is one thing Emacs sucks at really hard though. Your time. Don't look and emacs sucked away days. Configuring Emacs is a never ending project. There is no clear line between your user configuration, and custom extensions. Often configuration options are "Give me an arbitrary elsip function and I will use it in this way".
7. Emacs Packages 🔗
Emacs packages are awesome! Maybe because of the power of lsip?
7.1. gptel 🔗
I just installed some more emacs packages, and I feel awed. There is a package for emacs that allows you to interact with GPT. It supports org mode. It supports branching conversations by default. Each path in the outline tree is a conversation path.
This is awesome! I literally thought very long about doing something similar, because that would make things so much better. But I thought it would take too much time. And here am I in emacs learning that this is just possible by default with gptel.
gptel also works everywhere in emacs! In every text buffer. Even if the minibuffer. It does by default not work in exwm, but after thinking about it I think it's possible with a very simple wrapper.
In the dedicated chat buffer you can also just edit the history of the conversation. Amazing. Another obsivously good feature that I wanted to have for so long.
I now also noticed that you can add a property drawer to a org heading. In there you can specifiy a system prompt, the model to use, as well as some other parameters. I didn't know that I needed that but it seems quite good.
Also in the org tree mode the first heading is ignored. At first that threw me off, but it actually makes a lot of sense. You want to have a short descriptive title.
The more I understand this package the more awed I am. I can enable gptel mode, and then save the org file. While generating responses and while editing the buffer gptel keeps track of what text was generated by the AI automaticall! When you save the file than it creates file properties that save what regions are generated by the AI. This is so simple and awesome.** Typst html I managed to write a small package to export typst instead of latex to html. Works pretty well, and it was very easy to do this. I was suprised that I was able to get the MVP working in just 4-5 hours.
7.2. exwm 🔗
Somehow exwm is just awesome. There a bunch of things that just work, which I didn't get to work in xmonad.
- Firefox can play 4k videos without lag.
- It has i3 style workspaces by default, which I could not figure out how to do in xmonad.
But more importantly configuring exwm is super easy compared to xmonad. The ability to just evaluate your configuration as you write is is great.
Also exwm has simulation keys, which allow me to basically make other applications like chrome have emacs bindings for copy paste!
Overall I think the setup that you have many windows on a workspace, without all of them being shown works really well. They are just emacs buffers, and all the functionality to navigate and manipulate the buffer objects (e.g. renaming a buffer) is applicable to the buffers that display X windows. The entire recentcy sorted history of buffers in emacs is really great, and it also works with X windows.
7.3. Org Mode 🔗
This is not something new, but now that I went back I can notice just how good org mode is. Edditing text is just fun! Changing the structure of your document in obsidian is such a sludge that I just don't want to do it. In org mode it's fun, because it's so easy. My ability to think what structural edit (e.g. indent an entire heading tree) I want to make is the limiting factor, not how quickly I can enter a long sequence of keypresses to make them!
I haven't tried to make my init.el an org file. But I exect that to be great!
8. The Default Emacs Keybinds Suck! What now? 🔗
Emacsemacs was developed on the Space-cadet keyboard in the 1970s. It has oversised control keys easily reasable with the thumbs.
Probably they just never updated the keybindings.
To prevent RSI the following can be used:
- You can remap your modifier keys. I map LEFTALT to LEFTCTRL and RIGHTALT to LEFTALT. (I also swaped TAB with CAPSLOCK.)
- I also tried Capslock as CTRL but that felt worse (it's possible to make CAPSOCK CTRL when other keys are pressed and ESC when pressed alone.) I also swaped tab and
- evil-mode: is a vim emulator.
- god-mode: Vim like modal editing for default Emacs shortcuts. (I didn't like it when I briefly tried it.)
Currently I use the default Emacs keybindings and 1.
To remap control keys I use I use xremap.