3

Why does someone attempt to have a duplicate key in a single .dir-locals.el?

E.g.,

((nil . (...))
 (nil . (...)))

1 Answer 1

3
Convenient

We can add new per-directory variables anywhere; we don't need to locate where the same key is to set a new variable.

Efficient

For example,

;;; /tmp/.dir-locals.el
((nil . ((my/name . shynur)))
 (nil . ((subdirs . nil)
         (my/name . none))))

So my/name will evaluate to none in /tmp/file; in /tmp/*/file (or /tmp/*/*/.../file), it will evaluate to shynur.

You can implement this in other ways, but it must be messy.

2
  • 2
    Another possibility is that when dir-locals was added, it was "obvious" that there should never be a duplicate entry, but the check wasn't implemented: you might be hitting yet another undefined corner case. I'm not saying that's the case here, but it's good to always keep that possibility in mind. After all, Emacs is a 40-year-old piece of software that has had sometimes radical changes done to it: because of that, undefined behavior happens. It's good that you are exploring the dark recesses of Emacs' mind, but inevitably you'll run into such cases. Best thing to do is report it.
    – NickD
    Jul 13, 2023 at 19:50
  • 1
    @NickD: "Best thing to do is report it." -- Have added to my TODO list.
    – shynur
    Jul 14, 2023 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.