skeeto / emacs-aio

async/await for Emacs Lisp
The Unlicense
218 stars 12 forks source link

Eager macro-expansion failure with `with-current-buffer` #26

Open Silex opened 2 years ago

Silex commented 2 years ago

Hello

In the following code, ok behaves properly but buggy creates an error.

(aio-defun ok ()
  (interactive)
  (let ((data (aio-await (aio-sleep 5 "yeah"))))
    (with-current-buffer "test"
      (insert data))))

(aio-defun buggy ()
  (interactive)
  (with-current-buffer "test"
    (insert (aio-await (aio-sleep 5 "yeah")))))

Eager macro-expansion failure: (error "special form (save-current-buffer (set-buffer \"test\") (insert (funcall (cps-internal-yield (aio-sleep 5 \"yeah\"))))) incorrect or not supported")

wakamenod commented 2 years ago

@Silex Hi, sorry if you may already know this or I'm totally wrong about this, but

aio is build upon the emacs's generator function, which does now seem work well with so-called special-forms

https://github.com/emacs-mirror/emacs/blob/master/lisp/emacs-lisp/generator.el#L472

How could you avoid this issue when you write your own package?? I'm also bumping into this problem again and again and it seems impossible for me to make UI related program with aio...

Silex commented 2 years ago

How could you avoid this issue when you write your own package??

Well the only way I found was to first gather data, then do the UI/whatever part (just like in my code example above).

wakamenod commented 2 years ago

@Silex Thanks for the comment!

Well the only way I found was to first gather data, then do the UI/whatever part (just like in my code example above).

I'm following this advice, and so far so good! :+1: