Skip to main content
22 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 ...
Gilles 'SO- stop being evil''s user avatar
14 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"...
nega's user avatar
  • 3,276
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.
Chen Levy's user avatar
  • 385
10 votes
Accepted

Can I mark a local variable as safe for a single file only?

In the elisp manual at C-hig (elisp)File Local Variables we find: You can specify safe values for a variable with a ‘safe-local-variable’ property. The property has to be a function of one argument; ...
phils's user avatar
  • 51.7k
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 ...
John Kitchin's user avatar
  • 11.9k
7 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 ...
Gilles 'SO- stop being evil''s user avatar
6 votes
Accepted

File-local variable to force specific shell for shell-script major mode

C-hf sh-mode says: This mode adapts to the variations between shells (see sh-set-shell) by means of an inheritance based feature lookup (see sh-feature). This mechanism applies to all ...
phils's user avatar
  • 51.7k
5 votes

User command to reload file-local variables

I stumbled myself over a way to do this when looking at the Elisp code in files.el: M-x normal-mode This command re-applies the local file variable list by calling the function hack-local-variables. ...
halloleo's user avatar
  • 1,345
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 ...
erikstokes's user avatar
  • 12.9k
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 ...
YoungFrog's user avatar
  • 3,526
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: ...
Stefan's user avatar
  • 26.5k
4 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 ...
Tobias's user avatar
  • 33.3k
3 votes
Accepted

How to set a variable on a single buffer?

eval: is a special form in the Local Variables section that evaluates the given Elisp-form. That is not what you want. The actual syntax for setting file local variables is: MAYBE_COMMENT ...
Tobias's user avatar
  • 33.3k
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 ...
DPD-'s user avatar
  • 251
3 votes
Accepted

Ignore all buffer's local variables

The doc string of enable-local-variables says: … A value of nil means always ignore the file local variables. … You can customize the value of this variable to Ignore, open your file and revert the ...
Tobias's user avatar
  • 33.3k
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 ...
phils's user avatar
  • 51.7k
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 -*- ...
npostavs's user avatar
  • 9,213
2 votes
Accepted

Disable auto-backup only for certain files

According to my test, simply set make-backup-files to nil locally, for example, M-x add-file-local-variable-prop-line make-backup-files nil
xuchunyang's user avatar
  • 14.6k
2 votes

Commenting out/disabling file local variable for input method in AUCTeX

I don't understand why you want to comment out that line (especially since it won't have any effect until you re-open the file or do something like M-x normal-mode): to toggle the devanagari-itrans ...
Stefan's user avatar
  • 26.5k
2 votes
Accepted

shell-script mode: set local vars for indentation

There should be a space instead of a - between Local and Variables:
Stefan's user avatar
  • 26.5k
2 votes

User command to reload file-local variables

I just use find-alternate-file which is bound to C-x C-v by default. C-x C-v Ret is lightning fast for me. revert-buffer will also work, but M-x revert-buffer Ret is more typing. Both of these ...
nega's user avatar
  • 3,276
2 votes

User command to reload file-local variables

I use quite often hack-local-variables to set the file local variables without side-effect (such as re-loading the major mode). giglair already suggested that in his comment. Warning: It does not ...
Tobias's user avatar
  • 33.3k
2 votes
Accepted

At what point are file-local and dir-local variables applied to a newly-loaded buffer?

Is it expected that dir-local variables are applied only after major-mode hooks are run? Yes. The local variables are normally processed in run-mode-hooks, after running the mode hooks and before ...
phils's user avatar
  • 51.7k
2 votes

How to set a variable on a single buffer?

[Not an answer: just a summary and linearization of the comments, which are pretty confusing as they stand and mostly deal with a different problem.] The way to set a local variable is as described ...
NickD's user avatar
  • 30.8k
2 votes

File-local variables do not affect org-babel-execute

First here's a simplified version of the problem. Consider this Org mode file: #+begin_src elisp (setq-default foo "bar") (defun func() (princ foo ) (with-temp-buffer "*tmp-...
NickD's user avatar
  • 30.8k
2 votes
Accepted

flyspell: ignore certain words in a buffer, but not others?

I can't directly convert @lawlist's comment into an answer, but it's exactly what I wanted: ispell.el has (defconst ispell-words-keyword "LocalWords: " "The keyword for local oddly-...
Dan Drake's user avatar
  • 625
2 votes
Accepted

risky file local “outline-level”

Its value is a function: Its value is ‘outline-level’ Function of no args to compute a header’s nesting level in an outline. It can assume point is at the beginning of a header line and that the ...
NickD's user avatar
  • 30.8k
1 vote
Accepted

How to hide "Local Variables:" specification at the end of a file or how to prevent "M->" from get into that region

You ask: why not put the local variable specification on the front of the file? You can alternatively put file-local variables at the very top of the file. See the Emacs manual, node Specifying File ...
Drew's user avatar
  • 78k
1 vote

Proper way to set file variables in an org-file

You have a syntax error in the value you give for org-html-xml-declaration. If you check the *Messages* buffer, you will probably find one that says “File local-variables error: (end-of-file)”. It is ...
db48x's user avatar
  • 18.4k
1 vote
Accepted

File-local variables not parsed in lilypond file

I can reproduce this and it's probably a bug, but lilypond-mode.el (at least my version of it) is very old and has not seen much updating. Not even sure where to report the bug. As a workaround ...
NickD's user avatar
  • 30.8k

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