Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use the current buffer in the finish function of async-start? #127

Closed
NightMachinery opened this issue Aug 5, 2020 · 4 comments

Comments

@NightMachinery
Copy link

NightMachinery commented Aug 5, 2020

I have a function that gets a link from the clipboard, gets its metadata, and outputs richly formatted markdown. I want to insert this rich link asynchronously: The user calls the insertion function, and then is free to do their own editing, and when the rich link is ready, it'll be inserted at the point the user initiated the call. I have tried the following, but I can't pass current-buffer to async lambdas at all:

(defun night/unt ()
  (interactive)
  (let* (
         (link (current-kill 0))
         (my-buffer (current-buffer))
         )
    (async-start (lambda () (let* (
                                   (cmd (concat "brishzr.dash " (shell-quote-argument (concat "ec " (shell-quote-argument link) " | inargsf unt"))))
                                   (text (shell-command-to-string cmd))
                                   )
                              text
                              ))
                 (lambda (text)
                   (message "name: %s my-buffer: %s string: %s" (buffer-name) my-buffer (buffer-string))
                   (with-current-buffer my-buffer (insert text))
                   (save-buffer)
                   ))))

fails with

error in process sentinel: async-handle-result: Invalid read syntax: "#"
error in process sentinel: Invalid read syntax: "#"
@f4nyc
Copy link

f4nyc commented Dec 8, 2020

Hi, I got the same problem, have u solve this or find another way out?

@thierryvolpiatto
Copy link
Collaborator

Use buffer-name instead of a buffer object with buffer syntax i.e #<buffer *scratch*>, same for your strings with properties, strip out the properties when passing strings to closures.

@f4nyc
Copy link

f4nyc commented Dec 9, 2020

Use buffer-name instead of a buffer object with buffer syntax i.e #<buffer *scratch*>, same for your strings with properties, strip out the properties when passing strings to closures.
Thanks for your nice helping!
And I got another question : how could I pass buffer to child process of async-start i.e inside START-FUNC ?
The only way I can figure out is saving the buffer to a temporary file and accessing it.

@thierryvolpiatto
Copy link
Collaborator

thierryvolpiatto commented Dec 9, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants