Questions tagged [defvar]
19 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
22
votes
1 answer
What does `setq-local` do, and when should I use it?
I'm not quite clear on all the variations of buffer-local variables, even
after reading all the doc and a bunch of postings here on SX.
Here's a summary of my understandings:
(defvar foo ..) declares a dynamic variable for the file. But the
variable…

Kevin
- 1,308
- 8
- 20
10
votes
3 answers
Why does defvar scoping work differently without an initvalue?
Suppose I have a file named elisp-defvar-test.el containing:
;;; elisp-defvar-test.el --- -*- lexical-binding: t -*-
(defvar my-dynamic-var)
(defun f1 (x)
"Should return X."
(let ((my-dynamic-var x))
(f2)))
(defun f2 ()
"Returns the…

Ryan C. Thompson
- 435
- 2
- 10
10
votes
4 answers
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 defvar-bound variables.
I don't want to call…

gavenkoa
- 3,352
- 19
- 36
8
votes
3 answers
Lambda in `defun` Captures the Lexical Environment, But in `let` It Doesn't
My example is simplified:
(defvar wtf 10)
(defun f (wtf)
(lambda ()
(cl-incf wtf)))
(setq f (f 20))
(setq g (let ((wtf 30))
(lambda ()
(cl-incf wtf))))
(list (funcall f)
(funcall g)
wtf)
;; ==> (21 11…

shynur
- 4,065
- 1
- 3
- 23
4
votes
1 answer
why is a let binding is ignored in compiled function?
I have this function which works perfectly in an uncompiled function. It should let-bind the variable bibtex-completion-bibliography to the result of (org-ref-find-bibliography).
(defun org-ref-valid-keys ()
"Return a list of valid bibtex…

John Kitchin
- 11,555
- 1
- 19
- 41
4
votes
1 answer
Test whether variable is defined, but not initialized
Q: How can I test (programmatically) whether a variable has been defined, but not initialized?
(defvar foo)
EXAMPLE:
(if (my-test foo)
(message "%s has been defined, but not initialized." foo)
(message "%s has been defined AND initialized."…

lawlist
- 18,826
- 5
- 37
- 118
3
votes
0 answers
Using a `defconst' or `defvar' While the Variable Has a Local Binding Sets the Global Binding?
The GNU Emacs Lisp Reference Manual, 12.5 Defining Global Variables:
If you use a defconst or defvar special form while the variable has a local binding (made with let, or a function argument), it sets the local binding rather than the global…

shynur
- 4,065
- 1
- 3
- 23
3
votes
1 answer
Use of defvar in straight.el's bootstrapping
The package straight.el requires the following bootstrapping code in your emacs config:
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
…

user242007
- 131
- 2
3
votes
1 answer
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 a lot of the stations are defunct.

Alejandro Erickson
- 696
- 5
- 17
2
votes
1 answer
How to use defvar with the symbol name in another variable?
I am trying to create a global variable which name is contained in another variable, using defvar:
(let ((var-name "my-test-var"))
;;(defvar (intern var-name) "some value")
(defvar (make-symbol var-name) "some value"))
This gives…

Håkon Hægland
- 3,608
- 1
- 20
- 51
1
vote
1 answer
What does defvar do in this code?
I know this may sound silly but what does defvar do in the code below? Does it define a variable that hold a capture template? or we say that the template is bound to the variable capture-template-contact?
I tried C-h f defvar for help but still…

Zoli
- 381
- 1
- 7
1
vote
1 answer
How to provide my own ediff-make-wide-display-function for ediff
For Ediff's wide display feature I like to use my own ediff-make-wide-display function. Ediff has a variable for this: ediff-make-wide-display-function. However when I write:
(defun my-ediff-make-wide-display ()
...)
(setq…

halloleo
- 1,215
- 9
- 23
1
vote
1 answer
Why are `defvars` in my macro ignored?
I want to use a macro to define variables. However, evaluating the macro does not define these vars. I seem to be missing something, but I can't find it. Here's the code:
(defmacro delve--build-cmp (name desc sort-fn-asc sort-fn-desc slot-fn…

Public Image Ltd.
- 129
- 7
1
vote
0 answers
Storing and Loading Non-Static/Multiple Configs
I'm writing an emacs wrapper to a set of scripts that require a lot of config settings to run.
These can be variously environment variables, command line parameters and so forth. They should be user visible and tweakable. They will store things…

Phil
- 533
- 4
- 17