emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [FEATURE] Make header argument :mkdirp yes work for other header


From: stardiviner
Subject: Re: [O] [FEATURE] Make header argument :mkdirp yes work for other header arguments not just :tangle
Date: Sun, 03 Mar 2019 23:15:01 +0800
User-agent: mu4e 1.1.0; emacs 27.0.50

Nicolas Goaziou <address@hidden> writes:

> Hello,
>
> stardiviner <address@hidden> 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.
      

Attachment: 0001-ob-core.el-Make-mkdirp-work-for-dir-too.patch
Description: Text Data

>
> 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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]