diff options
author | stardiviner <numbchild@gmail.com> | 2019-03-02 12:11:47 +0800 |
---|---|---|
committer | Nicolas Goaziou <mail@nicolasgoaziou.fr> | 2019-03-04 22:25:48 +0100 |
commit | 8b5941330b4e67097ea527b7c950fc77fcfbf364 (patch) | |
tree | 284e7ec13a3d2ce637e6795754fe68ba79a28d26 | |
parent | 9d7b1ef8a95dde16f5904eb28806415df5d2b472 (diff) | |
download | org-mode-8b5941330b4e67097ea527b7c950fc77fcfbf364.tar.gz |
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.
-rw-r--r-- | doc/org-manual.org | 7 | ||||
-rw-r--r-- | etc/ORG-NEWS | 6 | ||||
-rw-r--r-- | lisp/ob-core.el | 9 | ||||
-rw-r--r-- | testing/lisp/test-ob.el | 8 |
4 files changed, 26 insertions, 4 deletions
diff --git a/doc/org-manual.org b/doc/org-manual.org index 911f611..f0a6759 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -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 diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 057440a..cd5e4d9 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -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 diff --git a/lisp/ob-core.el b/lisp/ob-core.el index e6f0edb..df96af8 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -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) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 427c11c..33d6ae8 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -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) |