Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [file-local-variables]

File local variables are set automatically from -*-specifications-*- or "Local Variables:" specifications when visiting a buffer.

4
votes
1answer
86 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 ...
0
votes
0answers
22 views

file-local variables vs directory-local variables in Auctex

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 ...
4
votes
1answer
231 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 ...
3
votes
1answer
76 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 ...
0
votes
1answer
296 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; ...
1
vote
1answer
34 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 ...
2
votes
1answer
106 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? ...
5
votes
2answers
375 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, ...
0
votes
1answer
57 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-...
6
votes
1answer
747 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 ...
3
votes
1answer
356 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 ...
1
vote
2answers
408 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:...
3
votes
0answers
280 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 ...
1
vote
0answers
22 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
126 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 ...
4
votes
1answer
51 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 ...
10
votes
1answer
639 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 ...
10
votes
1answer
759 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) (...
2
votes
1answer
62 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
0answers
572 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-...
1
vote
1answer
120 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
56 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, ...
3
votes
2answers
84 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" -*- (...
8
votes
1answer
106 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: ...
1
vote
2answers
557 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 ...
2
votes
1answer
148 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
0answers
318 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 ...
12
votes
1answer
127 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-...
5
votes
1answer
357 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?
9
votes
2answers
664 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 ...
5
votes
2answers
69 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 ...
6
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 ...
10
votes
3answers
801 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
1k 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-...
12
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: ;; ...