From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: [FEATURE] Make header argument :mkdirp yes work for other header arguments not just :tangle Date: Sun, 03 Mar 2019 09:03:53 +0100 Message-ID: <87k1hge652.fsf@nicolasgoaziou.fr> References: <87ftsk9w03.fsf@gmail.com> <87a7id3mf0.fsf@gmail.com> <8736o4h15m.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([209.51.188.92]:49769) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h0M6N-0004O8-LB for emacs-orgmode@gnu.org; Sun, 03 Mar 2019 03:04:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h0M6L-0005dg-Ml for emacs-orgmode@gnu.org; Sun, 03 Mar 2019 03:04:03 -0500 Received: from relay9-d.mail.gandi.net ([217.70.183.199]:43175) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h0M6I-0005Rr-8x for emacs-orgmode@gnu.org; Sun, 03 Mar 2019 03:03:59 -0500 In-Reply-To: <8736o4h15m.fsf@gmail.com> (stardiviner's message of "Sun, 03 Mar 2019 15:23:17 +0800") 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: stardiviner Cc: Org Mode Hello, stardiviner 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