Skip to main content

The Craft of Emacs

Emacs Lisp development

1 hour

We’ve had a pleasant journey dipping our toes into Elisp.

We’ll dive deep in the next chapters, but before then it’s worth confronting the elephant in the room; the largest hurdle when it comes to crafting Emacs.

You have probably already noticed it. In fact, it may have caused the code to swim before your eyes, made you slightly dizzy, and perhaps even resulted in slight headaches. You may be mildly allergic to braces (...) .

The way of Emacs is lined with dense thickets of braces. Your exposure to them will only increase as you proceed. If left ignored they will trip you up and cloud your vision, leave you feeling lost and confused, and at worst cause you to stop.

Remember that you’re not alone. All Elispers struggle with syntax when they first explore the language. The more experienced ones have invented a few remedies:

Even with these rules you may feel at a loss as to how to read Elisp. Braces serve little guidance when navigating large swathes of code. For this reason, I have included a reading exercise at the end of each chapter. This shows you how I read the code, step by step, and what thoughts I have as I do so. It’s heavily opinionated — no two programmers read code in the same way — but may serve as a guide.

Browse the reading guide below.

Define the command xx‑view

(defunxx‑view
()
(interactive)
(normal‑mode)
(coe‑xx‑mode)
(coe‑xx‑ruler‑mode)
(coe‑xx‑basket‑clear)
(coe‑xx‑basket‑add)
(coe‑xx‑basket‑view)
)

It has no arguments

(defunxx‑view
()
(interactive)
(normal‑mode)
(coe‑xx‑mode)
(coe‑xx‑ruler‑mode)
(coe‑xx‑basket‑clear)
(coe‑xx‑basket‑add)
(coe‑xx‑basket‑view)
)

It resets the mode of the current buffer

(defunxx‑view
()
(interactive)
(normal‑mode)
(coe‑xx‑mode)
(coe‑xx‑ruler‑mode)
(coe‑xx‑basket‑clear)
(coe‑xx‑basket‑add)
(coe‑xx‑basket‑view)
)

It displays the pattern for the current buffer

(defunxx‑view
()
(interactive)
(normal‑mode)
(coe‑xx‑mode)
(coe‑xx‑ruler‑mode)
(coe‑xx‑basket‑clear)
(coe‑xx‑basket‑add)
(coe‑xx‑basket‑view)
)

It displays a ruler

(defunxx‑view
()
(interactive)
(normal‑mode)
(coe‑xx‑mode)
(coe‑xx‑ruler‑mode)
(coe‑xx‑basket‑clear)
(coe‑xx‑basket‑add)
(coe‑xx‑basket‑view)
)

It clears the pattern shopping basket

(defunxx‑view
()
(interactive)
(normal‑mode)
(coe‑xx‑mode)
(coe‑xx‑ruler‑mode)
(coe‑xx‑basket‑clear)
(coe‑xx‑basket‑add)
(coe‑xx‑basket‑view)
)

It adds the current pattern to the basket

(defunxx‑view
()
(interactive)
(normal‑mode)
(coe‑xx‑mode)
(coe‑xx‑ruler‑mode)
(coe‑xx‑basket‑clear)
(coe‑xx‑basket‑add)
(coe‑xx‑basket‑view)
)

It views the contents of the basket

(defunxx‑view
()
(interactive)
(normal‑mode)
(coe‑xx‑mode)
(coe‑xx‑ruler‑mode)
(coe‑xx‑basket‑clear)
(coe‑xx‑basket‑add)
(coe‑xx‑basket‑view)
)

The best way to acclimatize yourself is through experience. The more code you encounter, the easier it will be to read it. To veteran Elispers, braces are a mere detail, if noticed at all.