astahlman / ob-async

Asynchronous src_block execution for org-babel
343 stars 32 forks source link

ob-synchro-org-babel-execute-src-block #39

Open nikadon opened 6 years ago

nikadon commented 6 years ago

Hi, thank you for a brilliant package. I have a feature request for a function ob-synchro-org-babel-execute-src-block that will ignore the :async t statements.

Reasoning is this. When dealing with individual source code blocks async is very useful but when using functions like org-babel-execute-to-point all code blocks should be executed one after another (synchronously). The new function (ob-synchro-org-babel-execute-src-block) can be incorporated in the definition of the org-babel-execute-to-point.

My usage case is iPython with some blocks that take few minutes to execute, while waiting I can still work on the org-file and prepare next code blocks for testing, and this is thanks to ob-async. When done with testing I want to execute all blocks one after another (synchronously). This can take hours, but I can start new Emacs process ;)

astahlman commented 5 years ago

Rather than creating a separate function, I'd prefer to support this by making ob-async-org-babel-execute-src-block respect the actual value of the :async header-arg (if supplied) instead of merely looking for the presence of the :async keyword in the list of header-args.

That way, you could do something like this:

#+BEGIN_SRC emacs-lisp
  (defun ob-async-use-async-p ()
    (if (bound-and-true-p ob-async-force-sync)
        "no"
      "yes"))

  (defun ob-async-toggle-force-sync ()
    (interactive)
    (setq-local ob-async-force-sync (not (bound-and-true-p ob-async-force-sync))))
#+END_SRC

And use it like this:

#+BEGIN_SRC sh :async (ob-async-use-async-p)
sleep 2 && echo "I'm synchronous"
#+END_SRC