Questions tagged [directory-local-variables]
Directory local variables are used to apply the same Emacs settings to all files in a directory. https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html
91 questions
2
votes
1
answer
63
views
How should ‘auto-save-file-name-transforms’ be set from ‘.dir-locals.el’?
In my ~/.emacs.d/init.el, I have auto-save-file-name-transforms set so that auto-save files are saved at paths such as /home/[user]/.emacs.d/auto-saves/#!home![user]!path!to!file#. This works fine.
In ...
0
votes
1
answer
411
views
Safe variables in a .dir-locals.el file
I created a .dir-locals.el file using M-x add-dir-local-variable. The resulting file looks like this:
;;; Directory Local Variables -*- no-byte-compile: t -*-
;;; For more information see (...
1
vote
1
answer
205
views
How to disable file-local variables but leave directory-local variables enabled?
Summary (TL;DR):
I want to disable Emacs from processing and/or applying any file-local variables, no matter what. However, I still want Emacs to process and apply directory-local variables specified ...
0
votes
1
answer
100
views
org-refile-targets as a local variable
Is it possible to set org-refile-targets on a per-file basis?
A similar question was asked here. But it did not get any answers.
I am OK if it is set as a Local variable in the file or it is set up in ...
1
vote
2
answers
147
views
unload-feature not unloading function definitions
I have an elisp file that contains the following:
(defun hello ()
(interactive)
(message "Hello World"))
(provide 'examples)
When I call unload-feature examples RET, the function hello ...
1
vote
2
answers
154
views
Unable to override c-offsets-alist in dir-locals.el
I have Emacs 27.1 on Ubuntu 22.04 and I'm trying to modify c-offsets-alist for this particular project with C and C++ source files. I have a c-style and a c-mode-common-hook in my .emacs:
(defconst my-...
0
votes
0
answers
179
views
Make .dir-locals works with compilation
I'm using Emacs 29.1 I have the following .dir-locals.el file:
((nil . ((compilation-error-regexp-alist-alist . '(acap "^#[0-9]+ [0-9]\.[0-9]+ \\(.+?\\):\\([0-9]+\\):\\([0-9]+\\).*" 1 2 3))
...
0
votes
2
answers
553
views
How do I hide dotfiles only in the home directory in dired buffers?
I would like to hide dotfiles only in the home directory in dired buffers, but I do not know how to achieve this. I have been trying with the following:
(use-package dired
:ensure nil
:commands (...
0
votes
1
answer
110
views
Access dir-locals variables with elisp
I have following .dir-locals.el file in my project directory:
((nil . ((logbook . "todo.org"))))
and following function:
(defun project-switch (&optional project-dir)
"switch to ...
2
votes
1
answer
937
views
How to set rust-analyzer.linkedProjects with eglot?
My project structure is like this:
-- Project Root
- .git
- rusttools
- Cargo.toml
- src
- main.rs
When I open main.rs in Emacs, eglot complains:
[eglot] Server reports (type=1): ...
1
vote
0
answers
169
views
Follow symbolic links in alternative org-roam directory
I use org-roam to take notes. I have two org-roam directories. The alternative one has a .dir-locals.el file where I set the value of org-roam-directory and org-roam-db-location with the path to the ...
3
votes
1
answer
123
views
duplicate key in dir-locals file
Why does someone attempt to have a duplicate key in a single .dir-locals.el?
E.g.,
((nil . (...))
(nil . (...)))
1
vote
0
answers
59
views
conflict between “.dir-locals.el” and “.dir-locals-2.el”?
Say there're 3 files:
/tmp/
|
|__ LICENSE
|
|__ .dir-locals.el # Make LICENSE read-only
|
|__ .dir-locals-2.el # Do nothing
;;; /tmp/.dir-locals.el
((nil . ((eval . (when (string-match-p &...
3
votes
2
answers
365
views
dir local “auto-mode-alist” sets wrong mode
;;; /tmp/test/.dir-locals.el
((auto-mode-alist . (("/\\.dir-locals\\(-2\\)?\\.el\\'" . lisp-data-mode)
("/[^/-][^/]*\\.el\\'" . emacs-lisp-mode))))...
2
votes
2
answers
248
views
Marking as safe all possible lists of strings
Following this answer, I put the following lines in a .dir-locals.el file:
((latex-mode
(TeX-engine . default)
(mode . latex )
(TeX-master . "main")
(ispell-buffer-session-localwords
...
4
votes
1
answer
471
views
How can I set a buffer-local variable (format-all-mode) to nil within .dir-locals.el? (using Doom emacs)
I have a project where I want to disable format-all-mode for all my python files. I can do this manually by running M-x format-all-mode every time I open up a python file for that project.
I tried ...
0
votes
0
answers
17
views
Change face using dir locals file [duplicate]
I am trying to set face for org blocks to invisible for certain folders, so that it is nicer to read the org files with code. I am using .dir-locals.el file.
So, this example for the begin line works:
...
0
votes
1
answer
222
views
Disable blacken-mode on certain projects
I have blacken-mode enabled on all python buffers like this:
(add-hook 'python-mode-hook
(lambda ()
(blacken-mode 1)
;; other config
))
But on some ...
0
votes
0
answers
91
views
Override usr-full-name with .dir-locals
I've been trying to override the user-full-name by setting it in .dir-locals
((org-mode . ((org-export-with-date . nil)
(user-full-name . "Fullname")
(org-export-with-...
4
votes
1
answer
957
views
Is it possible to append to a list via .dir-locals.el?
So, I know that I can assign a variable via .dir-locals.el...
("thingy" (1 2 3 4))
but is there any way that I can append to an array, if at all?
("that" . "is correct")
...
0
votes
0
answers
330
views
"let: Symbol's value as variable is void" when loading .dir-locals
I have the following .dir-locals:
((nil . ((eval . (let ((project-root-dir (expand-file-name (locate-dominating-file default-directory ".dir-locals.el"))))
(defun tokenize-...
0
votes
0
answers
31
views
Loading project-specific Elisp script automatically [duplicate]
I have a project I am working on which contains custom file extensions (.set) for which I would like to write my own mode for. However, I want this mode to exist only within the context of the project....
0
votes
0
answers
73
views
dir-local variable not set for specific mode
I have the following .dir-locals.el file.
((nil . ((ffip-project-root . "~/projects/xyzzy/git")
(my-invalid-imports . ("org.junit.[A-Z]"))))
(jdee-mode . ((my-invalid-...
0
votes
0
answers
112
views
How to explicitly disallow a `.dir-locals` file ever from being loaded or queried about?
If I have a .dir-locals file that is meant as a template. How can I avoid the annoyance of being asked about whether or not the values are safe to load every time I open the file? I do want not to ...
0
votes
1
answer
205
views
How to apply a different theme for files in a specific directory
How can I use a different theme (or color scheme) for files in a specific directory?
Currently in my system, a single theme is applied to all buffers. The theme is chosen in ~/.emacs as
(load-theme '...
0
votes
1
answer
654
views
what is the type 'repeat string'?
Here it says that the type of lsp-clients-pylsp-library-directories is (repeat string)
How do I write my dir_locals.el file ?
I tried this but it doesn't work (see here)
((lsp-mode . ((lsp-clients-...
1
vote
1
answer
393
views
How to make csv-align-mode default in tsv-mode?
I'm editing tab separated file with Emacs and csv-mode.el. When the document is open, I can align the columns with M-x csv-align-mode. How to make it automatically aligned when I open the file?
Both ~/...
1
vote
1
answer
962
views
Adding directory local variable for projectile test command is not working
I'm setting up my python lsp using this video tutorial.
My emacs init.el configuration file is here
By default projectile-project-test-cmd runs the command python -m unittest discover. I want to ...
2
votes
1
answer
453
views
How to set a "#+SETUPFILE: .xxx.setup" as dir local?
I need this line in every my org files. It's tedious to include it in everyone of them.
1
vote
1
answer
156
views
How to manually define trusted paths for directory local variables '.dir-locals.el'?
I would like to define a list of trusted paths.
Where dir-locals.el can be loaded without asking me.
Without having to be concerned with safe-local-variable-valuesWhich isn't very practical if the ...
1
vote
1
answer
156
views
Using two programming languages with the same file extension
I am just starting to set up a perl environment in emacs but the problem is that I already program with prolog and both languages use the .pl file extension. I have two directory ~/src/prolog and ~/...
2
votes
1
answer
513
views
Automatically enable a mode with dir-locals.el
I'm trying to achieve the effect of automatically calling M-x importmagic-mode whenever I open a python file, but I need to do this in a directory specific way, using dir-locals.el.
I have this in dir-...
1
vote
0
answers
48
views
Ignore file- and directory-variables when using "emacs -Q"?
I am using emacs -Q as editor for git, because my startup is too heavy for "quick editing" use and using emacsclient will hang when git is invoked with M-x shell-command. However, as a ...
2
votes
2
answers
1k
views
.dir-locals for specific directory but not its children
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.
Edited:
My use case is: I'd like to hide dot ...
1
vote
2
answers
551
views
Set multiple dir-local variables for the same mode
I understand from here, that I can use dir-locals.el to customize modes, such as given in the example:
;; Warn about spaces used for indentation:
(haskell-mode . ((eval . (highlight-regexp ...
0
votes
2
answers
371
views
elpy flymake does not recognize local .pylintrc
I have the following in the project root for my .pylintrc:
[FORMAT]
# Maximum number of characters on a single line.
max-line-length=1000
# String used as indentation unit. This is usually " ...
2
votes
1
answer
196
views
realgud pdb with .dir-locals.el
I'm trying to use directory local variables so my realgud:pdb invocation can be:
Run pdb (like this): /home/username/work/place/environments/default/bin/python -m pdb /home/username/work/place/scratch....
1
vote
1
answer
354
views
Can not read dir-local variable from a hook function
hope you are all well.
Before stating problem, let me tell you my setup. I am using Emacs 27.1, using pyvenv, projectile, lsp-mode, lsp-python-ms for python-mode. I have set WORKON_HOME environmental ...
1
vote
0
answers
311
views
how best to set the `projectile-regenerate-tags` command
I have a fortran project I'm working on and I cannot figure out the right way to use .dir-locals to set the projectile-tags-command
here is my dir-locals.el file:
(
(f90-mode
(projectile-tags-...
4
votes
1
answer
649
views
does tramp mode look at .dir-locals
I'm using emacs over tramp to edit a project inside a vm on my local machine. It has something like this:
ssh:vm:~/projects/project/.dir-locals.el
ssh:vm:~/projects/project/src/tests/file-i'm-editing....
0
votes
2
answers
342
views
Apply settings in .dir-locals.el to both c and c++ major modes
Is there a way to specify the same settings for c-mode and c++-mode without repeating the alist?
I have:
((c-mode . ((comment-start . "/* ")
(comment-end . " */")
(comment-...
1
vote
0
answers
154
views
Is there a way to undo hook attached to major modes in spacemacs?
In my .spacemacs file I set the following hooks to run:
(add-hook 'js-mode-hook 'prettier-js-mode)
(add-hook 'web-mode-hook 'prettier-js-mode)
I, however, have projects where I don't want these to ...
0
votes
1
answer
559
views
How to use concat to get the path in .dir-locals.el with flycheck-clang-include-path
I am using the following content to include headers to my project using .dir-locals.el
((c++-mode .
((flycheck-clang-language-standard . "c++14")
(flycheck-clang-include-path
"/Users/user/...
2
votes
1
answer
612
views
At what point are file-local and dir-local variables applied to a newly-loaded buffer?
I'm currently attempting to call the function company-org-roam--init-hook from org-mode-hook in order to enable the company-org-roam backend in org-roam buffers. In some of the files in which this ...
4
votes
2
answers
1k
views
How to set minor mode variables in dir-locals?
Im writing an lsp-mode purescript client and couldn't figure out how to override the default config options using a .dir-locals file.
For example, I have a defcustom :
defcustom lsp-purescript-use-...
2
votes
2
answers
156
views
Directory Variable: .dirs-local.el with regexp
We can specify modes :
(c-mode . ((c-file-style . "BSD")
(subdirs . nil)))
Or directories :
("src/imported"
. ((nil . ((change-log-default-name . "ChangeLog.local")))))
Is there a ...
1
vote
1
answer
467
views
wrong-type-argument listp eval
I have a project which is centralized in a directory. The directory contains the .dir-locals.el file with the following content, just a defun:
(defun pr--narrow-buffer ()
"Narrow the current buffer ...
2
votes
1
answer
386
views
use .dir-locals.el to setup blacklist (based on projectile root) for ccls (c++mode server)
I use this setup to setup blacklists for ccls in my project:
(
(prog-mode (ccls-initialization-options . (:index (:blacklist [
"^/Users/xxx/proj/dir1/"
"^/Users/xxx/proj/dir2/(dir3|dir4)/"])))
)
How ...
3
votes
1
answer
1k
views
Use lsp-mode for some projects and ggtags for others
Is there a way to configure Emacs to activate lsp-mode for some projects and ggtags for other projects? Maybe using .dir-locals.el?
I code C++ and the project I most often work on doesn't support lsp-...
0
votes
1
answer
768
views
Fail to start Python Language Server when Python virtual env is activated from .dir-locals.el
I have the following in a .dir-locals.el
((python-mode . ((pyvenv-workon . "3.7")
(projectile-project-compilation-cmd . "python -m unittest fixcompdb_test.py"))))
I use lsp-mode and the Pyls ...