Questions tagged [variables]

for variables in Emacs Lisp, which are symbols with values. The symbol’s name is also called the variable name. Most variable names, by convention, consist of lowercase, ordinary words separated by hyphens.

Filter by
Sorted by
Tagged with
42 votes
2 answers
7k views

How to evaluate the variables before adding them to a list?

The below obviously doesn't work and hence this question. How do I correct the below code so that the value of somelist becomes '(("abc" . 123)) ? (setq x "abc") (setq y 123) (setq somelist nil) (...
Kaushal Modi's user avatar
  • 25.4k
31 votes
2 answers
12k views

what does "let*" ( let asterisk) mean in elisp

I've used let before, but never used let* what does let* ( let asterisk) mean in elisp? fyi this one was hard to google because of the asterisk.
american-ninja-warrior's user avatar
31 votes
3 answers
5k views

Reset custom variable to default value programmatically

Q: Using Elisp, how can I reset a variable to its default value without knowing what that value is? I tried to figure out how to do this by bringing up the Customize interface for a variable I set to ...
itsjeyd's user avatar
  • 14.6k
14 votes
3 answers
3k views

Assigning same value to multiple variables?

Sometimes I need to set same value to multiple variables. In Python, I could do f_loc1 = f_loc2 = "/foo/bar" But in elisp, I am writing (setq f_loc1 "/foo/bar" f_loc2 "/foo/bar") I am wondering ...
Chillar Anand's user avatar
12 votes
2 answers
1k views

Elisp: How to exclude sensitive information from an init file? (ie login credentials)

I want to define a log in function in my init script, but I don't want to hardcode my login credentials. I think a good workaround is to have my init script read in my login credentials from a local ...
modulitos's user avatar
  • 2,452
11 votes
2 answers
2k views

Search through the values of all variables in Emacs

I'd like to find which variables contain a certain value. Is there a way to do a regex search through the values of every variable in Emacs?
izkon's user avatar
  • 1,818
11 votes
2 answers
3k views

How to include other .org files programmatically (ie not from main .org file)?

Including other .org files is quite easy. For example, for configuration, #+setupfile: /path/to/config.org or #INCLUDE: /path/to/config.org Those lines need to be in the .org file in order to be ...
gsl's user avatar
  • 1,752
11 votes
1 answer
2k views

Color declared variables

I'm looking for a simple way to make emacs remember of declared variable in a single function in C/C++. By "simple", I mean without any external package, just with some elisp lines in configuration ...
Aracthor's user avatar
  • 173
10 votes
4 answers
638 views

Can I reload a library and have defvar re-assign values?

I am developing a library and would like to reload it after editing without exiting Emacs (assume that it is on load-path): (load-library "myname") When I do this, Emacs doesn't pick up changes to ...
gavenkoa's user avatar
  • 3,362
9 votes
3 answers
3k views

Quick way to toggle a variable

It would be nice to have a quick way to toggle a variable. Here's something that I have in mind. Call a "toggle var" function. The completing-read should list only variables that have single values (...
Kaushal Modi's user avatar
  • 25.4k
9 votes
1 answer
12k views

Symbol’s function definition is void

I am trying to make an interactive toggle in emacs 27.0.90 When I eval-region no warnings or errors are shown. However, when I do (helm/toggle-frame) in ielm it throws Symbol’s function definition is ...
546756ryd's user avatar
9 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
  • 938
8 votes
3 answers
2k views

interactively edit emacs variable in buffer

I was looking at this on StackOverflow and was wondering if there was a nice way built-in to edit strings of text stored in variables as if they were buffers? M-x set-variable doesn't really cut it ...
wdkrnls's user avatar
  • 3,667
8 votes
1 answer
1k views

Autoloads and variables

I understand what autoload does for functions (register file to load when such function is called or its documentation string is retrieved). However, it's not clear how to use autoload facility in ...
Mark Karpov's user avatar
  • 4,933
7 votes
4 answers
354 views

Tracking when variables get updated

I have a problem with org-mode's agenda view. While I've set org-agenda-files to '("~/org/") invariably when I finally spin up M-x org-agenda I find that org-agenda-files just points to one org-file. ...
stsquad's user avatar
  • 4,626
7 votes
1 answer
1k views

Define a function alias within a let binding?

How can I define an alias within a script with let-binding? I tried (let (b-s) (defalias 'b-s 'buffer-string)) But it doesn't work. I figured out to let-bind the variable where aliases as stored ...
Gabriele Nicolardi's user avatar
7 votes
1 answer
262 views

What type of variable binding is setq creating?

What type of variable binding or variable or symbol is setq creating, when the variable hasn't been declared prior setq? Given following source code: ;; -*- lexical-binding: t; -*- (defun setq-x () ...
jue's user avatar
  • 4,501
7 votes
2 answers
973 views

The default value of buffer-local variable not set until first `setq`

Say I define a buffer-local variable foo, and its default value is "a": (defvar foo "a") (make-variable-buffer-local 'foo) (default-value 'foo) ;; => "a" Immediately after this I run the ...
cutejumper's user avatar
6 votes
1 answer
1k views

Scope in lambda

In my .emacs conf file, I've got this function that adds a hook to set the compile-command based on the mode. It looks something like, (defun set-compile-cmd (mode-hook cmd) (add-hook mode-hook (...
user1943733's user avatar
6 votes
2 answers
488 views

What does customize: Set for Current Session do?

I have a variable that I want to switch between two different values and have it apply for the whole session. I'm able to do this using M-x customize-variable and picking "Set for Current Session". ...
Jim Hunziker's user avatar
6 votes
2 answers
275 views

Are there any libraries in Emacs or the wider package system for automatically persisting variables

I have a number of variables that store useful state that would be nice to persist across restarts of Emacs. Are there any libraries that allow this to be done simply so I can avoid a bunch of ...
stsquad's user avatar
  • 4,626
6 votes
1 answer
193 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,254
6 votes
2 answers
2k views

Debugging "Warning: Reference to free variable"

I have something like below (from the answer) in my init file: (add-hook 'LaTeX-mode-hook 'my-latex-hook) (defun my-latex-hook () (require 'tex-site) (define-key LaTeX-mode-map "-" (lambda () (...
Name's user avatar
  • 7,749
6 votes
1 answer
296 views

What's really behind an assignment in Emacs lisp?

[Warning : these are noob questions.] I'm a beginner in Emacs Lisp and I would like to be sure that I understand well what I'm really doing when I set a value to a variable with setq or let. Here is ...
Philopolis's user avatar
  • 1,124
6 votes
1 answer
673 views

How to store the variable value after Emacs was closed

Suppose, we have a variable defined in ~/.emacs: (defvar *my-var* "") Then in **scratch** buffer we set some value to it: (setq *my-var* "value") After we close emacs the value will be lost. How ...
user4035's user avatar
  • 1,059
6 votes
1 answer
3k views

elisp: What does "setf" do?

I read the official documentation. Here's what not clear: Scope: If I do a setf in a function, is that visible in another function. Undo: How do I undo it. in ruby, you can do def myfunc a = "...
american-ninja-warrior's user avatar
6 votes
1 answer
303 views

Best way to support obsolete variables

Emacs 25.1 obsoletes a variable isearch-word and recommends to use the new isearch-regexp-function instead. Because Emacs 24 does not have the new variable, I can't just replace it like: (if isearch-...
Yasushi Shoji's user avatar
6 votes
1 answer
265 views

I'm unsure which option to use for setting a variable: setq, customize-set-variable, or setopt

I'm a bit uncertain about which method to use for setting a variable: setq, customize-set-variable, or setopt. I did some research online, and it seems that opinions on this matter are quite varied. ...
Zoli's user avatar
  • 421
5 votes
3 answers
852 views

init.el - setq or defvar

I want to define a trash directory in my user-init-file but I don't know which way to do this is best or most correct. I currently have something like this: (defvar my-trash-dir (expand-file-name "....
rchar01's user avatar
  • 447
5 votes
2 answers
1k views

Set buffer-local variable in buffer other than the current one?

I'm in buffer A and I want to set a buffer-local variable in buffer B. I'm currently doing: (with-current-buffer B (setq-local some-var 'some-val)) but is there a way to do this without changing ...
ivan's user avatar
  • 1,938
5 votes
3 answers
268 views

What are the conditions when a variable can be both dynamically bound and cause a void-variable issue?

I get: Debugger entered--Lisp error: (void-variable implicit-layout-active) When using a variable declared as dynamically bound: (void-variable implicit-layout-active) I thought I cannot get void-...
Gracjan Polak's user avatar
5 votes
1 answer
3k views

Error void-variable on function name

What is the difference between the two functions func1 and func2? (defun func1 (arg) (if (listp arg) (mapcar (lambda (x) (func1 x)) arg) arg)) (func1 (list 1 2 3)) (defun func2 (arg) (...
ceving's user avatar
  • 1,318
5 votes
3 answers
385 views

Set (non-custom) variable to its initial value

Is there a (quick) way of resetting a variable to its default value (as defined in some .el file) after it has been modified? e.g. via commands in the .emacs file, without having to restart emacs. ...
cass's user avatar
  • 53
5 votes
2 answers
741 views

Where are these variables defined? - bytecomp Warnings

Lately I'm getting warnings when compiling the .emacs Warning (bytecomp): reference to free variable ‘url-http-extra-headers’ Warning (bytecomp): reference to free variable ‘oauth--token-data’ ...
Dox's user avatar
  • 965
5 votes
1 answer
974 views

How do you pass a variable in to a lambda?

How can I pass a stringvariable in to this function, so that instead of printing "This is a test", it prints "This is a value-of-variable" (async-start ;; What to do in the child process (...
american-ninja-warrior's user avatar
5 votes
1 answer
169 views

Can a symbol have a function, variable, and class?

Q: can one symbol refer to a function, a variable, and a class? Elisp is a Lisp-2 in which a symbol can have separate function and variable values. So, for example, I can define the following ...
Dan's user avatar
  • 32.7k
5 votes
1 answer
205 views

Function add-variable-watcher does not watch "last-command" variable

I have added a watcher function to watch the last-command variable. (defun my-watch (symbol newval op where) (message "Hello")) (add-variable-watcher 'last-command #'my-watch) The ...
Talespin_Kit's user avatar
5 votes
2 answers
110 views

describe-variable show characters instead of numbers

Is there a way to have describe-variable show characters instead of numbers where it makes sense? Here's for example output of describe-variable word-separating-categories: word-separating-...
Russ Kiselev's user avatar
5 votes
0 answers
555 views

list of current variables in a buffer for Python code

I would like to find a way to reproduce the "Workspace" of Matlab or the equivalent "Variables" window of the awesome pudb debugger directly in emacs for python code: it is a window which details the ...
Robin Tournemenne's user avatar
4 votes
3 answers
731 views

Set an Elisp var on the command line and read it in the init file

I'm trying to set a variable at load-time: # emacs --eval '(defvar myvar t)' Now, in this session, if I C-h v myvar RET I get a nice t. But if I put (message "MYVAR: %s" myvar) in my init file, I ...
yPhil's user avatar
  • 963
4 votes
1 answer
429 views

Why emacs can not see outer variable in lambda function?

I had a simple config to set fci-rule-column to different values depend on file types: (use-package fill-column-indicator :ensure t :config (setq fci-rule-color "LightSlateBlue") (setq fci-...
cuonglm's user avatar
  • 177
4 votes
1 answer
94 views

Per-host background colour

Having got a bunch of custom colors defined (thanks to Drew), I need to use them to customize the background color per host. I have named the colors after the hostname, eg (setq pentacle "#314159") (...
Peter Flynn's user avatar
4 votes
1 answer
153 views

Why isn't this variable being set although it is set in my .emacs?

In my init.el file I have the following line (setq js2-basic-offset 2) The last line in my .init.el file is (add-hook 'after-init-hook (lambda () (message "Welcome home %s" (user-...
Startec's user avatar
  • 1,344
4 votes
2 answers
2k views

How do I insert code block header :var in exported code block in org-mode

GNU Emacs 26.0.50.2 (x86_64-pc-linux-gnu, GTK+ Version 3.18.9) of 2016-10-06 Org-mode version 8.3.5 (release_8.3.5-1131-g7eecb2 @ ~/.emacs.d/el-get/org-mode/lisp/) I have come to share my projects as ...
Sparx's user avatar
  • 1,111
4 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
  • 999
4 votes
2 answers
1k views

Should "custom" variables defined without defcustom be set via custom-set-variables or setq?

Should I use custom-set-variables (as opposed to setq) when setting a variable that returns non-nil for custom-variable-p but was not defined by defcustom? For example, echo-keystrokes is defined in ...
ivan's user avatar
  • 1,938
4 votes
1 answer
2k views

Fixing "reference/assignment to free variable" warning during compilation if variable is dynamically bounded

For: (defun my-ag/font-lock-extend-region () (save-excursion (goto-char font-lock-beg) (forward-line 2) (setq font-lock-beg (point)))) I've got: Warning: reference to free variable '...
gavenkoa's user avatar
  • 3,362
4 votes
1 answer
361 views

Controling what an org-link points to with variables

Let's say I have the following: #+NAME: output-directory /path/to/output/directory Results can be found [[file+emacs:/path/to/output/directory][here]]. Is there a way for me to have an org link to ...
Daniel's user avatar
  • 3,603
4 votes
2 answers
456 views

Why is TAGS table setting persistent?

I have in my startup init file a setting: (setq tags-table-list (list "~/linux/TAGS")) After using emacs and TAGS tables, I now want to change that to: (setq tags-table-list (list "~/trunk/TAGS")) ...
WilliamKF's user avatar
  • 383
4 votes
1 answer
245 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,792

1
2 3 4 5