From mboxrd@z Thu Jan 1 00:00:00 1970 From: stardiviner Subject: Re: [Proposal] Make header argument :mkdirp yes work for other header arguments not just :tangle Date: Sat, 02 Mar 2019 12:55:31 +0800 Message-ID: <87a7id3mf0.fsf@gmail.com> References: <87ftsk9w03.fsf@gmail.com> Reply-To: numbchild@gmail.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([209.51.188.92]:41175) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzwgg-0007bL-De for emacs-orgmode@gnu.org; Fri, 01 Mar 2019 23:55:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzwgX-0001RE-Ev for emacs-orgmode@gnu.org; Fri, 01 Mar 2019 23:55:44 -0500 Received: from [122.236.13.50] (port=59556 helo=dark.localdomain) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzwgS-0001Ds-Pt for emacs-orgmode@gnu.org; Fri, 01 Mar 2019 23:55:40 -0500 In-reply-to: <87ftsk9w03.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Org Mode --=-=-= Content-Type: text/plain Christopher M. Miles 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ob-core.el-Make-mkdirp-work-for-dir-too.patch >From 708cc9a1fba5869941bcff0cefcaf47f64838ce3 Mon Sep 17 00:00:00 2001 From: stardiviner 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 . + +;;; 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 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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 proble= m 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=3D"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=3D/tmp/tmp-orgtest emacs -Q -batch --eval '(setq vc-handled-backend= s nil org-startup-folded nil)' --eval '(add-to-list '"'"'load-path (concat= default-directory "lisp"))' --eval '(add-to-list '"'"'load-path (concat de= fault-directory "testing"))' -l org-batch-test-init --eval '(setq org-batc= h-test t org-babel-load-languages (quote ( (awk . t) (C . t) (fortran . t= ) (maxima . t) (lilypond . t) (octave . t) (perl . t) (python . t) (v= ala . t) (emacs-lisp . t) (shell . t) (org . t))) org-test-select-re "te= st-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/te= sting/examples/agenda-file.org Finding ID locations (2/25 files): /home/stardiviner/Code/Emacs/org-mode/te= sting/examples/babel-dangerous.org Finding ID locations (3/25 files): /home/stardiviner/Code/Emacs/org-mode/te= sting/examples/babel.org Finding ID locations (4/25 files): /home/stardiviner/Code/Emacs/org-mode/te= sting/examples/include.org Finding ID locations (5/25 files): /home/stardiviner/Code/Emacs/org-mode/te= sting/examples/include2.org Finding ID locations (6/25 files): /home/stardiviner/Code/Emacs/org-mode/te= sting/examples/link-in-heading.org Finding ID locations (7/25 files): /home/stardiviner/Code/Emacs/org-mode/te= sting/examples/links.org Finding ID locations (8/25 files): /home/stardiviner/Code/Emacs/org-mode/te= sting/examples/macro-templates.org Finding ID locations (9/25 files): /home/stardiviner/Code/Emacs/org-mode/te= sting/examples/no-heading.org Finding ID locations (10/25 files): /home/stardiviner/Code/Emacs/org-mode/t= esting/examples/normal.org Finding ID locations (11/25 files): /home/stardiviner/Code/Emacs/org-mode/t= esting/examples/ob-C-test.org Finding ID locations (12/25 files): /home/stardiviner/Code/Emacs/org-mode/t= esting/examples/ob-awk-test.org Finding ID locations (13/25 files): /home/stardiviner/Code/Emacs/org-mode/t= esting/examples/ob-fortran-test.org Finding ID locations (14/25 files): /home/stardiviner/Code/Emacs/org-mode/t= esting/examples/ob-header-arg-defaults.org Finding ID locations (15/25 files): /home/stardiviner/Code/Emacs/org-mode/t= esting/examples/ob-lilypond-broken.org Finding ID locations (16/25 files): /home/stardiviner/Code/Emacs/org-mode/t= esting/examples/ob-lilypond-test.org Finding ID locations (17/25 files): /home/stardiviner/Code/Emacs/org-mode/t= esting/examples/ob-maxima-test.org Finding ID locations (18/25 files): /home/stardiviner/Code/Emacs/org-mode/t= esting/examples/ob-octave-test.org Finding ID locations (19/25 files): /home/stardiviner/Code/Emacs/org-mode/t= esting/examples/ob-screen-test.org Finding ID locations (20/25 files): /home/stardiviner/Code/Emacs/org-mode/t= esting/examples/ob-sed-test.org Finding ID locations (21/25 files): /home/stardiviner/Code/Emacs/org-mode/t= esting/examples/ob-shell-test.org Finding ID locations (22/25 files): /home/stardiviner/Code/Emacs/org-mode/t= esting/examples/org-exp.org Finding ID locations (23/25 files): /home/stardiviner/Code/Emacs/org-mode/t= esting/examples/property-inheritance.org Finding ID locations (24/25 files): /home/stardiviner/Code/Emacs/org-mode/t= esting/examples/setupfile.org Finding ID locations (25/25 files): /home/stardiviner/Code/Emacs/org-mode/t= esting/examples/setupfile3.org 25 unique files scanned for IDs Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-C.el (so= urce)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-R.el (so= urce)... 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-li= sp.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-eshell.e= l (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-a= rg-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.e= l (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-ob-octave.e= l (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.e= l (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.e= l (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.e= l (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.e= l (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 (sour= ce)... 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.e= l (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-datetre= e.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-duratio= n.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-footnot= e.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-inlinet= ask.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.e= l (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-pcomple= te.el (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-protoco= l.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.e= l (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-tempo.e= l (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org-timer.e= l (source)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-org.el (sou= rce)... 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 (sour= ce)... Loading /home/stardiviner/Code/Emacs/org-mode/testing/lisp/test-property-in= heritance.el (source)... selected tests: test-org-core/dir-mkdirp Running 0 tests (2019-03-02 12:24:25+0800, selector =E2=80=98"test-org-core= /dir-mkdirp"=E2=80=99) 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 --=20 [ 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 --=-=-=--