File local variables are set automatically from -*-specifications-*- or "Local Variables:" specifications when visiting a buffer. These specifications are included in the file itself and therefore only affect this file (hence "file local variables").
Questions tagged [file-local-variables]
62 questions
17
votes
2 answers
Key bindings specific to a buffer
Is it possible to set key bindings specific to buffer?
I have the following in one of my org files:
# Local Variables:
# eval: (local-set-key (kbd "") 'some-custom-defun-specific-to-this-buffer)
# End:
But this binding persists for other…

Kaushal Modi
- 25,203
- 3
- 74
- 179
15
votes
2 answers
Safe way to `enable-local-variables`?
I inherited my .emacs file from a friend about 18 years ago. Buried in the middle is the following ominous comment warning about the security implications of the enable-local-variables feature:
;; Date: Wed, 7 Dec 1994 11:57:50 -0600
;; From:…

Wandering Logic
- 253
- 2
- 7
15
votes
1 answer
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 page I linked to says that any integer value is…

Brendan
- 303
- 1
- 5
15
votes
1 answer
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) (add-to-list…

4lex1v
- 603
- 3
- 12
13
votes
1 answer
What is the file local variable mangle-whitespace?
I see
;; Local Variables:
;; mangle-whitespace: t
;; End:
in many Elisp source files by various experienced Emacs programmers.
But when I describe-variable, Emacs 24.3 says no variable mangle-whitespace is defined.
Is mangle-whitespace provided by…

Greg Hendershott
- 1,483
- 12
- 17
13
votes
3 answers
Prevent org-mode from swallowing file-local variables
It is sometimes convenient to define file local variables with
comments such as the following, which must be at the end of a file.
# Local Variables:
# fill-column: 80
# End:
However, in org-mode buffers, this comments are considered to be
“inside”…

Malabarba
- 22,878
- 6
- 78
- 163
9
votes
1 answer
Enabling a minor mode with a file-local variable prop line
The first line of a plain-text file reads:
# -*- eval: (auto-revert-tail-mode 1); -*-
Yet Emacs does not enable auto-revert-tail-mode after opening this file. What is wrong?

Eleno
- 1,428
- 11
- 17
9
votes
2 answers
Is there an emacs equivalent of vim's "modeline magic"?
I can't seem to find this answer anywhere, but I'm sure it's because I don't know the terms to search for.
I'm currently working in a mixed shop, with my developers using a mix of emacs, vim, Notepad++, and whatever you call the alleged text editor…

Petro
- 193
- 1
- 4
9
votes
2 answers
Can I set a particular file to automatically and silently accept changes?
That is, can I specify for a particular file that I don't want Emacs to notify me that the file has changed on disk and prompt me about whether I want to accept changes or not? I don't want to do this globally, just for files I know will frequently…

emacsomancer
- 1,011
- 1
- 9
- 16
9
votes
2 answers
How can I change Org-mode time format for one buffer?
In general all timestamps in Org-mode appears as [YYYY-MM-DD Day]. I have one file (buffer) where I would like the format to be different. Either just [YYYY-MM-DD] or [YYYY-MM]. How do I tell Org-mode to use a custom format for this one buffer?
I'd…

mankoff
- 4,108
- 1
- 22
- 39
9
votes
1 answer
How comment out a variable line in a local variable list
In a python file I have
# Local Variables:
# python-shell-interpreter: "python3"
# python-shell-virtualenv-path: "~/.virtualenvs/datascience"
# leo-python-args-to-send: "-f fqanalysis.txt"
# End:
For a couple of days I want to use the python file…

halloleo
- 1,215
- 9
- 23
8
votes
1 answer
Org-Ref: Managing multiple projects, each with own notes.org files and bibtex-pdfs folders
When using org-ref, the bibliography:ref.bib directive in the notes.org file can be used to direct it to the corresponding ref.bib bibliography. Is there a similar such directive or approach to enable the ref.bib file to "discover" its corresponding…

nyameko
- 545
- 2
- 15
7
votes
1 answer
Using File Local Variables in org-mode
Is there a way to use file local variables set in an org-mode file in the following contexts:
Simply expanding the variable when text is exported (eg: to LaTeX)
Passing the value to :var in a babel source block (SQL or Python)
Expanding the…

PeterT
- 73
- 1
- 4
6
votes
1 answer
# -*- mode: ... -*- string fallback
So I know that I can put at the first or second line of a file a line such as:
# -*- mode: conf -*-
to tell Emacs what major mode I want the file to be opened with.
But if that mode isn't installed I wish Emacs to fallback to a different mode.
For…

Chen Levy
- 385
- 3
- 12
6
votes
2 answers
File-local variable to force specific shell for shell-script major mode
I'm having the same problem as asked in this question: emacs is dropping into shell-script mode, but for the wrong shell variant.
Using a shebang as suggested in that question's answer is semantically incorrect: most of my files are meant to be…

drmuelr
- 163
- 5