Questions tagged [setq]
27 questions
22
votes
1 answer
What's the difference between setq and defvar
What is the difference between setq and defvar in Emacs lisp?
I see common lisp version of the same question at https://stackoverflow.com/questions/3855862. Are they same in Elisp?

Yasushi Shoji
- 2,151
- 15
- 35
18
votes
2 answers
Why do setq and set quote act differently on let-bound variables with lexical scope?
I had a bug in one of my extensions that eventually turned out to be caused by set not working as I expected:
;; -*- lexical-binding: t -*-
(let ((a nil))
(setq a t)
(print a))
(let ((a nil))
(set 'a t)
(print a))
when run with emacs -Q…

dshepherd
- 1,281
- 6
- 18
14
votes
3 answers
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 if there a way to achieve this using "/foo/bar" only…

Chillar Anand
- 4,042
- 1
- 23
- 52
9
votes
3 answers
When use setq or set '
I tried to find an answer to this seemingly simple question, but the swamp (internet) is a big place.
In the emacs init file in one case I use: (show-paren-mode t)
In another case I use:
(set 'inhibit-startup-message t) or (setq…

Daniel
- 201
- 2
- 7
7
votes
1 answer
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 ()
(setq x 10))
(defvar y 20)
(setq-x)
(message…

jue
- 4,476
- 8
- 20
7
votes
2 answers
init.el and trampling of custom-set-variables
My new init.el uses require to load various settings that I have organised into directories and files. This is an attempt to tame what was a very large and messy init.el and custom.el file. Also I ultimately hope to use org files to better…

Phil
- 533
- 4
- 17
6
votes
1 answer
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 a piece of code:
(setq x '(1 2 3 4)) ; define…

Philopolis
- 1,094
- 8
- 14
4
votes
1 answer
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. Here are the options I'm considering:
Just use…

Zoli
- 381
- 1
- 7
4
votes
2 answers
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 keyboard.c via defvar_lisp, but the following…

ivan
- 1,928
- 10
- 20
3
votes
2 answers
How to define a bundle of variable-and-function pairs?
I want to define a bundle of variable-and-function pairs, e.g.: vl/path-doc points to my often used path, and vl/open-path-doc is used for open it in dired-mode.
I tried this piece of code:
(setq vivo-work-directory "~/Workspace/vivo/")
(defvar…

Vivodo
- 133
- 5
2
votes
0 answers
why does the Iterator Yield A Different Value?
I tested two similar generators, and the result confused me.
This iterator yields values as I expected:
ELISP> (iter-defun f (x)
(setq x (iter-yield (1+ x)))
(setq x (iter-yield (* 2 x))))
f
ELISP> (progn
(setq x (f 1))
…

shynur
- 4,065
- 1
- 3
- 23
2
votes
1 answer
Cannot get a symbol's value for the first time when using `setq-default`
I can use setq-default to set a symbol's default value, as follows:
(with-temp-buffer
(make-local-variable 'bar)
(setq-default bar "xyz")
(symbol-value 'bar))
When I first executed the above code, I got an error:
Symbol’s value as variable…

Searene
- 479
- 2
- 14
1
vote
1 answer
Setting new values in `org-refile-target` not working
I'm trying to add a new file foo.org and delete an old bar.org from the org-refile-target variable. So doing
(setq org-refile-targets (quote (("~/foo.org" :maxlevel . 2))
should work by replacing the former
(setq org-refile-targets (quote…

Daniel
- 99
- 9
1
vote
1 answer
Backup a variable and store it back
I have problems to get into Lisp. I assume I miss the correct terms to search for.
So I try to "speak in Python".
#!/usr/bin/env python3
foo = 7
backuped_foo = foo
# temporary change the value of foo
foo = 323
# restore the original foo value
foo…

buhtz
- 679
- 4
- 22
1
vote
1 answer
Inconsistency in emacs' rules of scope?
I have always felt that emacs' rules of scope are a bit strange
and prone to contradictions. In fact I have even attempted to file
bug reports just to be told that my interpretation of the rules of scope
was wrong, which I always reluctantly…

Ruy
- 787
- 4
- 11