Questions tagged [file-local-variables]

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").

Filter by
Sorted by
Tagged with
13
votes
2answers
2k views

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: ;; ...
13
votes
1answer
1k views

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 ...
12
votes
3answers
975 views

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 ...
12
votes
1answer
863 views

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) (...
12
votes
1answer
136 views

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-...
11
votes
2answers
2k views

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 "<f10>") 'some-custom-defun-specific-to-this-...
9
votes
2answers
730 views

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 ...
9
votes
1answer
168 views

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: ...
7
votes
2answers
1k views

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 ...
7
votes
1answer
514 views

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?
6
votes
1answer
286 views

# -*- 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 ...
6
votes
1answer
1k views

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 ...
5
votes
2answers
881 views

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, ...
5
votes
2answers
72 views

How can I make documents 'portable' between Emacsen?

I put 'portable' in quotes because, as we all know, Emacs works with plain text and this plain text is innately portable. However, the format of this plain text is not. My particular use-case is with ...
4
votes
1answer
99 views

How to prevent parsing file-local variables?

I have the following text: Local Variables: eval: (face-remap-add-relative 'default :family "AR PL KaitiM GB" :foundry "ARPH") End: In my document as a code sample. However, whenever I open the ...
4
votes
2answers
214 views

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 ...
4
votes
1answer
1k views

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 ...
3
votes
3answers
199 views

User command to reload file-local variables

How can I easily reload file-local variables, after I have changes their values in the file buffer? I know a work around Save and close the file and re-open. But this is pretty cumbersome.
3
votes
1answer
221 views

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

I'm working on a project with all source files appended with this vim formating rule -- vim: et:sw=4:ts=8:sts=4:tw=80. Is there a way to make Emacs setup the correct indentation for me automatically? ...
3
votes
2answers
103 views

byte compile file-local variables

Is it possible to access a user-defined file-local variable during byte-compilation? As an example, I am trying to get this code to work: --- testfilelocals.el --- ;; -*- my-file-local: "foo" -*- (...
3
votes
0answers
440 views

How to mark risky variable as safe?

I have some customization in my .dir-locals.el. Some of variables set there are unsafe and when I set them and visit some file in dir for the first time Emacs nicely asks me to save their name-value ...
3
votes
0answers
899 views

How to set the Ispell language via a file variable in Org-Mode?

I put the following in the beginning of the Org file: * :noexport: Local Variables: ispell-local-dictionary: "american" End: #+EXPORT_EXCLUDE_TAGS: noexport And I start flyspell via a hook: (add-...
2
votes
1answer
526 views

Org-mode COMMENT blocks local variable eval?

The code below is an org-mode file that will not load by-backend. But if I put the org code block setup anywhere else besides under * COMMENT it does run and (fbound 'by-backend) gives t. What is it ...
2
votes
1answer
84 views

How to use a prompting interactive function in an elisp source file

I've seen this, but it doesn't work for this case.... Basically, I want to do a load-file on an .el file containing (add-file-local-variable-prop-line "eval" "(set-input-method 'TeX)") and have it ...
2
votes
1answer
205 views

Mode local variables

I frequently use file-local variables, but after writing some minor modes I find the need to implement mode-based behavior. Let's say I want to define a variable errors-list-regexp that varies ...
2
votes
2answers
217 views

How to customize DONE headlines per-file in org-mode?

I would like to customize the headline and keyword inside of an org file. In this question is shown how to change the faces of each keyword, but not the headlines. For the moment, I haven't achieve ...
2
votes
0answers
384 views

.dir-locals.el isn't recognized

I am working on a project that includes some configuration in .dir-locals.el: ((c++-mode . ((compile-command . "cd ../../\; ./build.sh")))) This gets picked up just fine for me and sets the ...
1
vote
2answers
862 views

Add hook for specific files

I am looking to create some customized settings for a specific file. I think I want to add a hook for that file, or something that will create a few settings when that file loads. For example, I have ...
1
vote
1answer
132 views

How to make a file variable buffer local?

I have customized the variable sh-indentation with 4, but in one file I would like to use a different value. So I defined a file variable: # -*- mode: sh; sh-indentation: 2; -*- But the result is ...
1
vote
1answer
65 views

Disable auto-backup only for certain files

As of How to stop auto backup in some directory in Emacs, it's possible to configure emacs to backup conditionally. Is there an option to set inside the file, in the first line, to disable backup for ...
1
vote
1answer
67 views

How to check if a variable is a file local variable

Some background, I have some code that sets a default compile command depending on the mode. However, in some files, I've used the add-file-local-variable-prop-line to create a more specific command, ...
1
vote
1answer
195 views

How to save speck-mode dictionary with file?

What I tried, putting at the end of a file: Local IspellDict: de As local variable: speck-dictionary: de However, neither is interpreted. When I open the file in question, speck-mode always uses en ...
1
vote
1answer
72 views

Cannot run a file-local after-save-hook with arguments

I have been trying to make auto-save compilation rules for my org files. I have tested the following functions in the interpreter: (defun async-shell-command-no-window (command) (interactive) (...
1
vote
0answers
54 views

file-local variables vs directory-local variables in Auctex [duplicate]

I have a file with the following content, let's call it tmp.tex \emph{Hello} %%% Local Variables: %%% mode: latex %%% TeX-master: "main" %%% End: and another file main.tex that includes the ...
1
vote
2answers
599 views

emacs indentation style in file local variables

I am using emacs 24.5 and I ran into a problem with file local variables. I am working on a git project where file local variables are set like: /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:...
1
vote
0answers
27 views

Specify fallback possibilities for file-local variables?

It is clear from the manual how to set file variables: -*- mode: modename; var: value; … -*- For example, at the top of my ~/.gitconfig file, I have # -*- mode: conf; -*- I recently discovered ...
0
votes
1answer
541 views

python-mode: tab always indents with 2 spaces

I start up my Emacs25 with emacs25 -Q to skip any init.el. When I then open a python file with local file variables as shown below, TAB indents only two spaces, instead of four: # -*- mode: Python; ...
0
votes
1answer
21 views

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

I have the following local variables defined in a XeTeX file. As you can see, the input method is currently set to Devanagari. This is inconvenient when I want to type Roman letters. I'd like a way to ...
0
votes
1answer
25 views

shell-script mode: set local vars for indentation

I have a shell script that uses 2-space indentation, like this: #!/bin/bash function foo() { echo "Hello world" echo "Nice to see you $1" } foo Tony Emacs default indentation for shell is 4-...
0
votes
1answer
67 views

Adding to kill-buffer-hook results in “setq: Wrong type argument”

Subtract a buffer's (the file's) size from a variable before killing it. Emacs 26. (defvar cumulative-open-bytes '0 ) (defun buffer-settings-calc-bytes () (interactive) (let ((current-open-file-...
0
votes
0answers
22 views

Setting reftex-section-levels as a file-local variable

I'm trying to set reftex-section-levels as a file-local variable on a few files I have, since they use non-standard sectioning commands. If I start emacs and open one such file, such as this ...