Questions tagged [let-binding]
The let-binding tag has no usage guidance.
53
questions
0
votes
1
answer
28
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 ...
0
votes
0
answers
19
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 ...
0
votes
1
answer
42
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 ...
0
votes
2
answers
60
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 ...
2
votes
1
answer
56
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-...
3
votes
1
answer
78
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 ...
8
votes
3
answers
348
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)
...
0
votes
0
answers
10
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 ...
0
votes
2
answers
74
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 ...
3
votes
1
answer
71
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 ()
...
0
votes
1
answer
30
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 (...
0
votes
2
answers
26
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)
...
2
votes
1
answer
279
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 ...
0
votes
0
answers
90
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-...
1
vote
1
answer
46
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-...
1
vote
1
answer
53
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 ... ...
0
votes
3
answers
115
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 ...
4
votes
1
answer
64
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-...
1
vote
1
answer
238
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 ...
0
votes
2
answers
86
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 ...
0
votes
2
answers
127
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 ...
7
votes
1
answer
321
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.
...
8
votes
2
answers
888
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?
0
votes
1
answer
59
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 "/...
0
votes
1
answer
443
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)...
6
votes
1
answer
270
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 ...
3
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 ...
5
votes
1
answer
125
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)))
(...
2
votes
0
answers
24
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 "...
0
votes
1
answer
52
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 ...
1
vote
1
answer
107
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" "...
3
votes
3
answers
826
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 ,...
1
vote
1
answer
44
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))
[...
29
votes
2
answers
11k
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.
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:
(...
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 ...
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 ...
5
votes
2
answers
185
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 ...
1
vote
2
answers
225
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 ...
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 ...
2
votes
1
answer
131
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 "...
2
votes
1
answer
147
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 ...
1
vote
0
answers
55
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" ...
1
vote
1
answer
112
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 ...
2
votes
2
answers
144
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 ...
13
votes
1
answer
611
views
Why does a constant in `let` change with repeated calls? [duplicate]
Say we have such a foo function:
(defun foo (e)
(let ((lst '(a b c)))
(delq e lst)))
Then we use it in following way (sequentially evaluating one by one):
(foo 'c) ; => (a b)
(foo 'b) ; =&...
1
vote
0
answers
18
views
Factoring code into a let block [duplicate]
I'm following the instruction here to set the default font:
(add-to-list 'default-frame-alist '(font . "Monospace 10"))
(set-face-attribute 'default t :font "Monospace 10")
This works. To avoid the ...
5
votes
2
answers
362
views
Match against a variable with pcase
I'm trying to get pcase to match against a let-bound variable. However, I can't seem to get pcase to recognize the variable correctly.
See this minimal example:
(let ((a 1)) (pcase 2 (a 7))) => ...
3
votes
1
answer
133
views
Dynamic generation of varlist in a let form
Let's say I have a let form and I want to generate the varlist
dynamically from another function. Something like this:
(let ((x 1)
(y 2)
(the-dyn-gen))
body...
)
I have some local ...
9
votes
1
answer
3k
views
Override a function locally, but allow calls to the original function
The advice feature allows modifying the behavior of a function globally. An advice definition can make calls to the original function.
(defadvice foo
(around foo-bar activate compile)
"Always set ...