reddit / emacs

emacs does not load .dir-locals.el

Sharkalash · 2022-09-19 13:52
Hi everyone. I am currently facing an issue with emacs, it just won't load my .dir-locals.el file. I have set enable-local-variables to true, but it just like emacs is ignoring the file. I don't have any mention of it in the logs when I open it. The version is 27.1. So if anyone already faced the issue, I am interested how I can solve this. EDIT: in fact, the file is not ignored, but the value I am trying to set to some variable are just not applied. I am trying to set the variable cmake-ide-build-dir of the cmake-ide plugin. EDIT2: I found out that, when I was in cpp mode the local variable were not set because of this line when configuring irony ``` (add-hook 'irony-mode-hook 'irony-eldoc) ``` This line was provoking an error, preventing loading anything else after this. Thanks.
db48x · 2022-09-19 15:49
Are you loading the files via TRAMP? If so, then you need to set `enable-remote-dir-locals` to `t`.
7890yuiop · 2022-09-19 21:21
Note also that buffers which are *not* visiting files often don't process directory-local variables (as doing so doesn't necessarily make sense in general). There are many that *do* still process the dir-locals, but the major mode has to explicitly request it.
Sharkalash · 2022-09-19 21:22
No I'm not using TRAMP
db48x · 2022-09-19 22:41
In that case my psychic debugger isn’t working today. What other information can you supply about the problem? What are the paths for the file you are editing and the .dir-locals.el file? What is the content of the .dir-locals.el file? How are you testing that Emacs read it successfully?
ideasman_42 · 2022-09-20 02:41
You might like to try [`sidecar-locals`](https://codeberg.org/ideasman42/emacs-sidecar-locals), I find it convenient to store arbitrary settings for my projects - trusting blocks of code isn't so convenient. `dir-locals` is fine for a few variables though.
7890yuiop · 2022-09-20 06:06
> in fact, the file is not ignored, but the value I am trying to set to some variable are just not applied What does "not applied" mean? Does it not have the value you set, or does the value you set simply not have the effect you were wanting? If it doesn't have the value you set, then presumably something else is clobbering it subsequently.
Sharkalash · 2022-09-20 07:12
I didn't know about it. I'll check this out thanks.
Sharkalash · 2022-09-20 07:15
Not applied means the variable I am trying to modifying through the dir-locals still has its default value. I am using cmake-ide, when emacs launch, this plugin run cmake in a build directory in /tmp. I am trying to modify the path of this build directory and it stays always the same and ignore the local value I am trying to set. my file : ``` ((nil . ((cmake-ide-project-dir . "/path/") (cmake-ide-build-dir . "/path/build") ))) ```
Sharkalash · 2022-09-20 07:21
SInce I have put ``(hack-local-variables t)`` in my ``.emacs``, I am prompted when I open a file in the directory whether to trust safe local variable value. Also, if I makes a mistakes in the syntax of the .dir-locals.el, I can see it in the logs. This is my file: ``` ((nil . ((cmake-ide-project-dir . "/path") (cmake-ide-build-dir . "/path/build") ))) ``` When I open emacs in that directory, cmake-ide try to run cmake in a default build dir in /tmp. I want to modify that. But somehow, the value I set in the file are not considered and the build dir stays the default one. I can make it work if I set these variables globally, but I don't want to have this one set globally, hence the local variable.
7890yuiop · 2022-09-20 07:36
Ok. Strictly speaking I doubt that it stays the same. Rather, I would expect that something happening *after* processing dir-locals is changing it to the value you're seeing (which also happens to be the default value).
Sharkalash · 2022-09-20 07:56
That is maybe the case. Do you have any advice on how I can debug this and how I can find where is happening this after processing?
db48x · 2022-09-20 08:31
You can use `M-x normal-mode` to reset the mode of the current buffer and reload the file– and directory–local variables. You can also use `M-x describe-variable` (or `C-h v`) to show the value of a variable. You should see something like this: cmake-ide-project-dir is a variable defined in ‘cmake-ide.el’. Its value is "test" Original value was nil Local in buffer test.cpp; global value is nil As you can see, my `.dir-locals.el` file successfully set the variable. I can’t really test it by calling `cmake-ide-compile`, but it looks to me like it would work just fine. A quick test with `M-: (cide--locate-project-dir)` printed `"/home/db48x/temp/test"` in the minibuffer, which looks right.
Sharkalash · 2022-09-20 08:36
Thank you, I will try this out.
7890yuiop · 2022-09-20 09:02
Try this: (defalias 'watcher-debug (apply-partially #'debug nil)) (add-variable-watcher 'cmake-ide-build-dir #'watcher-debug) ;; (remove-variable-watcher 'cmake-ide-build-dir #'watcher-debug) Refer to `C-h i g (elisp)Debugger Commands` for driving the debugger.
Sharkalash · 2022-09-20 13:25
So I have set the watchpoint, and it seems that the value is first set to nil, during the \`\`require cmake-ide\`\` and then, if I open any file but not .cpp, the local value I want is set, but in case of a .cpp file, there is to a second break point so the value stays nil
Sharkalash · 2022-09-20 13:45
Ok, I finally found the issue, this is because of this line: ``` (add-hook 'irony-mode-hook 'irony-eldoc) ``` Thank you for all the advices and help!