Skip to main content

Questions tagged [defvar]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
9 votes
3 answers
528 views

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) ...
4 votes
0 answers
203 views

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 ...
0 votes
3 answers
49 views

Is the capture template bound to a variable?

I have the following defvar that declares a variable and gives it a string value. Notice, I used the word "gives" but I was wondering if "bind" would be the proper one to use. (...
1 vote
1 answer
121 views

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-...
0 votes
2 answers
189 views

Warning assigning variables

I'm rebuilding my emacs configuration, and trying to compile without warnings. I'm using also cask. I have this case: (require 'magit) ;; Enable a right limit of 70 chars for git logs (add-hook '...
1 vote
1 answer
34 views

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-...
1 vote
1 answer
139 views

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 (...
4 votes
1 answer
80 views

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-...
3 votes
1 answer
91 views

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/...
1 vote
0 answers
43 views

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 ...
10 votes
3 answers
397 views

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-...
23 votes
1 answer
10k views

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?
2 votes
1 answer
234 views

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 ...
0 votes
1 answer
102 views

Converting an expression to a string

I would like to add an alternative answer to the thread How do I force re-evaluation of a defvar? Before doing so, however, I would like to learn how to eliminate the single-quote to prevent ...
4 votes
1 answer
195 views

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) ...
11 votes
4 answers
685 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 ...
22 votes
1 answer
7k views

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 ..) ...
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 ...
0 votes
1 answer
46 views

Unexpected behavior when defining variable [duplicate]

I am trying to get the string value of a variable defined in a Python file and assign it to an elisp variable. The value is held in the variable org_file in a file config.py in the same directory as ...