Pay08 · 2022-12-20 18:03
When I try to save anything for the first time in an Emacs session, emms tries to save the history file which then throws up an lsp-mode error saying that the file can't be formatted. Is there a way to call `remove-hook` for that one specific file?
popska · 2022-12-20 18:22
file local variables ([https://www.emacswiki.org/emacs/FileLocalVariables](https://www.emacswiki.org/emacs/FileLocalVariables)) is probably what you are looking for.
if you specifically want to call remove-hook whenever you open a file you can put something like this at the top of your file: `-*- eval: (remove-hook ...) -*-`
Pay08 · 2022-12-20 20:40
Do file local variables work with simple text files?
wasamasa · 2022-12-20 22:06
One alternative is to write a smarter hook function with a conditional:
(defun my-hook ()
(when condition
(do-the-thing)))
Or even better, using the hook on specific modes only. For example you could use `prog-mode-hook` so that the hook function isn't run in history buffers in the first place (because they aren't using modes derived from `prog-mode`).
popska · 2022-12-20 22:41
yep, file local variables will work with all files.
​
the only consideration is that for files which are parsed by something else (i.e. a source code file) you will need to make sure it is in a comment, for example in C:
`/* -*- (file local variable things here...) -*- */`
Pay08 · 2022-12-21 06:02
>using the hook on specific modes only
That wouldn't work. The file isn't opened beforehand, just saved.
luiggi_oasis · 2022-12-21 15:46
The only minor drawback is that you get prompted about executing code when you open the file, right? Like a security kind of thing. You can answer Y and whitelist it forever I think.