* [Proposal] Make header argument :mkdirp yes work for other header arguments not just :tangle @ 2019-02-19 5:40 Christopher M. Miles 2019-03-02 4:55 ` stardiviner 2019-03-03 4:32 ` [Proposal] Make header argument :mkdirp yes work for other header arguments not just :tangle stardiviner 0 siblings, 2 replies; 11+ messages in thread From: Christopher M. Miles @ 2019-02-19 5:40 UTC (permalink / raw) To: Org Mode I hope `:mkdirp` header argument can also work for other related header arguments like `:dir`, `:file` etc not just `:tangle`. Like following example. #+begin_src sh :mkdirp yes :dir "data/code/mkdirp/dir" :file "test" :results file link echo "hello" #+end_src Do you have any idea about this? -- [ stardiviner ] I try to make every word tell the meaning what I want to express. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Proposal] Make header argument :mkdirp yes work for other header arguments not just :tangle 2019-02-19 5:40 [Proposal] Make header argument :mkdirp yes work for other header arguments not just :tangle Christopher M. Miles @ 2019-03-02 4:55 ` stardiviner 2019-03-03 7:23 ` [FEATURE] " stardiviner 2019-03-03 4:32 ` [Proposal] Make header argument :mkdirp yes work for other header arguments not just :tangle stardiviner 1 sibling, 1 reply; 11+ messages in thread From: stardiviner @ 2019-03-02 4:55 UTC (permalink / raw) To: Org Mode [-- Attachment #1: Type: text/plain, Size: 501 bytes --] Christopher M. Miles <numbchild@gmail.com> writes: > I hope `:mkdirp` header argument can also work for other related header > arguments like `:dir`, `:file` etc not just `:tangle`. Like following > example. > > #+begin_src sh :mkdirp yes :dir "data/code/mkdirp/dir" :file "test" :results file link > echo "hello" > #+end_src > > Do you have any idea about this? I made a patch for make ~:mkdir~ support for ~:dir~ header argument. But I still got some issues. I added patch in attachment. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-ob-core.el-Make-mkdirp-work-for-dir-too.patch --] [-- Type: text/x-patch, Size: 4405 bytes --] From 708cc9a1fba5869941bcff0cefcaf47f64838ce3 Mon Sep 17 00:00:00 2001 From: stardiviner <numbchild@gmail.com> Date: Sat, 2 Mar 2019 12:11:47 +0800 Subject: [PATCH] ob-core.el: 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-manualo.rg (mkdirp): declare new change in manual. * etc/ORG-NEWS: declare changes in ORG-NEWS. * testing/lisp/test-ob-core.el: Add a specific testing file for ob-core.el, and add a testing for :mkdir yes work with :dir header argument usage. --- doc/org-manual.org | 7 ++++--- etc/ORG-NEWS | 6 ++++++ lisp/ob-core.el | 9 +++++++-- testing/lisp/test-ob-core.el | 30 ++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 testing/lisp/test-ob-core.el diff --git a/doc/org-manual.org b/doc/org-manual.org index 00e5e1072..30c797ad7 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -17476,9 +17476,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 057440a71..cd5e4d900 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 e6f0edba5..6baa11de4 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -678,8 +678,13 @@ block." (org-src-coderef-regexp coderef) "" expand nil nil 1)))) (dir (cdr (assq :dir params))) (default-directory - (or (and dir (file-name-as-directory (expand-file-name dir))) - default-directory)) + ;; Possibly create the parent directories for file. + (let ((mkdirp (cdr (assq :mkdirp params))) + (fnd (file-name-as-directory (expand-file-name dir)))) + (if (and (string= mkdirp "yes") fnd) + (make-directory fnd 'parents)) + (or (and dir (file-name-as-directory (expand-file-name dir))) + default-directory))) (cmd (intern (concat "org-babel-execute:" lang))) result) (unless (fboundp cmd) diff --git a/testing/lisp/test-ob-core.el b/testing/lisp/test-ob-core.el new file mode 100644 index 000000000..c601e44eb --- /dev/null +++ b/testing/lisp/test-ob-core.el @@ -0,0 +1,30 @@ +;;; test-ob-core.el --- tests for ob-core.el + +;; Copyright (c) 2018-2022 Free Software Foundation, Inc. +;; Authors: stardiviner + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. + +;;; Code: +(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")))) + +(provide 'test-ob-core) + +;;; test-ob-core.el ends here -- 2.21.0 [-- Attachment #3: Type: text/plain, Size: 10061 bytes --] I can't run through many org babel related tests. When I revert my patch in source code, and run test again, the failed tests all passed. So the problem is in my code, but I don't understand where's wrong. The ~let~ form suppose to return ~default-directory~ correctly. Even I run the single test with "test-dirty", It seems don't report fail or success status in output: Here is the command I run and the command output: #+begin_src sh :dir "~/Code/Emacs/org-mode" :async make BTEST_RE="test-org-core/dir-mkdirp" test-dirty 2>&1 | cat #+end_src #+RESULTS[<2019-03-02 12:24:25> 3e762f60ab3c3ec0550a29b8dbf8717707dec0e5]: #+begin_example install -m 755 -d /tmp/tmp-orgtest TMPDIR=/tmp/tmp-orgtest emacs -Q -batch --eval '(setq vc-handled-backends nil org-startup-folded nil)' --eval '(add-to-list '"'"'load-path (concat default-directory "lisp"))' --eval '(add-to-list '"'"'load-path (concat default-directory "testing"))' -l org-batch-test-init --eval '(setq org-batch-test t org-babel-load-languages (quote ( (awk . t) (C . t) (fortran . t) (maxima . t) (lilypond . t) (octave . t) (perl . t) (python . t) (vala . t) (emacs-lisp . t) (shell . t) (org . t))) org-test-select-re "test-org-core/dir-mkdirp" )' -l org-loaddefs.el -l cl -l testing/org-test.el -l ert -l org -l ox --eval '(org-test-run-batch-tests org-test-select-re)' Finding ID locations (1/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/agenda-file.org Finding ID locations (2/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/babel-dangerous.org Finding ID locations (3/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/babel.org Finding ID locations (4/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/include.org Finding ID locations (5/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/include2.org Finding ID locations (6/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/link-in-heading.org Finding ID locations (7/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/links.org Finding ID locations (8/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/macro-templates.org Finding ID locations (9/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/no-heading.org Finding ID locations (10/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/normal.org Finding ID locations (11/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/ob-C-test.org Finding ID locations (12/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/ob-awk-test.org Finding ID locations (13/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/ob-fortran-test.org Finding ID locations (14/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/ob-header-arg-defaults.org Finding ID locations (15/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/ob-lilypond-broken.org Finding ID locations (16/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/ob-lilypond-test.org Finding ID locations (17/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/ob-maxima-test.org Finding ID locations (18/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/ob-octave-test.org Finding ID locations (19/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/ob-screen-test.org Finding ID locations (20/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/ob-sed-test.org Finding ID locations (21/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/ob-shell-test.org Finding ID locations (22/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/org-exp.org Finding ID locations (23/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/property-inheritance.org Finding ID locations (24/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/setupfile.org Finding ID locations (25/25 files): /home/stardiviner/Code/Emacs/org-mode/testing/examples/setupfile3.org 25 unique files scanned for IDs Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-C.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-R.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-awk.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-clojure.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-core.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-emacs-lisp.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-eshell.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-exp.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-fortran.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-header-arg-defaults.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-lilypond.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-lob.el (source)... 0 source block added to Library of Babel Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-lua.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-maxima.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-octave.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-perl.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-plantuml.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-python.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-ruby.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-scheme.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-sed.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-shell.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-sqlite.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-table.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-tangle.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-vala.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-agenda.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-archive.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-attach-annex.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-attach.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-bbdb.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-capture.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-clock.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-colview.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-datetree.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-duration.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-element.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-feed.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-footnote.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-info.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-inlinetask.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-lint.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-list.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-macro.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-macs.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-num.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-pcomplete.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-protocol.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-src.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-table.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-tempo.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-timer.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ox-publish.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ox.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-property-inheritance.el (source)... selected tests: test-org-core/dir-mkdirp Running 0 tests (2019-03-02 12:24:25+0800, selector ‘"test-org-core/dir-mkdirp"’) Ran 0 tests, 0 results as expected (2019-03-02 12:24:25+0800, 0.000297 sec) make cleantest make[1]: Entering directory '/home/stardiviner/Code/Emacs/org-mode' rm -fr /tmp/tmp-orgtest || { \ find /tmp/tmp-orgtest -type d -exec chmod u+w {} + && \ rm -fr /tmp/tmp-orgtest ; \ } make[1]: Leaving directory '/home/stardiviner/Code/Emacs/org-mode' #+end_example -- [ stardiviner ] I try to make every word tell the meaning what I want to express. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* [FEATURE] Make header argument :mkdirp yes work for other header arguments not just :tangle 2019-03-02 4:55 ` stardiviner @ 2019-03-03 7:23 ` stardiviner 2019-03-03 8:03 ` Nicolas Goaziou 0 siblings, 1 reply; 11+ messages in thread From: stardiviner @ 2019-03-03 7:23 UTC (permalink / raw) To: Org Mode [-- Attachment #1: Type: text/plain, Size: 428 bytes --] I hope ~:mkdirp~ header argument can also work for other related header arguments like ~:dir~, ~:file~ etc not just ~:tangle~. Like following example. #+begin_src sh :mkdirp yes :dir "data/code/mkdirp/dir" :file "test" :results file link echo "hello" #+end_src So I added a simple patch to make it work. (I posted message before, but I forgot to update the subject which might be ignored, so I post a new one again.) [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-ob-core.el-Make-mkdirp-work-for-dir-too.patch --] [-- Type: text/x-patch, Size: 4340 bytes --] From 53103450181c86c5b5fe07e7d4222618f9d1d8f8 Mon Sep 17 00:00:00 2001 From: stardiviner <numbchild@gmail.com> Date: Sat, 2 Mar 2019 12:11:47 +0800 Subject: [PATCH] ob-core.el: 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-manualo.rg (mkdirp): declare new change in manual. * etc/ORG-NEWS: declare changes in ORG-NEWS. * testing/lisp/test-ob-core.el: Add a specific testing file for ob-core.el, and add a testing for :mkdir yes work with :dir header argument usage. --- doc/org-manual.org | 7 ++++--- etc/ORG-NEWS | 6 ++++++ lisp/ob-core.el | 7 ++++++- testing/lisp/test-ob-core.el | 30 ++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 testing/lisp/test-ob-core.el diff --git a/doc/org-manual.org b/doc/org-manual.org index 00e5e1072..30c797ad7 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -17476,9 +17476,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 057440a71..cd5e4d900 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 e6f0edba5..b2a5ee5cb 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -677,8 +677,13 @@ 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 + ;; Possibly create the parent directories for file. + (let (fnd (file-name-as-directory (expand-file-name dir))) + (if (and (string= mkdirp "yes") fnd) + (make-directory fnd 'parents)))) default-directory)) (cmd (intern (concat "org-babel-execute:" lang))) result) diff --git a/testing/lisp/test-ob-core.el b/testing/lisp/test-ob-core.el new file mode 100644 index 000000000..c601e44eb --- /dev/null +++ b/testing/lisp/test-ob-core.el @@ -0,0 +1,30 @@ +;;; test-ob-core.el --- tests for ob-core.el + +;; Copyright (c) 2018-2022 Free Software Foundation, Inc. +;; Authors: stardiviner + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. + +;;; Code: +(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")))) + +(provide 'test-ob-core) + +;;; test-ob-core.el ends here -- 2.21.0 [-- Attachment #3: Type: text/plain, Size: 247 bytes --] -- [ stardiviner ] I try to make every word tell the meaning what I want to express. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [FEATURE] Make header argument :mkdirp yes work for other header arguments not just :tangle 2019-03-03 7:23 ` [FEATURE] " stardiviner @ 2019-03-03 8:03 ` Nicolas Goaziou 2019-03-03 15:15 ` stardiviner 0 siblings, 1 reply; 11+ messages in thread From: Nicolas Goaziou @ 2019-03-03 8:03 UTC (permalink / raw) To: stardiviner; +Cc: Org Mode Hello, stardiviner <numbchild@gmail.com> writes: > I hope ~:mkdirp~ header argument can also work for other related header arguments > like ~:dir~, ~:file~ etc not just ~:tangle~. Like following example. > > #+begin_src sh :mkdirp yes :dir "data/code/mkdirp/dir" :file "test" :results file link > echo "hello" > #+end_src > > So I added a simple patch to make it work. Thank you. Some comments follow. > #+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. Please also support "t" and "nil", or, more generally, make "no" and "nil" equivalent, and anything else would be "t". > - (or (and dir (file-name-as-directory (expand-file-name dir))) > + (or (and dir > + ;; Possibly create the parent directories for file. > + (let (fnd (file-name-as-directory (expand-file-name dir))) > + (if (and (string= mkdirp "yes") fnd) > + (make-directory fnd 'parents)))) > +;;; test-ob-core.el --- tests for ob-core.el Tests are in "test-ob.el" file. You should add yours there instead of creating a new file. > +(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")))) Nitpick: `should' is better outside `org-test-with-temp-text'? Could you send an updated patch? Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [FEATURE] Make header argument :mkdirp yes work for other header arguments not just :tangle 2019-03-03 8:03 ` Nicolas Goaziou @ 2019-03-03 15:15 ` stardiviner 2019-03-04 22:21 ` Nicolas Goaziou 0 siblings, 1 reply; 11+ messages in thread From: stardiviner @ 2019-03-03 15:15 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 2147 bytes --] Nicolas Goaziou <mail@nicolasgoaziou.fr> writes: > Hello, > > stardiviner <numbchild@gmail.com> writes: > >> I hope ~:mkdirp~ header argument can also work for other related header arguments >> like ~:dir~, ~:file~ etc not just ~:tangle~. Like following example. >> >> #+begin_src sh :mkdirp yes :dir "data/code/mkdirp/dir" :file "test" :results file link >> echo "hello" >> #+end_src >> >> So I added a simple patch to make it work. > > Thank you. Some comments follow. > >> #+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. > > Please also support "t" and "nil", or, more generally, make "no" and > "nil" equivalent, and anything else would be "t". I use ~cond~ to handle this. Don't know whether have better. I can use ~if~ to exclusive on "no" and "nil". But it is not robust. > >> - (or (and dir (file-name-as-directory (expand-file-name dir))) >> + (or (and dir >> + ;; Possibly create the parent directories for file. >> + (let (fnd (file-name-as-directory (expand-file-name dir))) >> + (if (and (string= mkdirp "yes") fnd) >> + (make-directory fnd 'parents)))) > >> +;;; test-ob-core.el --- tests for ob-core.el > > Tests are in "test-ob.el" file. You should add yours there instead of > creating a new file. I though it is "test-ob-core.el", but have not found it. So I created a new one. :) > >> +(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")))) > > Nitpick: `should' is better outside `org-test-with-temp-text'? Updated. > > Could you send an updated patch? New patch in attachment. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-ob-core.el-Make-mkdirp-work-for-dir-too.patch --] [-- Type: text/x-patch, Size: 3663 bytes --] From aafdd41f7ae5f6218a2be890f58d45be443de4a9 Mon Sep 17 00:00:00 2001 From: stardiviner <numbchild@gmail.com> Date: Sat, 2 Mar 2019 12:11:47 +0800 Subject: [PATCH] ob-core.el: 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-manualo.rg (mkdirp): declare new change in manual. * etc/ORG-NEWS: declare changes in ORG-NEWS. * 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. --- doc/org-manual.org | 7 ++++--- etc/ORG-NEWS | 6 ++++++ lisp/ob-core.el | 9 ++++++++- 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 00e5e1072..30c797ad7 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -17476,9 +17476,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 057440a71..cd5e4d900 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 e6f0edba5..c2b629bab 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 + ;; Possibly create the parent directories for file. + (let ((fnd (file-name-as-directory (expand-file-name dir)))) + (cond + ((member mkdirp '("yes" "t")) (make-directory fnd 'parents)) + ((member mkdirp '("no" "nil")) nil) + (t (make-directory fnd 'parents))))) 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 427c11c6d..33d6ae8f7 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) -- 2.21.0 [-- Attachment #3: Type: text/plain, Size: 271 bytes --] > > Regards, Regards, -- [ stardiviner ] I try to make every word tell the meaning what I want to express. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [FEATURE] Make header argument :mkdirp yes work for other header arguments not just :tangle 2019-03-03 15:15 ` stardiviner @ 2019-03-04 22:21 ` Nicolas Goaziou 2019-03-05 5:13 ` stardiviner 2019-03-05 6:02 ` [Discuss] make :tangle header argument respect :dir could save info typing stardiviner 0 siblings, 2 replies; 11+ messages in thread From: Nicolas Goaziou @ 2019-03-04 22:21 UTC (permalink / raw) To: stardiviner; +Cc: Org Mode Hello, stardiviner <numbchild@gmail.com> writes: > New patch in attachment. Thank you. > From aafdd41f7ae5f6218a2be890f58d45be443de4a9 Mon Sep 17 00:00:00 2001 > From: stardiviner <numbchild@gmail.com> > Date: Sat, 2 Mar 2019 12:11:47 +0800 > Subject: [PATCH] ob-core.el: 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-manualo.rg (mkdirp): declare new change in manual. > > * etc/ORG-NEWS: declare changes in ORG-NEWS. No need to declare changes in changes file. This could end up in an infloop. > + (or (and dir > + ;; Possibly create the parent directories for file. > + (let ((fnd (file-name-as-directory (expand-file-name dir)))) > + (cond > + ((member mkdirp '("yes" "t")) (make-directory fnd 'parents)) > + ((member mkdirp '("no" "nil")) nil) > + (t (make-directory fnd 'parents))))) > default-directory)) I used: (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))) Do we need to make a case when dir is a remote? > +(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"))) > + I meant (should (org-test-with-temp-text "..." ... (file-directory-p "data/code"))) I applied your patch with the changes above. Regards, -- Nicolas Goaziou ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [FEATURE] Make header argument :mkdirp yes work for other header arguments not just :tangle 2019-03-04 22:21 ` Nicolas Goaziou @ 2019-03-05 5:13 ` stardiviner 2019-03-05 6:02 ` [Discuss] make :tangle header argument respect :dir could save info typing stardiviner 1 sibling, 0 replies; 11+ messages in thread From: stardiviner @ 2019-03-05 5:13 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: Org Mode Nicolas Goaziou <mail@nicolasgoaziou.fr> writes: > Hello, > > stardiviner <numbchild@gmail.com> writes: > >> New patch in attachment. > > Thank you. > >> From aafdd41f7ae5f6218a2be890f58d45be443de4a9 Mon Sep 17 00:00:00 2001 >> From: stardiviner <numbchild@gmail.com> >> Date: Sat, 2 Mar 2019 12:11:47 +0800 >> Subject: [PATCH] ob-core.el: 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-manualo.rg (mkdirp): declare new change in manual. >> >> * etc/ORG-NEWS: declare changes in ORG-NEWS. > > No need to declare changes in changes file. This could end up in an > infloop. > >> + (or (and dir >> + ;; Possibly create the parent directories for file. >> + (let ((fnd (file-name-as-directory (expand-file-name dir)))) >> + (cond >> + ((member mkdirp '("yes" "t")) (make-directory fnd 'parents)) >> + ((member mkdirp '("no" "nil")) nil) >> + (t (make-directory fnd 'parents))))) >> default-directory)) > > I used: > > (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))) I indeed have this thought of code too. But later changed still. I'm not good at Elisp yet, so hard to figure out which style code is better. I will keep learning. Thanks for your advice and teaching. > Do we need to make a case when dir is a remote? Absolutely, some people use remote dir very often, myself too. I use literate programming in Org Mode, so TRAMP etc support is very necessary. But I don't know how to support for remote dir. > >> +(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"))) >> + > > I meant (should (org-test-with-temp-text "..." ... (file-directory-p "data/code"))) Learned. I will check out to learn a bit of ert testing framework in recently. > > I applied your patch with the changes above. > > Regards, Thanks as always. -- [ stardiviner ] I try to make every word tell the meaning what I want to express. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 ^ permalink raw reply [flat|nested] 11+ messages in thread
* [Discuss] make :tangle header argument respect :dir could save info typing 2019-03-04 22:21 ` Nicolas Goaziou 2019-03-05 5:13 ` stardiviner @ 2019-03-05 6:02 ` stardiviner 2019-03-19 13:08 ` Sean O'Halpin 1 sibling, 1 reply; 11+ messages in thread From: stardiviner @ 2019-03-05 6:02 UTC (permalink / raw) To: Nicolas Goaziou; +Cc: Org Mode I realized one thing, the combination of ~:mkdir~, ~:dir~, and ~:tangle~ does not work good enough. Can make ~:tangle~ respect ~:dir~ too. WDYT? Here is an example: #+begin_src clojure :mkdirp yes :dir "data/code/clj-crawler-demo" :tangle "src/clj_crawler_demo/core.clj" (ns clj-crawler-demo.core (:require [clj-http.client :as http]) (:require [net.cgrand.enlive-html :as html])) (html/select (-> (http/get "https://www.baidu.com") :body html/html-snippet) [:div]) #+end_src Why need this? If ~:tangle~ respect ~:dir~, it will don't need the complete path to tangled file. And when the source block has other header argument need dir like ~:file~, this will make ~:tangle~ and other related header arguments shorter. If ~:tangle~ does not respect ~:dir~, user need to repeat the path: #+begin_src clojure :mkdirp yes :dir "data/code/clj-crawler-demo" :tangle "data/code/clj-crawler-demo/src/clj_crawler_demo/core.clj" (ns clj-crawler-demo.core (:require [clj-http.client :as http]) (:require [net.cgrand.enlive-html :as html])) (html/select (-> (http/get "https://www.baidu.com") :body html/html-snippet) [:div]) #+end_src This is long, I know there is ~#+headers:~ for source block. But reduce info would be better. I also consider the disadvantage of this change. Some user's existing source block might be broken. Let's level this change for discussion. -- [ stardiviner ] I try to make every word tell the meaning what I want to express. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Discuss] make :tangle header argument respect :dir could save info typing 2019-03-05 6:02 ` [Discuss] make :tangle header argument respect :dir could save info typing stardiviner @ 2019-03-19 13:08 ` Sean O'Halpin 2019-03-20 5:47 ` stardiviner 0 siblings, 1 reply; 11+ messages in thread From: Sean O'Halpin @ 2019-03-19 13:08 UTC (permalink / raw) To: numbchild; +Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 2147 bytes --] Hi, =:dir= specifies the directory for code execution, i.e. when you hit =C-c C-c= what is the environment in which the code is run? =:mkdirp= forces creation of the directory for tangle output, i.e. when you =org-babel-tangle= where do you put the output source code? They are quite separate concerns. Regards, Sean On Tue, 5 Mar 2019 at 06:03, stardiviner <numbchild@gmail.com> wrote: > > I realized one thing, the combination of ~:mkdir~, ~:dir~, and ~:tangle~ > does not work > good enough. Can make ~:tangle~ respect ~:dir~ too. WDYT? > > Here is an example: > > #+begin_src clojure :mkdirp yes :dir "data/code/clj-crawler-demo" :tangle > "src/clj_crawler_demo/core.clj" > (ns clj-crawler-demo.core > (:require [clj-http.client :as http]) > (:require [net.cgrand.enlive-html :as html])) > > (html/select > (-> (http/get "https://www.baidu.com") > :body > html/html-snippet) > [:div]) > #+end_src > > Why need this? If ~:tangle~ respect ~:dir~, it will don't need the > complete path to > tangled file. And when the source block has other header argument need dir > like > ~:file~, this will make ~:tangle~ and other related header arguments > shorter. > > If ~:tangle~ does not respect ~:dir~, user need to repeat the path: > > #+begin_src clojure :mkdirp yes :dir "data/code/clj-crawler-demo" :tangle > "data/code/clj-crawler-demo/src/clj_crawler_demo/core.clj" > (ns clj-crawler-demo.core > (:require [clj-http.client :as http]) > (:require [net.cgrand.enlive-html :as html])) > > (html/select > (-> (http/get "https://www.baidu.com") > :body > html/html-snippet) > [:div]) > #+end_src > > This is long, I know there is ~#+headers:~ for source block. But reduce > info would > be better. I also consider the disadvantage of this change. Some user's > existing > source block might be broken. > > Let's level this change for discussion. > > -- > [ stardiviner ] > I try to make every word tell the meaning what I want to express. > > Blog: https://stardiviner.github.io/ > IRC(freenode): stardiviner, Matrix: stardiviner > GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 > > > [-- Attachment #2: Type: text/html, Size: 3031 bytes --] ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Discuss] make :tangle header argument respect :dir could save info typing 2019-03-19 13:08 ` Sean O'Halpin @ 2019-03-20 5:47 ` stardiviner 0 siblings, 0 replies; 11+ messages in thread From: stardiviner @ 2019-03-20 5:47 UTC (permalink / raw) To: Sean O'Halpin; +Cc: Org Mode Sean O'Halpin <sean.ohalpin@gmail.com> writes: > Hi, > > =:dir= specifies the directory for code execution, i.e. when you hit =C-c C-c= what is the environment in which the code is run? I know currently it specify directory for code execution. I'm saying whether consider extend =:dir= semantic for tangling too. Because the header arguments could becoming very long if I repeat the sub-directory information in executing directory =:dir= and for =:tangle=. Like this: #+begin_src sh :mkdirp yes :dir "data/code/project-name-1" :tangle "data/code/project-name-1/src/project-name/main/App.java" .... #+end_src You see, The "=data/code/project-name-1=" path part is duplicate. And the header arguments is very long. Even though I can put header arguments in ~#+HEADERS:~ line of source block. But still duplicate info inputting, isn't it? > > =:mkdirp= forces creation of the directory for tangle output, i.e. when you =org-babel-tangle= where do you put the output source code? =:mkdirp= already support for auto force create of directory =:dir= now. > > They are quite separate concerns. > > Regards, > Sean > > On Tue, 5 Mar 2019 at 06:03, stardiviner <numbchild@gmail.com> wrote: > > I realized one thing, the combination of ~:mkdir~, ~:dir~, and ~:tangle~ does not work > good enough. Can make ~:tangle~ respect ~:dir~ too. WDYT? > > Here is an example: > > #+begin_src clojure :mkdirp yes :dir "data/code/clj-crawler-demo" :tangle "src/clj_crawler_demo/core.clj" > (ns clj-crawler-demo.core > (:require [clj-http.client :as http]) > (:require [net.cgrand.enlive-html :as html])) > > (html/select > (-> (http/get "https://www.baidu.com") > :body > html/html-snippet) > [:div]) > #+end_src > > Why need this? If ~:tangle~ respect ~:dir~, it will don't need the complete path to > tangled file. And when the source block has other header argument need dir like > ~:file~, this will make ~:tangle~ and other related header arguments shorter. > > If ~:tangle~ does not respect ~:dir~, user need to repeat the path: > > #+begin_src clojure :mkdirp yes :dir "data/code/clj-crawler-demo" :tangle "data/code/clj-crawler-demo/src/clj_crawler_demo/core.clj" > (ns clj-crawler-demo.core > (:require [clj-http.client :as http]) > (:require [net.cgrand.enlive-html :as html])) > > (html/select > (-> (http/get "https://www.baidu.com") > :body > html/html-snippet) > [:div]) > #+end_src > > This is long, I know there is ~#+headers:~ for source block. But reduce info would > be better. I also consider the disadvantage of this change. Some user's existing > source block might be broken. > > Let's level this change for discussion. > > -- > [ stardiviner ] > I try to make every word tell the meaning what I want to express. > > Blog: https://stardiviner.github.io/ > IRC(freenode): stardiviner, Matrix: stardiviner > GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 -- [ stardiviner ] I try to make every word tell the meaning what I want to express. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [Proposal] Make header argument :mkdirp yes work for other header arguments not just :tangle 2019-02-19 5:40 [Proposal] Make header argument :mkdirp yes work for other header arguments not just :tangle Christopher M. Miles 2019-03-02 4:55 ` stardiviner @ 2019-03-03 4:32 ` stardiviner 1 sibling, 0 replies; 11+ messages in thread From: stardiviner @ 2019-03-03 4:32 UTC (permalink / raw) To: Org Mode [-- Attachment #1: Type: text/plain, Size: 987 bytes --] Christopher M. Miles <numbchild@gmail.com> writes: > I hope `:mkdirp` header argument can also work for other related header > arguments like `:dir`, `:file` etc not just `:tangle`. Like following > example. > > #+begin_src sh :mkdirp yes :dir "data/code/mkdirp/dir" :file "test" :results file link > echo "hello" > #+end_src > > Do you have any idea about this? I figured out previous question now, it's because ~expand-file-name~ on ~nil~. #+begin_example Debugger entered--Lisp error: (wrong-type-argument stringp nil) expand-file-name(nil) (file-name-as-directory (expand-file-name dir)) (let ((mkdirp (cdr (assq :mkdirp params))) (fnd (file-name-as-directory (expand-file-name dir)))) (if (and (string= mkdirp "yes") fnd) (make-directory fnd 'parents)) (or (and dir (file-name-as-directory (expand-file-name dir))) default-directory))' #+end_example After fix, the patch works fine and passed all tests include my write corresponding test. [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: 0001-ob-core.el-Make-mkdirp-work-for-dir-too.patch --] [-- Type: text/x-patch, Size: 4340 bytes --] From 53103450181c86c5b5fe07e7d4222618f9d1d8f8 Mon Sep 17 00:00:00 2001 From: stardiviner <numbchild@gmail.com> Date: Sat, 2 Mar 2019 12:11:47 +0800 Subject: [PATCH] ob-core.el: 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-manualo.rg (mkdirp): declare new change in manual. * etc/ORG-NEWS: declare changes in ORG-NEWS. * testing/lisp/test-ob-core.el: Add a specific testing file for ob-core.el, and add a testing for :mkdir yes work with :dir header argument usage. --- doc/org-manual.org | 7 ++++--- etc/ORG-NEWS | 6 ++++++ lisp/ob-core.el | 7 ++++++- testing/lisp/test-ob-core.el | 30 ++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 testing/lisp/test-ob-core.el diff --git a/doc/org-manual.org b/doc/org-manual.org index 00e5e1072..30c797ad7 100644 --- a/doc/org-manual.org +++ b/doc/org-manual.org @@ -17476,9 +17476,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 057440a71..cd5e4d900 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 e6f0edba5..b2a5ee5cb 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -677,8 +677,13 @@ 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 + ;; Possibly create the parent directories for file. + (let (fnd (file-name-as-directory (expand-file-name dir))) + (if (and (string= mkdirp "yes") fnd) + (make-directory fnd 'parents)))) default-directory)) (cmd (intern (concat "org-babel-execute:" lang))) result) diff --git a/testing/lisp/test-ob-core.el b/testing/lisp/test-ob-core.el new file mode 100644 index 000000000..c601e44eb --- /dev/null +++ b/testing/lisp/test-ob-core.el @@ -0,0 +1,30 @@ +;;; test-ob-core.el --- tests for ob-core.el + +;; Copyright (c) 2018-2022 Free Software Foundation, Inc. +;; Authors: stardiviner + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see <http://www.gnu.org/licenses/>. + +;;; Code: +(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")))) + +(provide 'test-ob-core) + +;;; test-ob-core.el ends here -- 2.21.0 [-- Attachment #3: Type: text/plain, Size: 247 bytes --] -- [ stardiviner ] I try to make every word tell the meaning what I want to express. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 ^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2019-03-20 5:47 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2019-02-19 5:40 [Proposal] Make header argument :mkdirp yes work for other header arguments not just :tangle Christopher M. Miles 2019-03-02 4:55 ` stardiviner 2019-03-03 7:23 ` [FEATURE] " stardiviner 2019-03-03 8:03 ` Nicolas Goaziou 2019-03-03 15:15 ` stardiviner 2019-03-04 22:21 ` Nicolas Goaziou 2019-03-05 5:13 ` stardiviner 2019-03-05 6:02 ` [Discuss] make :tangle header argument respect :dir could save info typing stardiviner 2019-03-19 13:08 ` Sean O'Halpin 2019-03-20 5:47 ` stardiviner 2019-03-03 4:32 ` [Proposal] Make header argument :mkdirp yes work for other header arguments not just :tangle stardiviner
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).