Skip to content

Commit 2333106

Browse files
gjsteinastahlman
authored andcommitted
Add list of languages for ob-async to ignore (#35)
I recently noticed an incompatibility between this and the ob-ipython package, which defines its own :async keyword (and keeps an open pipe to an ipython session running in the background). To remedy this, I have added an elisp variable ob-async-no-async-languages-alist here: for any languages included in this list, the original ctrl-c-ctrl-c function is run — as it is for src blocks that do not include the :async keyword. By default, the variable is set to nil, so that there are no changes to the default behavior of ob-ipython. I've also included a test to show this functionality in action. By setting ob-async-no-async-languages-alist to '("sh"), we can run one of the core tests, but expect that the code will finish before the check is run, circumventing the :async keyword. Let me know if something seems amiss, and I'm happy to update this. (...and thanks for writing this package; I use it all the time.)
1 parent 0fff2da commit 2333106

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

ob-async.el

+8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
(require 'async)
3939
(require 'dash)
4040

41+
(defvar ob-async-no-async-languages-alist nil
42+
"async is not used for languages listed here. Enables compatability for other languages, e.g. ipython, for which async functionality may be implemented separately.")
43+
4144
;;;###autoload
4245
(defalias 'org-babel-execute-src-block:async 'ob-async-org-babel-execute-src-block)
4346

@@ -70,6 +73,11 @@ block."
7073
;; If there is no :async parameter, call the original function
7174
((not (assoc :async (nth 2 (or info (org-babel-get-src-block-info)))))
7275
(funcall orig-fun arg info params))
76+
;; If the src block language is in the list of languages async is not to be
77+
;; used for, call the original function
78+
((member (nth 0 (or info (org-babel-get-src-block-info)))
79+
ob-async-no-async-languages-alist)
80+
(funcall orig-fun arg info params))
7381
;; Otherwise, perform asynchronous execution
7482
(t
7583
(let ((placeholder (ob-async--generate-uuid)))

test/ob-async-test.el

+14
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ See http://stackoverflow.com/questions/14698081/elisp-sleep-for-doesnt-block-whe
4848
(wait-for-seconds 5)
4949
(should (string= "Sorry for the wait." (results-block-contents))))))
5050

51+
52+
(ert-deftest test-async-ignore-lang-sh-block ()
53+
"Testing ignoring a language."
54+
(let ((buffer-contents "Here's a shell source block:
55+
56+
#+BEGIN_SRC sh :async
57+
sleep 1s && echo 'Sorry for the wait.'
58+
#+END_SRC")
59+
(ob-async-no-async-languages-alist '("sh")))
60+
(with-buffer-contents buffer-contents
61+
(org-babel-next-src-block)
62+
(org-ctrl-c-ctrl-c)
63+
(should (string= "Sorry for the wait." (results-block-contents))))))
64+
5165
(ert-deftest test-async-execute-existing-sh-block ()
5266
"Test that we can insert results for a sh block that has already been executed"
5367
(let ((buffer-contents "Here's a shell source block:

0 commit comments

Comments
 (0)