21 votes
Accepted

Mark a local variable safe for any value

Set the safe-local-variable property to a function that validates the value. For example, fill-column has a safe-local-variable property set to integerp. Use (lambda (x) t) as the validation function ...
user avatar
18 votes
Accepted

Key bindings specific to a buffer

For closure, here is an answer that expands upon my comment. I define a minor mode with the required keybinding and toggle it in the required buffer using file local variables. (define-minor-mode ...
user avatar
  • 3,816
14 votes
Accepted

Safe way to `enable-local-variables`?

18 years ago, you were right to be worried. But time has marched on. Since Emacs 22, there is a decent built-in mechanism to whitelist safe local variables. The details are documented in the Emacs ...
user avatar
13 votes

Trust .dir-locals.el

You can customize safe-local-variable-values in your init file. This will require you to also specify which values you consider safe. (add-to-list 'safe-local-variable-values '(var . value)) This ...
user avatar
  • 1,259
12 votes
Accepted

Is there an emacs equivalent of vim's "modeline magic"?

What you're looking for are File Variables, specifically you want to look at Specifying File Variables in the Emacs Manual. There are two ways to specify File Variables. The more "modeline magic like"...
user avatar
  • 2,283
11 votes
Accepted

Prevent org-mode from swallowing file-local variables

Based on a quick skim through the documentation on Org Syntax, I don't think there is a built-in way for doing this. One possible workaround would be to add a top-level headline such as * File-local ...
user avatar
  • 14.2k
10 votes

Safe way to `enable-local-variables`?

Emacs is pretty safe when it comes to local variables. It does not actually evaluate anything for file- or directory-local variables, it only parses Lisp syntax. Also, a variable has to be declared "...
user avatar
10 votes

# -*- mode: ... -*- string fallback

Found it: # -*- mode: conf; mode: apache -*- It seems that the last valid mode wins, so I need to put the my wanted mode last, and the fallback mode(s) before it.
user avatar
  • 375
9 votes

Prevent org-mode from swallowing file-local variables

I keep a top level headline at the end of my Org files called * Configuration. I ensure it is tagged :NOEXPORT:ARCHIVE: With this it does not get exported (thanks to the :noexport: tag) and ...
user avatar
9 votes
Accepted

What is the file local variable mangle-whitespace?

I've grepped my ~/.emacs.d/elpa for mangle-whitespace and noticed it's used in a few packages which are all written by Roland Walker. Then I proceeded downloading the tarballs for Emacs 22.1 to Emacs ...
user avatar
  • 20.9k
8 votes
Accepted

How comment out a variable line in a local variable list

Based on a quick check of C-hig (emacs) Specifying File Variables, I'm reasonably sure that you can't. I think your options are: Move the comment outside of the local variables block. Change the ...
user avatar
  • 43.1k
8 votes
Accepted

Org-Ref: Managing multiple projects, each with own notes.org files and bibtex-pdfs folders

I think you need to put the local variables in two places, which is the org file and the bib file. The issue is that the notes functions are called while the bibtex buffer is active, so the local ...
user avatar
  • 10.9k
8 votes
Accepted

Can I set a particular file to automatically and silently accept changes?

You can do this for a specific buffer with M-x auto-revert-mode (manual). For file buffers, this will check every auto-revert-interval seconds (defaults to 5) for changes and update the buffer from ...
user avatar
  • 96
7 votes
Accepted

Enabling a minor mode with a file-local variable prop line

Take a look at the variables enable-local-eval and enable-local-variables. If you've changed one or both of these from their default values it could explain the behavior you are seeing. For example ...
user avatar
  • 19.1k
7 votes
Accepted

How can I change Org-mode time format for one buffer?

You need to define the variable org-time-stamp-custom-formats, not to call a function. What you type after the variable name and colon is a value (what you might type after '). -*- org-time-stamp-...
user avatar
6 votes

Key bindings specific to a buffer

Here is a generic way to set buffer-specific key bindings. Create a temporary minor mode (save the below snippet to temp-mode.el and require it in your init.el. Enable that temp-mode minor mode and ...
user avatar
  • 24.2k
6 votes

Prevent org-mode from swallowing file-local variables

I have averted this problem inadvertently as I always use some footnote in my documents. Doing C-c C-x f will insert a footnote and that will auto create * Footnotes section at the end of the buffer. ...
user avatar
  • 24.2k
5 votes

Add hook for specific files

A simple answer is to use the eval pseudo-variable in a file-local variables block. See the following answer on S.O. for details: https://stackoverflow.com/a/4356877/324105
user avatar
  • 43.1k
5 votes
Accepted

Org-mode COMMENT blocks local variable eval?

A section with a COMMENT keyword is just that, a comment, not to be evaluated. So speaks the manual Finally, a ‘COMMENT’ keyword at the beginning of an entry, but after any other keyword or ...
user avatar
  • 12.1k
5 votes

Is there an emacs equivalent of vim's "modeline magic"?

File variables The equivalent of Vi modelines in Emacs is file variables. As is often the case, the purpose of the feature is the same, but there are differences in the implementation details. The ...
user avatar
4 votes
Accepted

How to prevent parsing file-local variables?

If the format of your file allows it, you can use a new page character (insert it with C-q C-l on its own line). Why it works is explained in the manual (info "(emacs) Specifying File Variables"). The ...
user avatar
  • 3,331
4 votes

How to make a file variable buffer local?

Firstly, all file-local and directory-local variables are (necessarily) buffer-local. Here, Emacs is telling you that sh-indentation is buffer-local (with a value of 2) in that buffer. You can trust ...
user avatar
  • 43.1k
4 votes

How can I change Org-mode time format for one buffer?

The following will work: # Local Variables: # org-time-stamp-custom-formats: ("<%Y-%m>" . "<%Y-%m %H:%M>") # eval: (org-toggle-time-stamp-overlays) # End: Using (org-...
user avatar
4 votes
Accepted

Is there a way to recognize `-- vim: et:sw=4:ts=8:sts=4:tw=80` in emacs?

I wouldn't be surprised if there's already a package out there that does it, but I couldn't find one. You should be able to cover most of it with something along the lines of the untested code below: ...
user avatar
  • 25.2k
3 votes

Can I set a particular file to automatically and silently accept changes?

Yes. Put this at the end of your file. * COMMENT Config Local Variables: eval: (auto-revert-mode 1) End: This assumes Org-mode, for other modes use comments in the language used as explained in the ...
user avatar
  • 1,609
3 votes
Accepted

python-mode: tab always indents with 2 spaces

The syntax for file-local variables requires -*- on both ends (OP is missing the closing one); the following works correctly: # -*- mode: Python; python-indent-offset: 4; python-guess-indent: nil -*- ...
user avatar
  • 8,783
3 votes
Accepted

Using File Local Variables in org-mode

Orgmode's export function copies the buffer content to a new buffer and evaluates the source blocks in the new buffer. Thereby only buffer local variables with prefixes org- and orgtbl- are copied ...
user avatar
  • 29.8k
3 votes
Accepted

file-local-variables not evaluated on load

Using mode for anything but the major mode is deprecated. To enable minor modes, use eval: %%% Local Variables: %%% mode: latex %%% eval: (orgtbl-mode 1) %%% End: See (info "(emacs) Specifying File ...
user avatar
  • 43.1k
3 votes
Accepted

File local variables doesn't work

As explained by @NickD, org-duration-format isn't a safe variable: (get 'org-duration-format 'safe-local-variable) ; nil So there are two ways: Set enable-local-variables to t for getting asked if ...
user avatar
  • 141
2 votes
Accepted

Mode local variables

Yes, make the variable buffer-local, and turn the mode on in a given buffer, to use it. Your code can of course test whether the mode is on in a given buffer.
user avatar
  • 69.1k

Only top scored, non community-wiki answers of a minimum length are eligible