How to set a directory local variable for a directory itself non-recursively? I don't want the variable set in .dir-locals.el affect the sub-directories.


My use case is: I'd like to hide dot files under ~ by setting dired-omit-files since there are quite a lot of them in my home directory. But I do not want to hide dot files of any other subdirectory of ~. Though I think I can set it using some dired-mode-hook by comparing buffer-name or buffer-file-name, I guessed there may be simpler solution by using directory local variables.

  • Not quite a duplicate, but cross-referencing with emacs.stackexchange.com/q/54974/454
    – phils
    Dec 6 '20 at 9:27
  • You could test (string= (expand-file-name dired-directory) (expand-file-name "~/")) to see whether the current dired buffer is visiting your home directory.
    – phils
    Dec 7 '20 at 3:00

No, there isn't. You can set the variable in the directory-local variables, and the unset it in the child directory's variables. Or you can use file-local variables.

  • There so many subdirectories though... Dec 6 '20 at 9:17
  • 1
    @stackunderflow I suggest you edit the question to explain your use-case in detail. What you're asking for isn't supported, but depending on what you're actually trying to achieve, there might be other convenient options.
    – phils
    Dec 6 '20 at 9:26
  • Then consider using file-local variables instead. Or you could certainly consider extending Emacs so that it could support non-recursive directory-local variables.
    – db48x
    Dec 6 '20 at 9:26
  • @phils I've updated the question details. Dec 7 '20 at 0:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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