org-babel-execute-src-block: Force :dir according to live session

* lisp/ob-core.el (org-babel-execute-src-block): Force eval directory
to follow live session buffer, if any.  This is consistent with what
we promise in the manual section "16.4 Environment of a Code
Block">Choosing a working directory.

Link: https://orgmode.org/list/87mssi8ht2.fsf@gmail.com
This commit is contained in:
Ihor Radchenko 2024-02-03 16:47:57 +01:00
parent cbfe1354b3
commit 13d0f8bf8e
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 11 additions and 8 deletions

View File

@ -840,14 +840,17 @@ guess will be made."
(dir (cdr (assq :dir params))) (dir (cdr (assq :dir params)))
(mkdirp (cdr (assq :mkdirp params))) (mkdirp (cdr (assq :mkdirp params)))
(default-directory (default-directory
(cond (cond
((not dir) default-directory) ((not dir) default-directory)
((member mkdirp '("no" "nil" nil)) ((when-let ((session (cdr (assq :session params))))
(file-name-as-directory (expand-file-name dir))) (when (org-babel-comint-buffer-livep session)
(t (buffer-local-value 'default-directory (get-buffer session)))))
(let ((d (file-name-as-directory (expand-file-name dir)))) ((member mkdirp '("no" "nil" nil))
(make-directory d 'parents) (file-name-as-directory (expand-file-name dir)))
d)))) (t
(let ((d (file-name-as-directory (expand-file-name dir))))
(make-directory d 'parents)
d))))
(cmd (intern (concat "org-babel-execute:" lang))) (cmd (intern (concat "org-babel-execute:" lang)))
result exec-start-time) result exec-start-time)
(unless (fboundp cmd) (unless (fboundp cmd)