From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex =?utf-8?Q?Benn=C3=A9e?= Subject: Re: Correct way to insert results Date: Thu, 14 May 2015 10:17:41 +0100 Message-ID: <87a8x7ldqi.fsf@linaro.org> References: <874mnjh6xq.fsf@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:44005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YspG5-0006CI-NN for emacs-orgmode@gnu.org; Thu, 14 May 2015 05:16:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YspG0-0005i7-St for emacs-orgmode@gnu.org; Thu, 14 May 2015 05:16:49 -0400 Received: from static.88-198-71-155.clients.your-server.de ([88.198.71.155]:34654 helo=socrates.bennee.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YspG0-0005h1-Mc for emacs-orgmode@gnu.org; Thu, 14 May 2015 05:16:44 -0400 Received: from localhost ([127.0.0.1] helo=zen.linaro.local) by socrates.bennee.com with esmtp (Exim 4.80) (envelope-from ) id 1YsqWf-0005wg-Ba for emacs-orgmode@gnu.org; Thu, 14 May 2015 12:38:01 +0200 In-reply-to: <874mnjh6xq.fsf@linaro.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Alex Bennée 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 > : # > > #+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 > : # > > Any idea how I can do this better? -- Alex Bennée