Questions tagged [directory-local-variables]

Filter by
Sorted by
Tagged with
32
votes
2answers
4k views

Reloading directory-local variables

How do you reload directory-local variables? I would like to modify a .dir-locals.el and have such changes applied to the current Emacs session.
21
votes
2answers
2k views

Remember permission to execute “risky” local variables

In many of my projects I use .dir-locals.el files to setup project specific variables such as compile commands. Upon opening a file within a directory containing such a file, emacs complains about "...
16
votes
2answers
3k views

How can I set directory local variable in relative to .dir-locals.el file location?

I often find myself in the situation where I'm told to put relative paths as directory local variable. For example cmake-ide's cmake-ide-project-dir and cmake-ide-build-dir. Of course this is not very ...
14
votes
1answer
1k views

Mark a local variable safe for any value

The variable safe-local-variable-values can store name/value pairs that are safe as file-local or directory-local. However sometimes I want to say any value is valid for a given variable. The manual ...
14
votes
1answer
1k views

Trust .dir-locals.el

I want to put some config outside my init.el file into .dir-locals.el, i.e the following: ((nil (let ((dirs '(".cask" "core" "packages" "modules" "snippets" "themes"))) (mapc #'(lambda (path) (...
12
votes
2answers
1k views

How to set major mode for a file in .dir-locals.el?

I would like to set the major mode for a file as you would using file-local variables Local Variables: mode: text End: but in .dir-locals.el in order not to “pollute” the file in question. Is this ...
11
votes
1answer
3k views

Calling functions in .dir-locals in Emacs

I'm trying to activate flycheck-mode by default when opening any file in my project's directory. I'm a bit of an elisp newbie, my .dir-locals.el file looks like this: ((nil . (mode . flycheck-mode)) ...
10
votes
1answer
658 views

How are file paths mapped to subdirectories in .dir-locals.el?

I like the idea of .dir-locals.el. I have my own .dir-locals.el file in my home directory that should set all the variables for directories/files that I open unless there is .dir-locals.el closer to ...
8
votes
3answers
747 views

White list of .dir-locals.el

Is it possible to load .dir-locals.el file without prompting me, but also without adding values I am configuring in that file to my init.el in custom-set-variables? The reason I want it is that that ...
8
votes
1answer
3k views

variable project root folder in .dir-locals.el

I'm using company-mode for completion in C++ code. To tell clang backend of company where the include files for the current project are I have to use the following .dir-locals.el file ((c++-mode (...
5
votes
1answer
964 views

How can I turn off flycheck minor mode for given directory

So my question is like in title. I want to turn off flycheck minor mode for all files in directory. I have specified in my .emacs file that it should be on in c++-mode, c-mode and few others, but I ...
5
votes
1answer
242 views

How to set tags-table-list as a per-directory local variable?

I have two tags tables that I would like to be searched/visited when I'm working on one of my R packages. I am able to set them globally with the following code in my .emacs config file: (setq tags-...
4
votes
1answer
183 views

How can I make an interactive function be local to directories?

I want to make it so that I have interactive functions that can only be called from buffers in a certain directory, like variables in .dir-locals.el. Is there a way to do this? For example, say I'm ...
4
votes
1answer
127 views

Can I override the “nil” variables in .dir-locals.el with a more specific mode?

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 ...
4
votes
2answers
1k views

How to customize major mode initialization with local variables?

Seems like most major modes clear all local variables before initializing. It also seems like many major modes read variables while initializing to customize their behavior. If I want to set a file ...
4
votes
1answer
396 views

How to stop auto backup in some directory in Emacs

In general I want Emacs to save a backup file for me, except in some special directories. I tried to define a Directory Local Variables, and add: ((nil . ((make-backup-files . nil)))) But it seem ...
3
votes
1answer
893 views

.dir-local.el misunderstanding

I generated a .dir-locals.el by calling the function add-dir-local-variable, giving it the path for the project for which I want the variable, the variable itself, and its value. The generated file ...
3
votes
1answer
289 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-...
3
votes
1answer
156 views

how to apply parent directory and current directory variable together

there is a .dir-locals in parent directory ((nil (global-auto-revert-ignore-buffer . t))) and there is a .dir-locals in current directory ((nil (tags-file-name "TAGS"))) but when I visit files in ...
3
votes
0answers
104 views

Evaluation of .dir-locals.el in shell?

I observed that directory local variables, defined in .dir-locals.el, are set for files, dired-buffers, new buffers, but not for shell or eshell buffers (well, that is also the case for buffers ...
3
votes
0answers
566 views

How to mark risky variable as safe?

I have some customization in my .dir-locals.el. Some of variables set there are unsafe and when I set them and visit some file in dir for the first time Emacs nicely asks me to save their name-value ...
2
votes
1answer
337 views

How to enable auto-revert-mode for files under a certain directory

I have my org files kept synchronized via rsync with various devices. These buffers are usually open in any running emacs instances due to agenda and capture. I want emacs to re-read these files from ...
2
votes
2answers
272 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
1answer
3k views

flycheck-gcc-include-path in .dir-locals.el

In my .dir-locals.el I have: (cpp-mode . (setq flycheck-gcc-include-path '("/home/<user>/<project>/include"))) This doesnt seem to set flycheck-gcc-include-path, any ideas why? Also is ...
2
votes
1answer
105 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 ...
2
votes
1answer
44 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....
2
votes
1answer
120 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 ...
2
votes
1answer
423 views

How to trust code in .dir.locals.el and pass the (is it safe) test?

I have this code in my .dir-locals.el file: (eval . (let ((root (projectile-project-root))) (setq-local company-clang-arguments (list (concat "-I" root "headers")...
2
votes
0answers
134 views

Setting org-babel-load-languages in .dir-locals.el

As per the title, I'd like to set the org-babel-load-languages (to contain ditaa and calc languages) for a specific project only. The only solution I found so far is this one ( (org-mode . ...
2
votes
0answers
274 views

How to set indentation style substatement-open offset parameter from .dir-locals.el?

Within CC mode, for C and C++ files inside a directory, I'd like to have the open braces following a case/do/for/if/while not indented, whatever the style is and without having to change anything in ....
2
votes
0answers
99 views

org-journal-mode new entry ignores .dir-locals.el

I am using org-journal-mode. I have created .dir-locals.el in my ~/Documents/journal directory and it gets correctly applied if I open a file the usual way. However, if I hit the C-xC-j to add a new ...
1
vote
1answer
38 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....
1
vote
1answer
36 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 ~/...
1
vote
1answer
475 views

Enable .dir-locals.el variables inside just opened buffer

I'm programmtically create a new buffer as a result of shell command (defun jira-ticket-view (&optional jira-ticket) "Open Jira Ticket Inside Emacs" (interactive) (setq jiraURL (get-jira-...
1
vote
1answer
462 views

dir-locals not working

I wanted to have wc-mode (a minor mode) enabled when I edit any markdown file in a specific directory. So, I created a .dir-locals.el file and added the following to it: ((markdown . ((wc-mode . t))))...
1
vote
2answers
380 views

How to use magit-commit-arguments to set commit author

I'm trying to use a .dir_locals.el file to override the author field in Git commits (so when I'm committing something in a work repo, I use my work email). It looks like magit-commit-arguments is ...
1
vote
1answer
777 views

Compile command as a directory variable?

I am working on a cmake project and I would like to set a directory variable containing the correct compile command. I added this to the root directory of the project in a .dir-locals.el file: ;;; ...
1
vote
1answer
76 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
1answer
79 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 ...
1
vote
1answer
392 views

evaluating fn in dir-locals.el

I realize there are a number of questions surrounding this topic, but I'm trying use a global function that I've written inside a project .dir-locals.el. Specifically, I wrote a function to add a ...
1
vote
1answer
140 views

Override per-directory settings on a file type basis

I'm using dir-locals-set-class-variables in my git directories to apply whitespace-mode settings differently, based on the needs of each repo. if my sf directory, for all subfolders, I want to use ...
1
vote
0answers
23 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 ...
1
vote
0answers
42 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-...
1
vote
0answers
22 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 ...
1
vote
2answers
53 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 ...
1
vote
0answers
641 views

Why are my .dir-locals not being applied even though they are loaded

Still on a never ending quest to get per project settings working for python using tramp and .dir-locals. Hitting a strange problem when I open a buffer I am asked if i would like to run my .dir-...
1
vote
0answers
26 views

Using multiple .dir-locals.el [duplicate]

Say I have two directories A and B, with A containing B. Both A and B have directory local variables specified through their own .dir-locals.el files. B/.dir-locals.el whenever emacs visits a file in ...
0
votes
1answer
28 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-...
0
votes
2answers
448 views

Load package in dir-locals

Sorry, I'm new to emacs and I'm sure this is a very basic question. For my personal projects I prefer spaces for indentation, whereas work requires smart-tabs (tabs for indentation, spaces for ...
0
votes
1answer
268 views

cmake-ide defining variables

I have a project I build using cmake. To build this project, I need to define several options like -DPRODUCT=amd64 -DXML_DIR=/opt/xml_database Normally, I either pass these as -D or configure them in ...