Nistur

jump to main content

On Emacs

I thought that I would just take a break from my lisp series to talk about something else which has come up recently.

Photo by Viktorya Sergeeva
Emacs. I use it every day for a multitude of different purposes, and I've had people ask why. From the look of it, it feels old fashioned and there are often features in more modern software which are missing.

But are they?

Before I get to that, I will first address the Unix purists who may be reading this. I complain about a lot of pieces of software which try to do too much and, in over-stretching themselves, fail to do one task properly. I realise that the Unix way is to do one thing, and do it well, and to achieve complex behaviour by composition of parts. I not only agree with that, but I also design my projects around it. Emacs seems to be contrary to this ideal. I could make the argument that the separate packages/.el files consitute these small parts, rather than Emacs as a whole, but the reality is: I don't care. As far as I'm concerned, Emacs is the exception that proves the rule. It does what I want, and it does it well, so I don't mind that it breaks the Unix paradigm.

I was not always an Emacser, I actually started off on the vi/Vim side of The Great War, but in roughly 2008 I tried Emacs and it changed my life. Since then I have used it to write code, to write my dissertation, to write my CV, to read and write email, to connect to IRC, control my music playback, and to harness the power of the butterfly. Could I have done all of this with separate tools? Sure. The difference here is the magic word: integration. At the most basic level, having access to the emacs kill-ring betwen everything I'm doing has changed how I work a lot. For those unaware, this means copy/pasting… "but-" I hear you say, "you can copy and paste between different programs as much as you want" and this is true, but the kill-ring is not just a simple copy/paste, but it stores the copy/cuts in a ring buffer, so you can cycle back through many different things. It sounds like such an inconsequential thing, something you could do by just going back and re-copying the thing you wanted, but honestly, once you start using this, it makes a big difference and you never want to go back. Of course this is not the only way that the integration helps, but it is the easiest to explain to those who don't use it.

So, what about these missing features then? Well, two that I've been asked about most are: HTML rendering in emails in gnus - this one is valid, but I have yet to actually find an email where I cared about this. I can easily open attached images in an external image viewer with a key press, and nothing else has caused me issues. IDE quality of life features, like jump-to-definition, or refactoring, or, or, or. You can bet that most of these, regardless what they are, already exist as packages that you can pull in. Those that don't are either because you're asking the wrong question, or that they're so trivial to do that they don't deserve a package.

Photo by Startup Stock Photos
Let's talk about the features then. As I spend most of my Emacs-life coding, this is also where most of my experience lies. Until last year, I only used Emacs for small personal projects, which I could easily keep in my head at once. For this reason, the effort of setting some of these up always just seemed like too much effort, when I could be making progress. Since I started working at Egosoft, I was free to work in Linux, which meant I was able to set up Emacs to work how I really wanted it to. It turned out that it was actually very simple. There is literally a package to do almost everything. So I have Company Mode set up for code completion, and Eglot providing language server interfaces. I have even started adding automatic generation of a 'compilecommands.json' file in my my latest personal project just so clangd can parse my project for this. It has changed Emacs from 'an editor I use to code in' into a powerful IDE.

But how about the things that I can't just do by installing a package? Well, as I said they fall into two categories. One is that you're probably asking the wrong question - this sounds like a facetious response, but it's fairly accurate. A number of times I have tried to find "how do I do this thing I'm used to doing in Visual Studio, in Emacs" only to find that you cannot, because you do something else in Emacs. Emacs doesn't necessarily adhere to modern standards (i.e. anything standardised in the last 3 decades) so to get the same result, you probably have to change the way you think to the Emacs way. This isn't to everyone's liking, but it works for me.

The last category then is trivial things. I have left this to last because it can make you look like an Emacs guru by doing very little. It is well known that Emacs is extensible. Editors like Visual Studio Code dream of being as extensible as Emacs. If you know how, you can change pretty much every single thing about Emacs. It is basically just a Lisp environment, in which someone has built an editor. As I've mentioned before, I cannot lisp, so I have done only the bare minimum needed to customise Emacs, but even so have a far more comfortable editor. To compile a project, you run `compile`. This you can do with the Tools menu at the top, or typing `M-x compile` (M- being "Meta", or the Alt key, sometimes Esc) but this is a bit clumsy, so I long ago bound it to F5, to make the most of my Visual Studio muscle memory. Since then I have extended this to four different key combinations, depending on what I want to do (just compile, compile and debug, compile and deploy to Steam and debug, or just debug) and none of these were things which Emacs could do, but just took a few lines of Lisp to add the functionality. I cannot overstate how freeing it is, when you have one of those "urgh, why does it do it like this? I wish it did X" moments, to just go and change the way it works. It is not a scary thing at all. There is plenty of documentation, and decades of examples.

I use Emacs because it makes using a computer fun.

And yes, this website is written in Emacs.

Photo by Deva Darshan