Skip to content

Commit

Permalink
Merge pull request #17 from rails-to-cosmos/master
Browse files Browse the repository at this point in the history
Named results support
  • Loading branch information
astahlman committed Nov 15, 2017
2 parents fce7355 + d329090 commit 6099e94
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
8 changes: 6 additions & 2 deletions ob-async.el
Expand Up @@ -64,7 +64,7 @@ block."
(cond
;; If this function is not called as advice, do nothing
((not orig-fun)
(warn "ob-async-org-babel-execute-src-block is longer needed in org-ctrl-c-ctrl-c-hook")
(warn "ob-async-org-babel-execute-src-block is no longer needed in org-ctrl-c-ctrl-c-hook")
nil)
;; If there is no :async parameter, call the original function
((not (assoc :async (nth 2 (or info (org-babel-get-src-block-info)))))
Expand Down Expand Up @@ -144,7 +144,11 @@ block."
(goto-char (point-min))
(re-search-forward ,placeholder)
(org-backward-element)
(org-backward-element)
(let ((result-block (split-string (thing-at-point 'line t))))
;; If block has name, search by name
(-if-let (block-name (nth 1 result-block))
(org-babel-goto-named-src-block block-name)
(org-backward-element)))
(let ((file (cdr (assq :file ',params))))
;; If non-empty result and :file then write to :file.
(when file
Expand Down
38 changes: 36 additions & 2 deletions ob-async.org
Expand Up @@ -626,6 +626,30 @@ I'd also like to test this with ERT.
#+RESULTS:
: test-async-execute-named-block

*** Execute a named block with existing named results located anywhere in buffer

#+BEGIN_SRC emacs-lisp
(ert-deftest test-async-execute-named-block-with-results ()
"Test that we can asynchronously execute a named block when results are anywhere in buffer."
(let ((buffer-contents "Here's a shell source block:
,#+RESULTS: async-block

,#+NAME: async-block
,#+BEGIN_SRC sh :async
sleep 1s && echo 'Sorry for the wait.'
,#+END_SRC"))
(with-buffer-contents buffer-contents
(re-search-forward "#\\+NAME")
(org-ctrl-c-ctrl-c)
(should (placeholder-p (results-block-contents)))
(wait-for-seconds 5)
(should (string= "Sorry for the wait." (results-block-contents))))))
#+END_SRC

#+RESULTS:
: test-async-execute-named-block-with-results


*** TODO Execute a blocks with post-processing
*** TODO Silent output

Expand Down Expand Up @@ -796,7 +820,11 @@ ripped straight from the original source for
(goto-char (point-min))
(re-search-forward ,placeholder)
(org-backward-element)
(org-backward-element)
(let ((result-block (split-string (thing-at-point 'line t))))
;; If block has name, search by name
(-if-let (block-name (nth 1 result-block))
(org-babel-goto-named-src-block block-name)
(org-backward-element)))
(let ((file (cdr (assq :file ',params))))
;; If non-empty result and :file then write to :file.
(when file
Expand Down Expand Up @@ -886,7 +914,7 @@ we take =async= from elpa.
fi
- emacs --version
# Install Cask
- mkdir "$HOME"/bin # Cask is installed here
- mkdir -p "$HOME"/bin # Cask is installed here
- wget 'https://raw.githubusercontent.com/flycheck/emacs-travis/master/emacs-travis.mk'
- make -f emacs-travis.mk install_cask
# Use Cask to install dependencies
Expand All @@ -910,3 +938,9 @@ we take =async= from elpa.
#+BEGIN_SRC emacs-lisp :tangle ob-async.el
;;; ob-async.el ends here
#+END_SRC

* COMMENT Local Variables
# Local Variables:
# org-src-preserve-indentation: nil
# org-adapt-indentation: nil
# End:
16 changes: 16 additions & 0 deletions test/ob-async-test.el
Expand Up @@ -206,6 +206,22 @@ for row in x:
(wait-for-seconds 5)
(should (string= "Sorry for the wait." (results-block-contents))))))

(ert-deftest test-async-execute-named-block-with-results ()
"Test that we can asynchronously execute a named block when results are anywhere in buffer."
(let ((buffer-contents "Here's a shell source block:
#+RESULTS: async-block
#+NAME: async-block
#+BEGIN_SRC sh :async
sleep 1s && echo 'Sorry for the wait.'
#+END_SRC"))
(with-buffer-contents buffer-contents
(re-search-forward "#\\+NAME")
(org-ctrl-c-ctrl-c)
(should (placeholder-p (results-block-contents)))
(wait-for-seconds 5)
(should (string= "Sorry for the wait." (results-block-contents))))))

(ert-deftest test-async-execute-silent-block ()
"Test that we can insert results for a sh block that hasn't been executed yet"
:expected-result :failed
Expand Down

0 comments on commit 6099e94

Please sign in to comment.