Questions tagged [let-binding]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
3
votes
3answers
267 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
1answer
29 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)) [...
9
votes
2answers
2k 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.
2
votes
2answers
355 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: (...
1
vote
2answers
316 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 ...
3
votes
1answer
385 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
2answers
106 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
2answers
90 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
1answer
27 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
1answer
72 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 "...
1
vote
1answer
132 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
0answers
43 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
1answer
63 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
2answers
100 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 ...
12
votes
1answer
438 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
0answers
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 ...
3
votes
2answers
139 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))) => ...
2
votes
1answer
101 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 ...
7
votes
1answer
1k 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 ...
12
votes
1answer
472 views

Emacs let-bound advice

I'd like to temporarily override a function in a piece of code. Take, for example, the following: (defun nadvice/load-quiet (args) (cl-destructuring-bind (file &optional noerror ...
1
vote
1answer
93 views

Cannot assign current buffer name in let statement

I'm trying to write some buffer switching function (which in itself may be a fool's errand, but I digress...) - and it looks a little like this (defun swk--quit-buffer (original-buffer) (switch-to-...
11
votes
2answers
2k views

Bind multiple values directly from list without binding the list itself

Is it possible to assign multiple return values directly to variables without going through a temporary variable in Emacs Lisp? For example, let's say I have a function that returns a list of two ...