emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Alex Bennée" <alex.bennee@linaro.org>
To: emacs-orgmode@gnu.org
Subject: Re: Correct way to insert results
Date: Thu, 14 May 2015 10:17:41 +0100	[thread overview]
Message-ID: <87a8x7ldqi.fsf@linaro.org> (raw)
In-Reply-To: <874mnjh6xq.fsf@linaro.org>


Alex Bennée <alex.bennee@linaro.org> writes:

> Hi,
>
> I'm working on adding async call functionality to org-babel blocks so I
> don't need to block my main Emacs for long running calculations. However
> I'm having problems with the insertion of the results once handled.

Ping? Is this something I should just write a custom routine for to
replace a token generated at the initial call?

> My
> code looks like this:
>
> (defmacro async-org-call (async-form)
>   "Expands `ASYNC-FORM' as an asynchronus org-bable function.
> If executed inside an org file will insert the results into the src
>   blocks results.  Otherwise the result will be echoed to the Message
>   buffer."
>
>   (let ((result-buffer (buffer-name))
>         (result-org-name (nth 4 (org-babel-get-src-block-info))))
>
>     `(async-start
>
>       ;; The result of the async-sexp is returned to the handler
>       ;; as result.
>       (lambda ()
>         ,(async-inject-variables "async-form")
>         (eval async-form))
>
>       ;; This code runs in the current emacs process.
>       (lambda (result)
>         (let ((buf ,result-buffer)
>               (org ,result-org-name))
>           
>           ;; Send the results somewhere
>           (if (and buf org)
>               (save-excursion
>                 (with-current-buffer buf
>                   (org-babel-goto-named-result org)
>                   (org-babel-insert-result (format "%s" result))))
>             (message (pp (format "async-result: %s" result)))))))))
>
> However the insert result seems to keep skipping the named result I'm
> aiming for (I was calling basic-async-test, the results end up after
> async-with-delay in a fresh RESULTS: drawer):
>
> ** Basic async
>
> #+name: basic-async-test
> #+begin_src emacs-lisp 
> (async-org-call (format "this is in inferior"))
> #+end_src
>
> #+RESULTS: basic-async-test
> : #<process emacs>
>
> #+name: async-with-delay
> #+begin_src emacs-lisp 
> (async-org-call ((sleep-for 3) (format "woken up")))
> #+end_src
>
> #+RESULTS:
> =this is in inferior
> =: this is in inferior
>
> #+RESULTS: async-with-delay
> : #<process emacs>
>
> Any idea how I can do this better?

-- 
Alex Bennée

      reply	other threads:[~2015-05-14  9:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-11  8:09 Correct way to insert results Alex Bennée
2015-05-14  9:17 ` Alex Bennée [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a8x7ldqi.fsf@linaro.org \
    --to=alex.bennee@linaro.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).