43 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 ...
Drew's user avatar
  • 76.4k
16 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 ...
genehack's user avatar
  • 471
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, ...
sds's user avatar
  • 5,958
11 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 ...
Basil's user avatar
  • 12.2k
10 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 ...
Tobias's user avatar
  • 32.8k
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-...
npostavs's user avatar
  • 9,083
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-...
Basil's user avatar
  • 12.2k
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 ...
Drew's user avatar
  • 76.4k
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/...
Toothrot's user avatar
  • 3,254
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 ...
db48x's user avatar
  • 16.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 ...
Gilles 'SO- stop being evil''s 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 ...
Marco Wahl's user avatar
  • 2,826
7 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.
wasamasa's user avatar
  • 22k
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 ...
scbagley's user avatar
  • 609
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 ...
Stefan's user avatar
  • 26.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 ...
npostavs's user avatar
  • 9,083
6 votes
Accepted

Fixing "reference/assignment to free variable" warning during compilation if variable is dynamically bounded

Assuming you are using lexical binding, if the variable is dynamic, then it must be defvar'd (to ensure that lexical binding cannot treat it otherwise). AFAIK it would be a bug to not use defvar. For ...
phils's user avatar
  • 49.7k
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 ...
Drew's user avatar
  • 76.4k
6 votes
Accepted

practical relevance of storing value and function into one symbol

Emacs Lisp is a Lisp 2, which means only just what you described: the same symbol can have separate values as (1) a variable and (2) a function. (We call only #1 the "value" of the symbol.) Some ...
Drew's user avatar
  • 76.4k
6 votes
Accepted

How do you pass a variable in to a lambda?

The following lisp code demonstrates how the value of a variable var can be injected into the lambda used as START-FUNC in (async-start START-FUNC &optional FINISH-FUNC). I changed the lambda ...
Tobias's user avatar
  • 32.8k
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 ...
NickD's user avatar
  • 28.2k
6 votes
Accepted

What type of variable binding is setq creating?

Quoth the docstring of special-variable-p: special-variable-p is a built-in function in `src/eval.c'. (special-variable-p SYMBOL) Probably introduced at or before Emacs version 24.1. Return non-...
Basil's user avatar
  • 12.2k
5 votes

How to store the variable value after Emacs was closed

desktop-save-mode will do this for you. It saves more than just the state of variables though, it also saves open buffers, window layouts and more. To explicitly save the value of a global variable ...
Jordon Biondo's user avatar
5 votes
Accepted

How do I insert code block header :var in exported code block in org-mode

Add Code to Org file expand-src-block #+NAME: expand-src-block #+BEGIN_SRC elisp :var block-name="" :var datum="" :var info="" :var lang="" :var body="" :exports none (save-excursion (org-...
Melioratus's user avatar
  • 4,564
5 votes
Accepted

elisp - simplify a stranger data structure

It's not an association list, strictly speaking, even though the name seems to say it is. An alist is a list of (key . value) dotted pairs. org-publish-project-alist is just a list of lists, where ...
NickD's user avatar
  • 28.2k
5 votes
Accepted

Controling what an org-link points to with variables

If you want to define the output directory in your org-file you can use customized link abbrevations as follows. #+LINK: my-output-dir file+emacs:/path/to/output/directory/ Results can be found [[my-...
Tobias's user avatar
  • 32.8k
5 votes
Accepted

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

What you're doing is correct. is there a way to do this without changing the current buffer, i.e. can I explicitly specify the buffer whose value I want to change? While there is nothing built in, ...
phils's user avatar
  • 49.7k
5 votes
Accepted

Set an Elisp var on the command line and read it in the init file

This doesn't work because command line options are processed after the init file. This allows the command line to refer to functions and variables defined or loaded in the init file, and allows the ...
xuchunyang's user avatar
  • 14.4k
5 votes

Where are these variables defined? - bytecomp Warnings

See the answer by Drew for a general description of compiler warnings pertaining to free variables. In your particular case, however, the culprit is the package oauth2.el, which for some reason is ...
Basil's user avatar
  • 12.2k
5 votes
Accepted

Setq doesn't work

When writing list or cons constants in source code there is actually a subtle difference between e. g. (cons 'first 'second) and '(first . second). The latter denotes a constant cons cell in your code,...
Oliver Scholz's user avatar

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