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
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))
0 votes
1 answer
77 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 ...
0 votes
0 answers
103 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: ...
1 vote
1 answer
44 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 ...
1 vote
2 answers
208 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 ...
0 votes
2 answers
57 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-...
4 votes
1 answer
311 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 ...
0 votes
1 answer
157 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 ...
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-...
1 vote
1 answer
130 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 ...
0 votes
0 answers
110 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 ...
0 votes
2 answers
28 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) ...
1 vote
2 answers
598 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 ...
2 votes
3 answers
454 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 ...
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, ...
7 votes
1 answer
339 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. ...
1 vote
1 answer
310 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 ...
1 vote
1 answer
248 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 ...
6 votes
2 answers
438 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))) => ...
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" "...
9 votes
2 answers
926 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. ...
6 votes
1 answer
208 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 ...
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 ...
1 vote
2 answers
83 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-...
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 "...
1 vote
1 answer
716 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-...
2 votes
1 answer
686 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 ...
4 votes
1 answer
255 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 ...)...
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 ...
10 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 ...
0 votes
2 answers
319 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 *...
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 ...
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 ...
2 votes
1 answer
532 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)) ((...
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 ...
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: ...
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 ...
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 ...
0 votes
2 answers
353 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 '((...
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 ...
10 votes
2 answers
4k views

How can I prevent flycheck-mode from checking certain files?

I've configured Emacs to open files named *.cfg in shell-script-mode. These are config files, of course, rather than shell scripts, but 90% of the time it does what I want (mainly, good guesses about ...
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 ....
14 votes
1 answer
1k views

Make a buffer-local variable become global again

I was experimenting with local variables and set: (defvar-local foo nil "Buffer local foo") I later redesigned my program to use a global variable instead using: (defvar foo nil "Not buffer local ...
6 votes
2 answers
547 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... ...
3 votes
1 answer
829 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,...
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-...
16 votes
2 answers
850 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 ...
2 votes
1 answer
314 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 ...
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 ...
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 ...