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>
This commit is contained in:
Nicolas Goaziou 2018-10-06 08:56:05 +02:00
parent ed9bdfd220
commit 26ed66b233
3 changed files with 37 additions and 25 deletions

View File

@ -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.

View File

@ -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

View File

@ -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\" }")