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"
(let ((enable-local-variables :all))
And if you want to reload dir-locals for every buffer in ...
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 modes are enabled via eval.
I think you wanted this:
((nil . ((eval . (flycheck-mode 1))
(cmake-ide-dir . "~/workspace/Samira3D")
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 if any value is valid.
(defvar my-variable-with-any-safe-value …)
(put 'my-variable-with-any-safe-value 'safe-local-variable
(lambda (x) t))
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 is OK if you know the set of possible values, as your question implies you do.
If you want to make a variable safe for all values that satisfy a predicate, you ...
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 variable applied to a subdirectory of your current directory.
So I expect giving it the absolute path to a directory is causing your problem. In your case, I think ...
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 time, you can add the following to your ~/.emacs:
'(LaTeX-command . "lualatex -shell-escape"))
My solution so far (based on this Stackoverflow answer):
;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")
((nil . ((eval . (set (make-local-variable 'my-project-path)
(let ((d (dir-locals-find-file ".")))
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 for any/all major modes:
((nil . ((eval . (flycheck-mode 0)))))
Local variables are processed after mode hooks, so this should reliably counteract your ...
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 directory and using it to enable auto-revert-mode. Specifically, the file should look contain this:
((nil . ((eval . (auto-revert-mode 1)))))
If you want only org ...
Based on the documentation in the manual, you are missing a portion of the subdir specification.
From the manual with comments for emphasis/clarification
(;; Dir settings
(nil . ((indent-tabs-mode . t)
(fill-column . 80)))
(c-mode . ((c-file-style . "BSD")
(subdirs . nil)))
;; Subdir specification
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 move the project or use it on another machine.
((nil . ((eval . (progn
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), then type demo RET, then "this is a demo" RET.
Your .dir-locals.el file will appear in a buffer:
;;; Directory Local Variables
;;; For more information see (...
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:
(when (string= (file-name-nondirectory buffer-file-name)
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 appropriately based on the presence or not of a local variable (which could be directory-local). It can still be called from anywhere, but you would ensure that it never ...
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 prompted for a variable, and you could type/select lsp-purescript-use-npx. Finally, you should be prompted for the value. Depending on your setup, you may or may ...
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 specify the major mode for only a given subset of files in the directory.
Addendum: Amusingly, it also has the side effect of setting the major mode of .dir-...
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 cdr of each such mode-vars pair, i.e. the mode-specific settings, should also form an alist: ((mode . ((var . val)))) instead of ((mode . (var . val))).
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 to be discussed. In the following I add the missing closing parenthesis ):
((nil (tags-table-list ("/R/Source/R-devel-SVN/" "/gitRepos/DADS/"))))
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 local variable foo to 42 in lisp-mode then do something like this:
(add-hook 'lisp-mode (lambda () (setq-local fill-paragraph-function 'my-fill-para)))
Or better ...
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 nil if no backup is to be done.
(defun my-backup-enable-predicate (name)
(dolist (specialdir '("/somedir/" "/some/other/") ...
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 with iffy options Emacs will save your choice into this custom.el file, leaving you free to share your init.el file publicly.
If you like to use Emacs' ...
To elaborate on theldoria's comments:
If wc-mode is a major mode then either:
((markdown-mode . ((mode . wc))))
((markdown-mode . ((eval . (wc-mode)))))
If wc-mode is a minor mode, then:
((markdown-mode . ((eval . (wc-mode 1)))))
I have assumed that markdown was an error, and have substituted markdown-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)))
(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 ...
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 . " */")
(comment-padding . 0))))
Or you could even use nil, which applies to every mode (again, maybe that's ok in practice).
((nil . ((comment-start . "/*...
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 Emacs.
Probably introduced at or before Emacs version 24.3.
Non-nil means dir-local variables will be applied to remote files.
n.b. I believe ...
You can disable this "don't remember risky variables" feature by putting the following in your ~/.emacs:
;; allow remembering risky variables
(defun risky-local-variable-p (sym &optional _ignored) nil)
Then it'll only re-confirm when you edit one.
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 for your scenario, you can remove your "current directory" file and specify all the variables in the parent .dir-locals.el file.
Keys which are strings ...
The directory local variables are set after the major mode command run. Otherwise the major-mode dependent file local variables would not work.
Therefore, you just buffer-locally add turn-on-auto-fill to text-mode-hook. But the hook is not run again and your configuration is without effect.
If you want to deactivate truncate-lines for all major modes and ...