ob-core: Make :mkdirp work for :dir too

* lisp/ob-core.el (org-babel-execute-src-block): Make directory if
  ":dir path" does not exist when ":mkdirp yes" exist.

* doc/org-manual.org (Header arguments): Document it.

* testing/lisp/test-ob.el: Add a specific testing file for ob-core.el,
  and add a testing for ":mkdir yes" work with :dir header argument
  usage.
This commit is contained in:
stardiviner 2019-03-02 12:11:47 +08:00 committed by Nicolas Goaziou
parent 9d7b1ef8a9
commit 8b5941330b
4 changed files with 26 additions and 4 deletions

View File

@ -17484,9 +17484,10 @@ to source file(s).
location. Example: =:tangle FILENAME=.
#+cindex: @samp{mkdirp}, header argument
The =mkdirp= header argument creates parent directories for tangled
files if the directory does not exist. =yes= enables directory
creation and =no= inhibits directory creation.
The =mkdirp= header argument creates parent directories for =dir=
header argument specified path and tangled files if the directory does
not exist. =yes= enables directory creation and =no= inhibits
directory creation.
#+cindex: @samp{comments}, header argument
The =comments= header argument controls inserting comments into

View File

@ -157,6 +157,12 @@ A call of ~org-set-tags-command~ with prefix argument C-u C-u avoids
the fast tag selection interface and instead offers the plain
interface.
*** ~:mkdirp~ now supports create directory for ~:dir~ path
The ~:mkdirp~ header argument used to only work for ~:tangle~ tangle
files. Now ~:mkdirp~ works for ~:dir~ too. This is more convenient for
specify default directory and with ~:file~ header argument.
* Version 9.2
** Incompatible changes
*** Removal of OrgStruct mode mode and radio lists

View File

@ -677,8 +677,15 @@ block."
(replace-regexp-in-string
(org-src-coderef-regexp coderef) "" expand nil nil 1))))
(dir (cdr (assq :dir params)))
(mkdirp (cdr (assq :mkdirp params)))
(default-directory
(or (and dir (file-name-as-directory (expand-file-name dir)))
(or (and dir
(not (member mkdirp '("no" "nil" nil)))
(progn
(let ((d (file-name-as-directory
(expand-file-name dir))))
(make-directory d 'parents)
d)))
default-directory))
(cmd (intern (concat "org-babel-execute:" lang)))
result)

View File

@ -1607,6 +1607,14 @@ echo \"$data\"
(cdr (assq :file (nth 2 (org-babel-get-src-block-info t))))))
))
(ert-deftest test-ob-core/dir-mkdirp ()
(org-test-with-temp-text
"#+begin_src sh :mkdirp yes :dir \"data/code\"
pwd
#+end_src"
(org-babel-execute-src-block))
(should (file-directory-p "data/code")))
(ert-deftest test-ob/script-escape ()
;; Delimited lists of numbers
(should (equal '(1 2 3)