Browse Source

ob-core: Fix :dir when :mkdirp is not defined

* lisp/ob-core.el (org-babel-execute-src-block): Fix behaviour of
  ":dir path" when ":mkdirp" is not defined.
* testing/lisp/test-ob.el (test-ob-core/dir-mkdirp): Add a test case.

TINYCHANGE
Joaquín Aguirrezabalaga 5 months ago
parent
commit
4939b41750
2 changed files with 16 additions and 9 deletions
  1. 8 8
      lisp/ob-core.el
  2. 8 1
      testing/lisp/test-ob.el

+ 8 - 8
lisp/ob-core.el

@@ -679,14 +679,14 @@ block."
 		 (dir (cdr (assq :dir params)))
 		 (mkdirp (cdr (assq :mkdirp params)))
 		 (default-directory
-		   (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)))
-		       default-directory))
+		   (cond
+		    ((not dir) default-directory)
+		    ((member mkdirp '("no" "nil" nil))
+		     (file-name-as-directory (expand-file-name dir)))
+		    (t
+		     (let ((d (file-name-as-directory (expand-file-name dir))))
+		       (make-directory d 'parents)
+		       d))))
 		 (cmd (intern (concat "org-babel-execute:" lang)))
 		 result)
 	    (unless (fboundp cmd)

+ 8 - 1
testing/lisp/test-ob.el

@@ -1633,7 +1633,14 @@ t
      (org-babel-execute-src-block)
      (message default-directory)
      (prog1 (file-directory-p "data/code")
-       (delete-directory "data" t)))))
+       (delete-directory "data" t))))
+  (should
+   (equal "/tmp/test-dir-no-mkdirp/"
+	  (org-test-with-temp-text-in-file
+	      "#+begin_src emacs-lisp :dir /tmp/test-dir-no-mkdirp
+default-directory
+#+end_src"
+	    (org-babel-execute-src-block)))))
 
 (ert-deftest test-ob/script-escape ()
   ;; Delimited lists of numbers