Skip to main content

Questions tagged [local-variables]

Use this tag for questions about variables local to a function, defined by let-binding them.

Filter by
Sorted by
Tagged with
0 votes
0 answers
104 views

Emacs/aucTeX ignores local variables

I am using emacs 29.2 (installed via brew) and auctex (14.04) on a Mac (12.7.4). My .emacs file shows: '(enable-local-variables :t) I have the following at the end of a TeX file: %%% Local Variables: ...
sgmoye's user avatar
  • 179
0 votes
1 answer
91 views

"Aliasing" `ls` to `gls`

gls not ls: My system has two forms of ls, the standard "old school" version of ls, and GNU ls which is available as gls. In my shell, I simply created an alias to use gls, but I have not ...
Anoduck's user avatar
1 vote
1 answer
48 views

Check value of local variable assigned with let/let* editing org-export functions

On my way learning emacs and doing some first steps in elisp programming, I'm trying to adapt the LaTeX output of org-export. It's a lot learning by doing and that's a good thing since it improves my ...
lukeflo's user avatar
  • 195
0 votes
2 answers
60 views

cannot use buffer-local variables after defining them

I'm trying to define a buffer-local variable inside a function using setq-local in a function here is the function definition: (defun set-buffer-local-variable () (with-current-buffer (get-buffer-...
ntriisii's user avatar
0 votes
1 answer
82 views

Returning the value of a buffer variable

Is this a good way to return the value of a buffer variable (if (local-variable-p variable buffer) (buffer-local-value variable buffer) (default-value variable))
Dilna's user avatar
  • 1
1 vote
2 answers
245 views

Avoid placing safe-local-variable-values in init file

I have a project with a .dir-locals.el file. This file contains some customizations for various project local variables, e.g. include directories for semantic and arguments for clang. First time ...
alexpanter's user avatar
4 votes
1 answer
331 views

How can I set a buffer-local variable (format-all-mode) to nil within .dir-locals.el? (using Doom emacs)

I have a project where I want to disable format-all-mode for all my python files. I can do this manually by running M-x format-all-mode every time I open up a python file for that project. I tried ...
modulitos's user avatar
  • 2,492
0 votes
1 answer
168 views

Bring setq variable into a (let ...) context of a elisp function?

I have written a function snippet that copies a paragraph to the kill-ring. I try to collect different point positions and corresponding line numbers: bop - begin of paragraph blnum - line umber of ...
huckfinn's user avatar
  • 125
1 vote
1 answer
48 views

How to stop set-auto-mode from removing local variable binding? [duplicate]

Why does (set-auto-mode) remove the local variable binding and how I can keep the local binding around? (defvar-local test-var nil) (setq test-var t) (message "%s" test-var) ;; t (set-auto-...
breatheoutbreathein's user avatar
1 vote
1 answer
135 views

How can I force require-final-newline nil?

I'm doing this from typescript-mode-hook: (defun disable-final-newline () (setq-default mode-require-final-newline nil) (setq-default require-final-newline nil) (setq mode-require-final-newline ...
Croad Langshan's user avatar
0 votes
0 answers
118 views

Stop AuCTeX from asking for a master file everytime I compile for the first time after reopening Emacs

Since I work with multifile-documents, I put (setq-default TeX-master 'nil) in my init.el. Everytime I compile for the first time in a new Emacs-session, I get queried for the master file. The first ...
Sinthoras's user avatar
0 votes
2 answers
30 views

Avoiding code duplication with conditional code that uses let bindings

This is the procedural logic I want to program in Elisp: def my_func(): v1; v2; if (some_condition): v1 = 2 v2 = 3 else: v1 = 4 v2 = 5 foo(v1) ...
Gradient's user avatar
  • 211
2 votes
3 answers
459 views

local variable set to nil after switch-to-buffer call

Emacs 26.1 user here. I know some common-lisp but new to elisp, so I wonder if I'm missing something obvious. I'm trying a rather simple frame setup with a function I wrote, and there's this strange ...
AlbusMPiroglu's user avatar
7 votes
1 answer
340 views

How to make sure no global variables have been created in a piece of lisp code?

I am writing some lisp code and I would like it not to mess with the global variables in the system. I am therefore being very careful to only use variables within the scope of the let special form. ...
Ruy's user avatar
  • 839
1 vote
2 answers
635 views

.dir-locals for specific directory but not its children

How to set a directory local variable for a directory itself non-recursively? I don't want the variable set in .dir-locals.el affect the sub-directories. Edited: My use case is: I'd like to hide dot ...
Saddle Point's user avatar
1 vote
1 answer
313 views

Can not read dir-local variable from a hook function

hope you are all well. Before stating problem, let me tell you my setup. I am using Emacs 27.1, using pyvenv, projectile, lsp-mode, lsp-python-ms for python-mode. I have set WORKON_HOME environmental ...
shimon's user avatar
  • 51
1 vote
1 answer
256 views

How to change a variable value in the current buffer?

I spent a long time looking for this and kept getting reference to M-x customize. But, that didn't give me access to certain variables like comment-start. I couldn't access comment-start with M-x ...
mcp's user avatar
  • 556
1 vote
1 answer
123 views

Local variable's state mutated across function calls [duplicate]

I was surprised to discover that a local variable can have it's state modified across function invocations. Consider the following example. (defun example-mutable () (let ((x '("the" "quick" "...
dpritch's user avatar
  • 445
5 votes
3 answers
645 views

How to bind keys to a function which can be defined per-mode?

Currently I have variables defined with setq-local, this is useful for modes, so I can define variables only for a particular mode. How can this be done for functions? I'd like to have a function, ...
ideasman42's user avatar
  • 8,925
6 votes
1 answer
209 views

Surprisingly persistent local variable

A local variable keeps coming back, and I know not whence. In a certain buffer, TeX-command-extra-options is "--synctex=1", even after I have removed this from my init.el and restarted Emacs. I tried ...
Toothrot's user avatar
  • 3,284
2 votes
2 answers
1k 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 ...
Maikol Solís's user avatar
1 vote
2 answers
85 views

When local variables are "calculated"?

Does elisp calculate values of local variables at declaration or when calling them? Say i want to find out what headlines in buffer are lvl2, and do stuff to them: (defun map-org-heads () (org-...
testing-lisp1's user avatar
1 vote
1 answer
719 views

Enable .dir-locals.el variables inside just opened buffer

I'm programmtically create a new buffer as a result of shell command (defun jira-ticket-view (&optional jira-ticket) "Open Jira Ticket Inside Emacs" (interactive) (setq jiraURL (get-jira-...
DmitrySemenov's user avatar
4 votes
1 answer
258 views

Make a variable visible to some functions only

Consider the following metacode: ;;; -*- lexical-binding: t -*- (defvar var1 ...) (defvar var2 ...) (defun main () "Main entry point" ...) (defun func1 ...) (defun func2 ...) ... (defun funcn ...)...
antonio's user avatar
  • 1,822
0 votes
1 answer
82 views

How not to propagate dired-actual-switches as a directory variable to the sub directories

I want to set dired-actual-switches for the directory /path/to/data, but not for data's subdirectories. So I generated the following .dir-locals.el file in /path/to/data: ;;; Directory Local ...
halloleo's user avatar
  • 1,355
11 votes
0 answers
2k views

Display all local variables within a edebug session

When using edebug one can get a local variable by command describe-variable (C-h v), but are there any ways to display all local variables? For example in Python you can call locals() in a pdb ...
atevm's user avatar
  • 958
0 votes
2 answers
320 views

write-file-functions: Clarification as to permanent local behavior with add-hook

According to the write-file-functions doc-string, "[t]his variable's value is permanent if it is given a local binding." Step 1: Start from emacs -q using Emacs 25.2.1. Step 2: Switch to the *...
lawlist's user avatar
  • 19.2k
3 votes
1 answer
1k views

.dir-local.el misunderstanding

I generated a .dir-locals.el by calling the function add-dir-local-variable, giving it the path for the project for which I want the variable, the variable itself, and its value. The generated file ...
Gauthier's user avatar
  • 511
0 votes
1 answer
64 views

Idiomatic way to improve `insert-pair`

I have the following custom implementation of insert-pair: (defun *-insert-pair (&optional arg open close) "Wrap next ARG sexps in parentheses. If there is no next sexp, insert a new pair of ...
Tianxiang Xiong's user avatar
2 votes
1 answer
538 views

Using local variables in cl-loop

This is my first time trying to write my own elisp code, so bear with me. I have the following cl-loop: data contains the following: ((refs . [((file . "api/user.js") (start . 266) (end . 269)) ((...
aiguofer's user avatar
  • 588
2 votes
1 answer
693 views

Making a variable window-local

I am developing a feature to adapt a mode-line to the width of the window. I have developped it so far using buffer-local variables to store the state of the mode-line, however, when I open the same ...
deb0ch's user avatar
  • 203
2 votes
1 answer
1k views

How can I automatically add some local variables info to a C-x C-f new (.tex) file?

I use auctex to edit my .tex files. Each time I create a new file .tex file via C-x C-f, I want to insert two local variables informations: % Local Variables: % coding: utf-8-unix % TeX-engine: ...
cjorssen's user avatar
  • 197
5 votes
3 answers
1k views

How can I create mode-local variables?

I'm looking to create a command which stores a kind of "history" for the current major-mode. I need the variable to be independent for each major mode, but consistent across all buffers in any ...
JCC's user avatar
  • 1,029
5 votes
2 answers
2k views

How to customize major mode initialization with local variables?

Seems like most major modes clear all local variables before initializing. It also seems like many major modes read variables while initializing to customize their behavior. If I want to set a file ...
sfridman's user avatar
  • 151
0 votes
2 answers
359 views

Combine setq and concat

Could you help me with smarter way of handling package-archives? At the moment I have the following in my init.el ;; This is dumb but... (if (eq system-type 'windows-nt) (setq package-archives '((...
Maxim Kim's user avatar
  • 1,766
2 votes
1 answer
122 views

How to reference a local variable inside the definition of a function?

Is it possible to reference a local variable inside the definition of a function? Here's an example: I have an alist text-alist consisting of keys and text snippets. I want each text snippet bound to ...
Erik Sjöstrand's user avatar
15 votes
1 answer
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 ...
Brendan's user avatar
  • 303
9 votes
2 answers
930 views

Prevent folding org files opened by ediff

Folding gets in the way when merging two org files using ediff, so I'm trying to disable all folding in org-mode buffers created by ediff. Non-ediff folding behavior should remain unaffected. ...
ebpa's user avatar
  • 7,529
6 votes
2 answers
442 views

Match against a variable with pcase

I'm trying to get pcase to match against a let-bound variable. However, I can't seem to get pcase to recognize the variable correctly. See this minimal example: (let ((a 1)) (pcase 2 (a 7))) => ...
PythonNut's user avatar
  • 10.4k
1 vote
0 answers
148 views

My function seems to not know a variable has changed and gives the wrong output

I want to change the shebang string every time I create a new Python file, some projects use Python 2 and other use Python 3, so the shebang should change according to the value of a variable in the ....
shackra's user avatar
  • 2,812
22 votes
2 answers
4k views

Remember permission to execute "risky" local variables

In many of my projects I use .dir-locals.el files to setup project specific variables such as compile commands. Upon opening a file within a directory containing such a file, emacs complains about "...
elemakil's user avatar
  • 2,547
6 votes
2 answers
553 views

Using different theme on tramp buffers (and buffer-related themes in general)?

Is it possible to configure emacs so it uses different theme for tramp buffers than for defaults? Say, I use twilight by default, but while editing sth via ssh I'd like to switch to pastels-on-dark... ...
Mekk's user avatar
  • 1,047
3 votes
1 answer
830 views

Set variables based on path without using directory-local variables

I want to set variables, in particular, compile-command and tabbing related variables based on the path of the file I'm editing. In my .vimrc I use the following to do this. autocmd BufRead,...
Praxeolitic's user avatar
5 votes
1 answer
1k views

How to get an value from a buffer local variable

I have the following code in the file1.el: (with-current-buffer (get-buffer-create "TestBuffer") (read-only-mode -1) (erase-buffer) (make-local-variable 'source) (setq source (get-source-...
Andrii Tykhonov's user avatar
16 votes
2 answers
858 views

Is there a way to daisy chain .dir-locals.el files?

Suppose I have a directory with these files. /foo/bar/baz/.dir-locals.el /foo/bar/.dir-locals.el /foo/.dir-locals.el When I go to create a file in /foo/bar/baz/, I'd like to daisy chain them ...
Eric Johnson's user avatar
2 votes
1 answer
316 views

How to activate whitespace-mode for a cc-mode buffer from .dir-locals.el?

I'd like to enable whitespace-mode from a .dir-locals.el file such that when I open a file managed by cc-mode, I will see trailing spaces highlighted with the whitespace face. I think I'm close. This ...
Eric Johnson's user avatar
8 votes
2 answers
2k views

Only enable whitespace mode in certain buffers

I would like to have whitespace mode turned on for all buffer except for org-mode ones. It is easy to do this when emacs starts up, but since I use a persistant copy of emacs with emacs daemon mode I ...
jcv's user avatar
  • 235
6 votes
1 answer
1k views

How do I use company-mode in some buffers and auto-complete-mode in others?

My init.el loads company with (global-company-mode). I want to make an exception for Javascript buffers, and instead use auto-complete-mode for that mode. Q: I am struggling to find a way to unhook ...
Chris's user avatar
  • 719
9 votes
2 answers
979 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 ...
emacsomancer's user avatar
  • 1,041
5 votes
2 answers
77 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 ...
Sean Allred's user avatar
  • 6,951