Emacs .dir-locals.el Tutorial

Here’s another tutorial for a useful feature using the world’s best text editor: directory-local variables. Specifically, this will be about proper CL macro indentation, even when you don’t have a Sly/Slynk client running and connected to Nyxt.

Turns out, you can customize lisp-indent-function (or rather, common-lisp-indent-function) so that macros are indented properly instead of being treated like just another function. My .dir-locals.el file looks something like the following:

  ((eval . (let ((macros (list 'define-configuration
              (lambda (sym)
                (put sym 'common-lisp-indent-function 1))

The first line indicates that the following would be eval’d (with user consent) whenever Emacs’ lisp-mode gets enabled. The define-configuration macro in the list is obviously Nyxt-specific, with the alex namespace / nickname being a re-exported alexandria package, which has plenty of useful general macros.

This .dir-locals.el file you would place at either the root directory of your dotfiles’ project, or the directory where your config.lisp etc are located.


Hmmm, that’s useful! Would you have time to open a PR with it, by any chance? It’s quite a lot of manual search for things, but you’ve already dipped yout toes in it, so you’re in a best position to make a reasonably working file :slight_smile:

Incidentally, I already suggested this but I guess @ambrevar didn’t understand what I was getting at…

Just so we’re clear: are you talking about Nyxt’s .dir-locals.el, or a sample .dir-locals.el file others can use for their configs, or what?

I’m talking Nyxt one!

I thought of it, but I’m not entirely sure it would be the best idea, at least for Nyxt proper, since you’d hope if someone was hacking on Nyxt, they’d have a REPL setup and thus wouldn’t need this…