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
16
votes
2answers
3k 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-...
14
votes
1answer
2k 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 ...
14
votes
1answer
1k 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) (...
13
votes
2answers
3k 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
158 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
3answers
1k 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 ...
9
votes
2answers
809 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
276 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: ...
8
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 ...
8
votes
1answer
2k 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 ...
8
votes
1answer
723 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?
7
votes
2answers
2k 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, ...
6
votes
1answer
340 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 ...
5
votes
1answer
3k 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 ...
5
votes
2answers
73 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
408 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? ...
4
votes
1answer
122 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
412 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
0answers
1k 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-...
3
votes
3answers
707 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
2answers
136 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
594 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 ...
2
votes
1answer
789 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
100 views

file-local-variables not evaluated on load

Here is my example mwe-1.tex local variable declaration from within this file is %%% Local Variables: %%% mode: latex %%% mode: orgtbl %%% End: when I execute this command in a shell: emacs -q -...
2
votes
1answer
143 views

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

I'm currently attempting to call the function company-org-roam--init-hook from org-mode-hook in order to enable the company-org-roam backend in org-roam buffers. In some of the files in which this ...
2
votes
1answer
125 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
251 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
545 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
429 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
1k 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
154 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
111 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
117 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
222 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
1answer
236 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
0answers
24 views

Ignore file- and directory-variables when using “emacs -Q”?

I am using emacs -Q as editor for git, because my startup is too heavy for "quick editing" use and using emacsclient will hang when git is invoked with M-x shell-command. However, as a ...
1
vote
0answers
43 views

Specify the input method for a file

Using Doom Emacs 2.0.9 on Emacs 26.3 on Manjaro. I am writing some devanagari text in a file. Every time I edit the file, I need to toggle-input-method and select 'devanagari'. Is there a way to ...
1
vote
2answers
834 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
29 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
821 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
47 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
49 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
26 views

File-local variables not parsed in lilypond file

I have a definitions.ly file that ends with the following: %%% Local Variables: %%% LilyPond-master-file: "score.ly" %%% End: However, the value of LilyPond-master-file is still nil when I ...
0
votes
1answer
115 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
27 views

How can I evaluate a file-local eval pseudo-variable lexically?

I have a use-case with a directory-local eval variable where it's necessary (or at least, more convenient) that it's evaluated with lexical binding. Specifically, the form to be evaluated looks ...