emacs-deferred icon indicating copy to clipboard operation
emacs-deferred copied to clipboard

lexical let-binding no scope of let variables in subsequent deferred async tasks

Open falkoHein opened this issue 5 years ago • 3 comments

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)

falkoHein avatar Mar 27 '19 18:03 falkoHein

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.

p3r7 avatar Jan 17 '20 15:01 p3r7

Thanks! I got stuck here too. Never thought of using a quoted expression @p3r7

mukundzare avatar Oct 13 '23 10:10 mukundzare

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!

Stwerp avatar Feb 06 '24 01:02 Stwerp