diff options
author | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-10-06 08:56:05 +0200 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2018-10-06 08:56:05 +0200 |
commit | 26ed66b23335eb389f1f2859e409f46f66279e15 (patch) | |
tree | 82652b2f56d18e13a5a374d518229f45de09860b | |
parent | ed9bdfd220b75233e5bae2ef39164d14624060fa (diff) | |
download | org-mode-26ed66b23335eb389f1f2859e409f46f66279e15.tar.gz |
ob: :file and :file-ext no longer imply :results file
* lisp/ob-core.el (org-babel-execute-src-block): ":results file" must
be specified in order to return a file.
(org-babel-merge-params): :file and :file-ext no longer imply :results
file.
* testing/lisp/test-ob.el (test-ob/indented-cached-org-bracket-link):
(test-ob/result-file-link-type-header-argument):
(test-ob/result-graphics-link-type-header-argument): Update tests.
Deducing the results from some other arguments is not obvious.
Moreover, it prevents users from setting, e.g., :file-ext, in a node
property, as every block would then create a file.
Reported-by: Alex Fenton <alex@pressure.to>
<http://lists.gnu.org/r/emacs-orgmode/2018-05/msg00469.html>
-rw-r--r-- | etc/ORG-NEWS | 6 | ||||
-rw-r--r-- | lisp/ob-core.el | 16 | ||||
-rw-r--r-- | testing/lisp/test-ob.el | 40 |
3 files changed, 37 insertions, 25 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index dbe3c13..aa1b774 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -14,6 +14,12 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org. ** Incompatible change +*** ~:file~ header argument no longer assume "file" ~:results~ + +The "file" ~:results~ value is now mandatory for a code block +returning a link to a file. The ~:file~ or ~:file-ext~ header +arguments no longer imply a "file" result is expected. + *** Plain numbers are hours in Column View mode See [[git:3367ac9457]] for details. diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 5a902d2..7b7b314 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -694,7 +694,8 @@ block." (not (listp r))) (list (list r)) r))) - (let ((file (cdr (assq :file params)))) + (let ((file (and (member "file" result-params) + (cdr (assq :file params))))) ;; If non-empty result and :file then write to :file. (when file ;; If `:results' are special types like `link' or @@ -2624,19 +2625,6 @@ parameters when merging lists." results (split-string (if (stringp value) value (eval value t)))))) - (`(,(or :file :file-ext) . ,value) - ;; `:file' and `:file-ext' are regular keywords but they - ;; imply a "file" `:results' and a "results" `:exports'. - (when value - (setq results - (funcall merge results-exclusive-groups results '("file"))) - (unless (or (member "both" exports) - (member "none" exports) - (member "code" exports)) - (setq exports - (funcall merge - exports-exclusive-groups exports '("results")))) - (push pair params))) (`(:exports . ,value) (setq exports (funcall merge exports-exclusive-groups diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 095f66a..28a7355 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -30,7 +30,7 @@ should still return the link." (org-test-with-temp-text " * Test - #+<point>BEGIN_SRC emacs-lisp :file test.txt :cache yes + #+<point>BEGIN_SRC emacs-lisp :results file :file test.txt :cache yes (message \"test\") #+END_SRC" ;; Execute twice as the first time creates the cache. @@ -1003,30 +1003,48 @@ trying to find the :END: marker." The file is just a link to `:file' value. Inhibit non-empty result write to `:file' value." (org-test-with-temp-text " +<point>#+begin_src shell :results value file link :file \"/tmp/test.txt\" +echo \"hello\" > /tmp/test.txt +echo \"test\" +#+end_src" + (org-babel-execute-src-block) + (should (search-forward "[[file:/tmp/test.txt]]" nil t)) + (should (with-temp-buffer + (insert-file-contents "/tmp/test.txt") + (string= "hello\n" (buffer-string))))) + ;; Without "link" output type, the result is not a file. + (should-not + (org-test-with-temp-text " <point>#+begin_src shell :results value link :file \"/tmp/test.txt\" echo \"hello\" > /tmp/test.txt echo \"test\" #+end_src" - (org-babel-execute-src-block) - (should (search-forward "[[file:/tmp/test.txt]]" nil nil)) - (should (with-temp-buffer - (insert-file-contents "/tmp/test.txt") - (string= "hello\n" (buffer-string)))))) + (org-babel-execute-src-block) + (search-forward "[[file:/tmp/test.txt]]" nil t)))) (ert-deftest test-ob/result-graphics-link-type-header-argument () "Ensure that the result is a link to a file. The file is just a link to `:file' value. Inhibit non-empty result write to `:file' value." (org-test-with-temp-text " +<point>#+begin_src shell :results value file graphics :file \"/tmp/test.txt\" +echo \"hello\" > /tmp/test.txt +echo \"test\" +#+end_src" + (org-babel-execute-src-block) + (should (search-forward "[[file:/tmp/test.txt]]" nil nil)) + (should (with-temp-buffer + (insert-file-contents "/tmp/test.txt") + (string= "hello\n" (buffer-string))))) + ;; Without "link" output type, the result is not a file. + (should-not + (org-test-with-temp-text " <point>#+begin_src shell :results value graphics :file \"/tmp/test.txt\" echo \"hello\" > /tmp/test.txt echo \"test\" #+end_src" - (org-babel-execute-src-block) - (should (search-forward "[[file:/tmp/test.txt]]" nil nil)) - (should (with-temp-buffer - (insert-file-contents "/tmp/test.txt") - (string= "hello\n" (buffer-string)))))) + (org-babel-execute-src-block) + (search-forward "[[file:/tmp/test.txt]]" nil t)))) (ert-deftest test-ob/inline-src_blk-preceded-punct-preceded-by-point () (let ((test-line ".src_emacs-lisp[ :results verbatim ]{ \"x\" }") |