Questions tagged [let-binding]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
34 views

Check value of local variable assigned with let/let* editing org-export functions

On my way learning emacs and doing some first steps in elisp programming, I'm trying to adapt the LaTeX output of org-export. It's a lot learning by doing and that's a good thing since it improves my ...
lukeflo's user avatar
  • 195
0 votes
1 answer
37 views

let* equivalent for interactive

I'd like to call a series of completing-read prompts via interactive, where every prompt after the first takes the previous result as its only argument. (defun make-prompt () (completing-read "...
treeblah's user avatar
  • 123
0 votes
1 answer
29 views

How can I let-bind a variable to input read with `completing-read`?

How can I store the selected value in a let variable when using completing-read ? (let ( (selc '("Lower-Skeleton" "Upper-Skeleton")) ) (completing-read "Vista: " selc ...
Dilna's user avatar
  • 1
2 votes
1 answer
293 views

“named-let” bug?

The following code seems fine semantically: ;; -*- lexical-binding: nil; -*- (named-let f ((_ '(1))) (dolist (paren-1-paren _) (f ()))) Why does it throw an error? (Is this a bug? If so, I will ...
shynur's user avatar
  • 4,563
2 votes
1 answer
133 views

Enable Lexical Binding by Binding “lexical-binding” to t

(Please see what is letrec first.) The following code is obviously fine and self-explanatory: ;; -*- lexical-binding: t; -*- (setq post-self-insert-hook `(,@(when (boundp 'post-self-insert-hook) ...
shynur's user avatar
  • 4,563
0 votes
1 answer
49 views

"Symbol's value as variable is void: file-name" when using let

I want to create an Emacs lisp function which composes a path of a diary file which has the format <some directory>/t<timestamp>.org and determines whether or not such file exists. I ...
Franz Drollig's user avatar
0 votes
0 answers
23 views

Updating old customization code using deprecated lexical-let

Old code (lexical-let ((beg -1) (end -1) (prev-mid -1)) (defun forward-binary () (interactive) (if (/= prev-mid (point)) (setq beg -1 end -1) (setq beg prev-mid)) (if ...
ychaouche's user avatar
  • 207
0 votes
1 answer
81 views

Bring setq variable into a (let ...) context of a elisp function?

I have written a function snippet that copies a paragraph to the kill-ring. I try to collect different point positions and corresponding line numbers: bop - begin of paragraph blnum - line umber of ...
huckfinn's user avatar
  • 113
0 votes
2 answers
84 views

Any way to access a lexical let variable outside of the let?

I need to retrieve a local, lexical, runtime variable from a function, but I'm unable to modify the function to return it because it is from an external library. The variable I'm unable to reach is ...
sextrism's user avatar
2 votes
1 answer
60 views

`make-local-variable` Behaves Differently depending on Whether Variable is Special

Two examples (both are in the *scratch* buffer and under lexical scoping rule): _ (setq xx :default) (let ((xx :let)) (with-current-buffer (get-buffer-create "tmp") (make-local-...
shynur's user avatar
  • 4,563
3 votes
1 answer
115 views

Make a Variable Buffer-Local within a Let-Binding

12.11.2 Creating and Deleting Buffer-Local Bindings: Making a variable buffer-local within a let-binding for that variable does not work reliably, unless the buffer in which you do this is not ...
shynur's user avatar
  • 4,563
8 votes
3 answers
408 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) ...
shynur's user avatar
  • 4,563
0 votes
0 answers
11 views

ISO generic "call command interactively, interactively overriding global variables ..."

BRIEF: looking for an elisp package to make it easier and more to wrapperize calling interactive commands, temporarily overriding global variables as if by let. ---+ DETAIL: ISO = In Search Of. I ...
Krazy Glew's user avatar
0 votes
2 answers
113 views

How to set a variable name with a variable?

I want to do this. (let ((myvar "my/variable") (myval "Some Value")) (setq myvar myval)) The manual method is: (setq "my/variable" "Some Value") Here ...
ritchie's user avatar
  • 151
3 votes
1 answer
123 views

Warnings about malformed functions when using lexical-let

I have the following function: (defun filter-repl-show-after (line-num) "Show lines after LINE-NUM." (filter-repl--foreach-line (lexical-let ((line-num line-num)) (lambda () ...
Att Righ's user avatar
  • 745
0 votes
1 answer
34 views

Moving position of variable in a let clause

I have the following code and wonder whether I can define the variable brace-stxcode in the let* part rather than I currently do (make a new let). (let* ( (last-ppss-pos (point)) (ppss (...
Dilna's user avatar
  • 1
0 votes
2 answers
28 views

Avoiding code duplication with conditional code that uses let bindings

This is the procedural logic I want to program in Elisp: def my_func(): v1; v2; if (some_condition): v1 = 2 v2 = 3 else: v1 = 4 v2 = 5 foo(v1) ...
Gradient's user avatar
  • 211
2 votes
1 answer
324 views

Reliable lexical binding?

How does one reliably create a lexically bound/scoped variable? Consider the following: ;; -*- lexical-binding: t; -*- (let ((f load-file-name)) (defun foo () f)) Normally f would be lexically ...
Richard Hansen's user avatar
0 votes
0 answers
119 views

"let: Symbol's value as variable is void" when loading .dir-locals

I have the following .dir-locals: ((nil . ((eval . (let ((project-root-dir (expand-file-name (locate-dominating-file default-directory ".dir-locals.el")))) (defun tokenize-...
daedsidog's user avatar
  • 157
1 vote
1 answer
70 views

Using global variables inside functions using the `let` construct

Have the following code but want to use let in the function blink-cursor-timer-function. Have started doing the changes but do require some assistance with it. The variable names veak-indicator-...
Dilna's user avatar
  • 1
1 vote
1 answer
69 views

Why does let binding sometimes seem to fail to override a value?

In this example, the message isn't shown, but it's still logged (message-log-max is ignored). (let ((inhibit-message t) (message-log-max nil)) (hs-minor-mode)) The text Showing all blocks ... ...
ideasman42's user avatar
  • 8,546
0 votes
3 answers
178 views

How did `cl-flet` got circumvented?

I want to slightly alter the behavior of counsel-fzf by locally changing the definition of counsel-fzf-action, which activates in the end of the definition of the former. See the source code of ...
Student's user avatar
  • 225
4 votes
1 answer
68 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-...
John Kitchin's user avatar
  • 11.6k
1 vote
1 answer
296 views

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 ...
buhtz's user avatar
  • 709
0 votes
2 answers
108 views

lexically set referenced symbol of a symbol within let bind form

Is it possible to set a symbol that is the value of target symbol within the let bind form? because I am not setting a target symbol, I am not sure how to use let. I am doing this because I am passing ...
Joann Morris's user avatar
0 votes
2 answers
151 views

HTTP Error 400 returned when accessing MELPA package archive

I'm working on a VM running Centos 7 which ships with emacs 24.3. I wanted to install, use some newer packages requiring > 25.1 so I downloaded the source for emacs 25.2 and built it. When I try to ...
Frank P's user avatar
7 votes
1 answer
333 views

How to make sure no global variables have been created in a piece of lisp code?

I am writing some lisp code and I would like it not to mess with the global variables in the system. I am therefore being very careful to only use variables within the scope of the let special form. ...
Ruy's user avatar
  • 829
8 votes
2 answers
901 views

Is there any difference between '(let (var) ...)' and '(let ((var nil)) ...)'?

I've seen both (let (var) ...) and (let ((var nil)) ...) is there any difference between these statements?
ideasman42's user avatar
  • 8,546
0 votes
1 answer
91 views

Why I can't use `let` in this example?

I am learning Emacs lisp and wrote a function which takes as input a list of file name, and returns a list of numbers of each defun in a file (introduced in this tutorial) (lengths-list-file "/...
shpark's user avatar
  • 133
0 votes
1 answer
519 views

Identities between let/lambda/defun expressions and simplifying nested progn

I learned that a lambda and let works as if they already include a progn in their definition. That is (let ((x 1) (y 2) (z 3)) A B C) works as if it had a progn after binding the variables: (let ((x 1)...
hyiltiz's user avatar
  • 115
6 votes
1 answer
294 views

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 ...
Philopolis's user avatar
  • 1,124
4 votes
1 answer
1k views

Difference between pcase-let & cl-destructuring-bind?

I noticed both pcase-let and cl-destructuring-bind seem to perform the same operation. Is there any difference or reason to use one instead of the other? eg: (pcase-let ((`(,filename ,buf) (pop ...
ideasman42's user avatar
  • 8,546
5 votes
1 answer
129 views

Why does a let-bound huge list survive garbage collection after the let form?

Note that the following original test is errorneous and has been superseded by the EDITED version below. (progn (message "Before: %S" (memory-use-counts)) (let ((x (make-list 100000000 0))) (...
Tobias's user avatar
  • 32.8k
2 votes
0 answers
26 views

Is there a generalized setter for buffer-modified-p?

It is very simple to define a simple generalized setter for buffer-modified-p: (gv-define-simple-setter buffer-modified-p set-buffer-modified-p) That enables constructs like: (with-current-buffer "...
Tobias's user avatar
  • 32.8k
0 votes
1 answer
53 views

How to define a variable in a custom function?

I have a function for generating a new text file. The file is named automatically from date and time, following this format: yyyy-mm-dd--hh-mm-ss.txt. However, I also need my function to insert the ...
myotis's user avatar
  • 1,109
1 vote
1 answer
114 views

Local variable's state mutated across function calls [duplicate]

I was surprised to discover that a local variable can have it's state modified across function invocations. Consider the following example. (defun example-mutable () (let ((x '("the" "quick" "...
dpritch's user avatar
  • 435
3 votes
3 answers
895 views

How to avoid use of `lexical-let`

I have a macro that intends to creates a closure: ; -*- lexical-binding: t -*- (defmacro repro () (let ((kmap-sym (gensym "kmap-"))) `(let ((,kmap-sym (make-sparse-keymap))) (define-key ,...
erjoalgo's user avatar
  • 863
1 vote
1 answer
47 views

Calling locally defined function via function parameter

Interface, by example: (my-run-command '(my-append (3 6 8) (4 5))) Desired output: (3 6 8 4 5) Implementation, with bits missing: (defun my-run-command (command) (let ((my-append 'append)) [...
feklee's user avatar
  • 1,049
31 votes
2 answers
12k views

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

I've used let before, but never used let* what does let* ( let asterisk) mean in elisp? fyi this one was hard to google because of the asterisk.
american-ninja-warrior's user avatar
3 votes
2 answers
1k views

Emacs Lisp: let with while

I am trying to search backwards and find [ but skip all square brackets within strings. I came across (nth 3 (syntax-ppss)); but I can't figure out how to use it with let in the following code: (...
Arktik's user avatar
  • 952
2 votes
2 answers
1k views

How to let-bind multiple variables conditional on X?

Q: how can I let-bind multiple variables conditional on x? Assume that I have three variables, a, b, and c, that I want to let-bind conditional on some other x. How do I do that concisely and ...
Dan's user avatar
  • 32.7k
7 votes
1 answer
1k views

Define a function alias within a let binding?

How can I define an alias within a script with let-binding? I tried (let (b-s) (defalias 'b-s 'buffer-string)) But it doesn't work. I figured out to let-bind the variable where aliases as stored ...
Gabriele Nicolardi's user avatar
5 votes
2 answers
191 views

Is it possible to use let-binding for setting keys?

in LaTeX mode C-cC-f calls the tex-file function. I performed a litte tweak to that function and I wrote a tex-file-mod function. Now I'd like to call the tex-file-mode with the same key-binding ...
Gabriele Nicolardi's user avatar
1 vote
2 answers
232 views

Let bound face-attribute locally

How can I let-bound a face-attribute locally. E.g. I want to: (set-face-attribute 'query-replace nil :background "OrangeRed3") (perform-replace "bar" "foo" t t nil 1 nil (point-min) (point-max)) and ...
Gabriele Nicolardi's user avatar
0 votes
1 answer
35 views

Flagging or auto-correcting self-referential 'let' expressions

How do you catch the lisp programmer's error: "I typed let, but I really meant let* and wasted five to ten seconds for the nth time today!" I make this mistake all the time. Usually in a hurry or ...
ebpa's user avatar
  • 7,389
2 votes
1 answer
135 views

Why doesn't my keymap let-binding work?

I'm trying to define the keymap for a major mode but keep getting the error: Wrong type argument: keymapp. What am I doing wrong? (defun insert-text () (interactive) (let ((x (read-string "...
Jacek's user avatar
  • 35
2 votes
1 answer
148 views

What is bds in Emacs speak?

I am trying to learn Elisp and just found this line that I don't understand, in a package that I use to send code from buffer to a terminal: (let* ((region-active (region-active-p)) ;; The ...
Amelio Vazquez-Reina's user avatar
1 vote
0 answers
58 views

Why does end-of-line behave differently in --batch?

I have an elisp script that behaves differently between an interactive Emacs session and running Emacs with --batch. (defun call-fn-in-let (unused) (let (xx) (let (yy) (split-string "foo" ...
Wilfred Hughes's user avatar
1 vote
1 answer
117 views

Using replace-regexp-in-string without case folding

I'm trying to use replace-regexp-in-string (see function below) and I need to detect the boundary between a lower case and upper case character. Apparently let-binding case-fold-search to nil doesn't ...
Alexis Layton's user avatar
2 votes
2 answers
148 views

Increase the level of dynamic binding with backtick / comma

I have a favorite function that contains several levels of set-process-sentinel and lambda sentinels. I have been using lexical-let, but would like to see if it is possible to use dynamically bound ...
lawlist's user avatar
  • 18.9k