37 votes
Accepted

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

The general issue is that you need x and y to be evaluated before they get inserted in somelist. The issue with the quoted list (with ' as reader syntax) is that quote is a special form that does not ...
user avatar
  • 31.1k
32 votes
Accepted

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

It means that when there is more than one binding the variables are bound sequentially, so that each can depend on the values bound to those that are bound before it, i.e., those that come before it ...
user avatar
  • 69.7k
28 votes
Accepted

Reset custom variable to default value programmatically

C-hig (elisp) Variable Definitions Internally, defcustom uses the symbol property standard-value to record the expression for the standard value, saved-value to record the value saved by the user ...
user avatar
  • 43.5k
21 votes
Accepted

Assigning same value to multiple variables?

setq returns the value, so you can just: (setq f-loc1 (setq f-loc2 "/foo/bar")) Of if you don't want to rely on that, then use: (setq f-loc1 "/foo/bar" f-loc2 f-loc1) Personally I would avoid the ...
user avatar
  • 24.3k
20 votes

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

Do not quote the cons cell, because quoted expressions are not evaluated. That's exactly why one quotes - to prevent evaluation. But that's not what you want, so don't. Instead use the form that ...
user avatar
  • 24.3k
16 votes

Reset custom variable to default value programmatically

Another, probably cleaner, way to reset the value of a variable: custom-reevaluate-setting is a compiled Lisp function in custom.el. (custom-reevaluate-setting SYMBOL) Reset the value of ...
user avatar
  • 1,723
15 votes
Accepted

Search through the values of all variables in Emacs

Does apropos-value do what you're looking for? (apropos-value PATTERN &optional DO-ALL) Show all symbols whose value’s printed representation matches PATTERN. PATTERN can be a word, a list of ...
user avatar
  • 461
13 votes

Assigning same value to multiple variables?

A macro to do what you want As an exercise of a sort: (defmacro setq-every (value &rest vars) "Set every variable from VARS to value VALUE." `(progn ,@(mapcar (lambda (x) (list 'setq x value)...
user avatar
  • 4,773
12 votes

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

Emacs comes with auth-source.el. I would not try to roll my own version of it. auth-source makes it easy to read from ~/.authinfo.gpg. Good programs will already support authinfo. A quick search ...
user avatar
  • 2,622
11 votes
Accepted

Scope in lambda

No, it shouldn't, if you use dynamic binding. Here are two choices (alternatives) that can help: Use lexical binding. Set variable lexical-binding for the file. Use dynamic binding (what you are ...
user avatar
  • 69.7k
11 votes
Accepted

Error void-variable on function name

Short Answer Replace func2 with #'func2: (defun func2 (arg) (if (listp arg) (mapcar #'func2 arg) arg)) Explanation Emacs Lisp is a lisp-2 (like Common Lisp), not lisp-1 (unlike, say, ...
user avatar
  • 5,487
10 votes
Accepted

Define a function alias within a let binding?

Definitions This topic confuses me sometimes, so let's start with some definitions, namely those of let: let is a special form in ‘C source code’. (let VARLIST BODY...) Bind variables according to ...
user avatar
  • 11.4k
9 votes

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

is there a way to do this without changing the current buffer No, but buffer-local-value is a Generalized Variable, so you can use setf to take care of the buffer switching for you: (setf (buffer-...
user avatar
  • 8,793
9 votes
Accepted

init.el - setq or defvar

If the sole purpose of defining my-trash-dir is to use its value to set the user option trash-directory, then you should just write (setq trash-directory (expand-file-name ".trash" user-emacs-...
user avatar
  • 11.4k
8 votes
Accepted

Why emacs can not see outer variable in lambda function?

Either enable lexical binding as a file-local variable in the file's first line, as described in the Elisp manual, node Using Lexical Binding, or just use this with dynamic binding (which is the ...
user avatar
  • 69.7k
8 votes
Accepted

Surprisingly persistent local variable

In case someone else runs into this, I had enabled TeX-auto-save, which saves settings to an auto/ directory and loads them when a file is revisited. https://www.gnu.org/software/auctex/manual/...
user avatar
  • 2,934
7 votes
Accepted

What does customize: Set for Current Session do?

Any change to the variable is equivalent here, so just M-x set-variable or (setq THE-VAR A-NEW-VALUE) is sufficient. The function called when you click Set for Current Session is custom-variable-set. ...
user avatar
  • 69.7k
7 votes

Assigning same value to multiple variables?

Since you can use and manipulate symbols in lisp, you could simply loop over a list of symbols and use set. (dolist (var '(foo bar baz)) (set var 10)) (mapc (lambda (var) (set var 10)) '(foo bar baz)...
user avatar
7 votes
Accepted

Control of garbage collection?

A live object is one that you can reach by following pointers from other live objects. Functions and variables are live because they are reachable from the global list of definitions. Setting a ...
user avatar
  • 11.8k
7 votes
Accepted

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

This variable is an alias for ‘js-indent-level’. That's the clue. If you're running Emacs ≥25 then js2-mode defines js2-basic-offset as an alias of the variable js-indent-level. At the point where ...
user avatar
7 votes

Per-host background colour

The path you have chosen introducing symbols to keep the colors requires you to convert the names you get by system-name to those symbols and evaluate them to get the color. You could achieve this by ...
user avatar
  • 2,646
7 votes

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

let* is like a recursive let meaning: (let* ((var1 VAL1) (var2 VAL2)) ...) is like (let ((var1 VAL1)) (let ((var2 VAL2)) ...)) Thereby the usage of capital letters for VAL1 and VAL2 ...
user avatar
  • 30.3k
6 votes

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

custom-set-variables is weird – I'm not 100% sure it can handle cases like this. You may try (eval `(custom-set-variables … (erc-password … ,(special-value) …) …), but that strikes me as a dirty hack-...
user avatar
  • 6,681
6 votes
Accepted

What happens if variable changed through customize is later changed by package maintainers?

The answer to your question is: Yes, you won't hear about the new and exciting modules. But you can write: (setq foo (remq 'c foo)) to remove c from foo. Or clone the repository and use standard ...
user avatar
  • 589
6 votes
Accepted

Why isn't face-remapping-alist permanent-local by default?

permanent-local is fundamentally a way to distinguish whether the variable's buffer-local value is really specific to this buffer or is specific to the mode currently in use in this buffer. Sadly, in ...
user avatar
  • 25.3k
6 votes
Accepted

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

I, as a package author, bind case-fold-search to nil in the outer let, and I want to use the default value (it might or might not be set by the user) in the with-temp-buffer, In this case I would ...
user avatar
  • 8,793
6 votes
Accepted

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

Use customize-set-variable or custom-set-variables, depending on just what you want/need. Both of those make use of any initialization or setter functions (and so on) with which the user option might ...
user avatar
  • 69.7k
6 votes
Accepted

Is there a way to spread a list like in Typescript or Golang?

You can use the backquote mechanism in combination with ,@ to splice the value of a variable into a list; or equivalently, use append: (setq variable '(1 2 3)) (1 2 3) (setq another-variable `(-2 -1 ...
user avatar
  • 19.9k
6 votes
Accepted

Symbol’s function definition is void

You define a local variable, then later call a non-existent function with the same name in the if: (if (helm-in-frame-p) Drop the surrounding parentheses and it should work again.
user avatar
  • 21.1k

Only top scored, non community-wiki answers of a minimum length are eligible