emacs-deferred
emacs-deferred copied to clipboard
lexical let-binding no scope of let variables in subsequent deferred async tasks
I followed the example in the documentation related to lexical binding: (let ((a (point))) (deferred:$ (deferred:wait 1000) (deferred:nextc it (lambda (x) (goto-char a) (insert "here!")))))
In Emacs 26.1 I did a evaluation on region with above code and I got an error like:
deferred error : (void-variable a)
Hey!
I faced a similar situation.
Here is a workaround:
(let ((a (point)))
(deferred:$
(deferred:wait 1000)
(deferred:nextc it
`(lambda (x)
(goto-char ,a)
(insert "here!")))))
The trick is that deferred:next
and deferred:nextc
also seem accept a quoted lambda as a expression.
Thanks! I got stuck here too. Never thought of using a quoted expression @p3r7
This got me in something I was working on! A function would behave differently if I evaluated the defun
from the scratch buffer versus in a setup file. I finally tracked it down to this deferred error. Evaluating from scratch worked fine, but in my setup files, I needed to use the quote. Thanks!