4

There is a project called Piglit with a .dir_locals.el file like this:

((nil . ((indent-tabs-mode . t)))
 (python-mode . ((indent-tabs-mode . nil))))

I think the intention is that most files in the project should use indent-tabs-mode but Python files should not. However this doesn’t seem to work. As far as I can tell the definition for the nil mode overrides the definition for the Python mode and Emacs enables tab indentation for Python files. Is there any way to correctly implement the intended behaviour?

2
  • 2
    I notice that that project also has an .editorconfig file. I have seen an instance before where that was interfering with the other tab settings in emacs. This may or may not be an instance in this case. I will have to try and reproduce the issue myself.
    – shoshin
    Nov 14, 2018 at 18:03
  • This is a good opportunity, I guess, to advertise the Emacs development mailing list: lists.gnu.org/archive/html/emacs-devel/2018-11/msg00209.html.
    – Drew
    Nov 14, 2018 at 23:03

1 Answer 1

3

Experimentally, I think Emacs is using the first match it finds. So if you re-arrange spec to put the nil case last, you'll end up with the desired outcome.

((python-mode . ((indent-tabs-mode . nil)))
 (nil . ((indent-tabs-mode . t))))

I feel this is a change of behaviour, and possibly a bug. It's not flagged in NEWS in any case.


Edit: Ok, definitely a bug.

It turns out that it was previously also the case that the sequence mattered (I never noticed, as I always put the nil case first); but the priority order seems to have flipped in 26.1.

So I think it used to be the case that the last match had final say, whereas in 26.1 the first match has final say. Which is clearly a bad change when it comes to the compatibility of dir-locals files across different versions of Emacs.

Could you please M-x report-emacs-bug about this?

2

Your Answer

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

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