Skip to main content

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
8k 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.7k
34 votes
2 answers
13k 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.8k
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,492
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,878
11 votes
2 answers
4k 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,772
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
664 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,462
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 ...
atevm's user avatar
  • 948
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.7k
9 votes
1 answer
13k 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
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,707
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,973
7 votes
4 answers
384 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,661
7 votes
1 answer
2k 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's user avatar
  • 1,662
7 votes
1 answer
276 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,596
7 votes
2 answers
1k 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
503 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
300 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,661
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 ...
Toothrot's user avatar
  • 3,274
6 votes
2 answers
3k 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,905
6 votes
1 answer
333 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,134
6 votes
1 answer
694 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,069
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
307 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
1k 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
  • 441
5 votes
3 answers
872 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,948
5 votes
3 answers
280 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,378
5 votes
3 answers
407 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
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,121
5 votes
1 answer
452 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
  • 187
5 votes
1 answer
1k 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
2 answers
757 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
  • 985
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
1 answer
173 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
  • 33.1k
5 votes
1 answer
245 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
117 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
564 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
810 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
  • 983
4 votes
1 answer
99 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
156 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,354
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,948
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,462
4 votes
1 answer
389 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,653
4 votes
1 answer
1k views

change value of a defvar after loading package

I load a package that defines a list of radio stations with defvar (defvar default-list '((station1) (station2))) I want to redefine this list after loading the package (I am using require) because ...
Alejandro Erickson's user avatar
4 votes
2 answers
476 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
  • 393

1
2 3 4 5