Browse Source

ob-tangle: new :mkdirp header argument creates parent dirs of tangle targets

* lisp/ob-tangle.el (org-babel-tangle): New :mkdirp header argument
  optionally creates parent directories of tangle targets.
Eric Schulte 10 years ago
parent
commit
c07b5aed1e
1 changed files with 5 additions and 0 deletions
  1. 5 0
      lisp/ob-tangle.el

+ 5 - 0
lisp/ob-tangle.el

@@ -37,6 +37,7 @@
 (declare-function org-back-to-heading "org" (invisible-ok))
 (declare-function org-fill-template "org" (template alist))
 (declare-function org-babel-update-block-body "org" (new-body))
+(declare-function make-directory "files" (dir &optional parents))
 
 ;;;###autoload
 (defcustom org-babel-tangle-lang-exts
@@ -210,6 +211,10 @@ exported source code blocks by language."
                                     (if (and ext (string= "yes" tangle))
                                         (concat base-name "." ext) base-name))))
                   (when file-name
+		    ;; possibly create the parent directories for file
+		    (when ((lambda (m) (and m (not (string= m "no"))))
+			   (get-spec :mkdirp))
+		      (make-directory (file-name-directory file-name) 'parents))
                     ;; delete any old versions of file
                     (when (and (file-exists-p file-name)
                                (not (member file-name path-collector)))