35
votes
Accepted
Reloading directory-local variables
This function will re-read the dir-locals file and set the new values for the current buffer:
(defun my-reload-dir-locals-for-current-buffer ()
"reload dir locals for the current buffer"
...
24
votes
Accepted
Calling functions in .dir-locals in Emacs
Your list nesting is wrong.
You need to use the eval pseudo-variable to evaluate expressions / call functions.
Using mode to set a minor mode is deprecated. That's now for major modes only, and minor ...
22
votes
Accepted
Mark a local variable safe for any value
Set the safe-local-variable property to a function that validates the value. For example, fill-column has a safe-local-variable property set to integerp. Use (lambda (x) t) as the validation function ...
13
votes
Trust .dir-locals.el
You can customize safe-local-variable-values in your init file. This will require you to also specify which values you consider safe.
(add-to-list 'safe-local-variable-values '(var . value))
This ...
9
votes
Accepted
.dir-local.el misunderstanding
When you call add-dir-local-variable, it assumes you are already in the directory you want to apply the directory-local variable to. When it prompts for a directory, it's asking if you want the ...
9
votes
Remember permission to execute "risky" local variables
Emacs should offer (and normally does offer) the option to accept and remember the choice for later sessions. I suggest you M-x report-emacs-bug about this missing choice in your case.
In the mean ...
9
votes
Accepted
How can I turn off flycheck minor mode for given directory
Well you wouldn't want to remove the hook, as that's a global effect.
You can disable the mode on a per-buffer basis, though. Use the eval pseudo-variable. e.g. a .dir-locals.el like this would act ...
9
votes
How can I set directory local variable in relative to .dir-locals.el file location?
My solution so far (based on this Stackoverflow answer):
.dir-locals.el:
;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")
((nil . ((eval . (set (make-...
8
votes
Accepted
How to enable auto-revert-mode for files under a certain directory
Funny: it looks like you choose a tag that directly answers your question ("directory-local-variables")
The best way to accomplish this is by placing a .dir-locals.el file in your org ...
7
votes
Accepted
How are file paths mapped to subdirectories in .dir-locals.el?
Based on the documentation in the manual, you are missing a portion of the subdir specification.
Sample .dir-locals.el
From the manual with comments for emphasis/clarification
(;; Dir settings
(...
6
votes
Accepted
variable project root folder in .dir-locals.el
I found the solution with projectile. It has a function projectile-project-root which can be used to get the project path.
I can noe use the following in .dir-locals.el and it will still work when I ...
6
votes
Accepted
does tramp mode look at .dir-locals
enable-remote-dir-locals is a variable defined in ‘files.el’.
Its value is nil
You can customize this variable.
This variable was introduced, or its default value was changed, in
version 24.3 of ...
5
votes
How to set major mode for a file in .dir-locals.el?
The following .dir-locals.el works just fine for me to set the major mode of all files in a directory to shell-script-mode:
((nil . ((mode . shell-script))))
The obvious downside is that you can't ...
5
votes
Accepted
How to set major mode for a file in .dir-locals.el?
It's possible to specify a string instead of a mode, but this only works for subdirectories. So I'll use nil instead to match all modes, then the eval key to change the major mode conditionally:
((...
5
votes
How can I make an interactive function be local to directories?
So as per my earlier comment, Emacs doesn't really support what you're asking for.
I would strongly recommend that you simply define a global command in the normal way, and make it behave ...
5
votes
Reloading directory-local variables
You can also use: M-: (hack-dir-local-variables-non-file-buffer)
To check it works: from a buffer (an org mode file for instance), type M-x add-dir-local-variable, then validate (default org-mode), ...
5
votes
Accepted
White list of .dir-locals.el
I added this to my init.el:
(defun recursive-load-dir-settings (currentfile)
(let ((lds-dir (locate-dominating-file currentfile "settings.el")))
(when lds-dir
(progn
(load-file (...
5
votes
How to set minor mode variables in dir-locals?
As @phils suggested you should be able to run M-x add-dir-local-variable. You will be prompted for a mode, and you could type/select lsp-mode (I am guessing that is the mode name). Then, you will be ...
4
votes
Accepted
flycheck-gcc-include-path in .dir-locals.el
I see a few potential issues:
I am not familiar with a cpp-mode; I assume you mean c++-mode.
The contents of a dir-locals-file should form an alist, i.e. ((mode . vars)) instead of (mode . vars).
The ...
4
votes
Customized c-offsets-alist override c-file-style in dir-locals
Instead of modifying c-offsets-alist, you can modify c-file-offsets whose purpose is to set offsets via file local variables.
A small example for a .dir-locals.el file:
((nil . ((fill-column . 80)))
...
4
votes
Accepted
How to set tags-table-list as a per-directory local variable?
All your attempts to set tags-table-list are errorneous.
All cases except the second one do not define a mapping of modes to alists of settings and are therefore wrong.
Only the second case remains ...
3
votes
How to customize major mode initialization with local variables?
If you want to set a buffer-local value for a given mode, do so after the mode has been established. You do that by putting the value-assignment on the mode hook.
For example, if you want to set ...
3
votes
how to apply parent directory and current directory variable together
No, there is no provision (at least as at Emacs 24.5) for additionally continuing to look for and process ancestor .dir-locals.el files after a nearer one has been located.
However, if it makes sense ...
3
votes
White list of .dir-locals.el
If you write configuration to your init.el file manually, then you could add the following:
(setq custom-file "~/.emacs.d/custom.el")
(load custom-file t)
Now when emacs encounters a .dir-locals.el ...
3
votes
Accepted
How to stop auto backup in some directory in Emacs
Backup decisions seem to pass through the function normal-backup-enable-predicate, via the variable backup-enable-predicate which is set to this by default. You can provide your own function to return ...
3
votes
Accepted
dir-locals not working
To elaborate on theldoria's comments:
If wc-mode is a major mode then either:
((markdown-mode . ((mode . wc))))
or:
((markdown-mode . ((eval . (wc-mode)))))
If wc-mode is a minor mode, then:
((...
3
votes
Enable .dir-locals.el variables inside just opened buffer
As the new buffer is not saved yet it doesn't know where to look for dir-locals.
Have a look at function hack-dir-local-variables-non-file-buffer which uses default-directory to apply dir-locals to ...
3
votes
Accepted
Can I override the “nil” variables in .dir-locals.el with a more specific mode?
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))...
3
votes
Accepted
Apply settings in .dir-locals.el to both c and c++ major modes
Not as such (AFAIK).
However, both those modes derive from prog-mode which might be fine to target for this directory.
((prog-mode . ((comment-start . "/* ")
(comment-end . " */")
...
3
votes
Set multiple dir-local variables for the same mode
The dir-locals file contains an alist of nested alists. This would be the correct form for your example of setting multiple variables for python-mode:
((python-mode . ((python-shell-buffer-name . &...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
directory-local-variables × 73local-variables × 8
file-local-variables × 5
org-mode × 4
projectile × 4
hooks × 3
major-mode × 3
flycheck × 3
lsp-mode × 3
spacemacs × 2
python × 2
indentation × 2
dired × 2
tramp × 2
company-mode × 2
customize × 2
minor-mode × 2
cc-mode × 2
buffer-local × 2
alists × 2
org-export × 1
init-file × 1
org-babel × 1
magit × 1
buffers × 1