[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Async Python src block behavior with :dir header property
From: |
Ihor Radchenko |
Subject: |
Re: Async Python src block behavior with :dir header property |
Date: |
Sun, 04 Feb 2024 16:30:56 +0000 |
Jack Kamm <jackkamm@gmail.com> writes:
> I updated the patch for `org-babel-comint-async-filter' to follow the
> same approach, setting default-directory based on the session buffer's
> value rather than the :dir header arg.
Thanks!
Attaching the two patches combined with some fixed to my patch.
Please check if these two patches solve the discussed bug.
>From 66bbac4207d7132ebc9f91f60384809ae556c2ef Mon Sep 17 00:00:00 2001
Message-ID:
<66bbac4207d7132ebc9f91f60384809ae556c2ef.1707064153.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Sat, 3 Feb 2024 16:47:57 +0100
Subject: [PATCH 1/2] 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: 87mssi8ht2.fsf@gmail.com">https://orgmode.org/list/87mssi8ht2.fsf@gmail.com
---
lisp/ob-core.el | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 1de3af6ad..fd8d06c5d 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -840,14 +840,17 @@ (defun org-babel-execute-src-block (&optional arg info
params executor-type)
(dir (cdr (assq :dir params)))
(mkdirp (cdr (assq :mkdirp params)))
(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))))
+ (cond
+ ((not dir) default-directory)
+ ((when-let ((session (cdr (assq :session params))))
+ (when (org-babel-comint-buffer-livep session)
+ (buffer-local-value 'default-directory (get-buffer
session)))))
+ ((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 exec-start-time)
(unless (fboundp cmd)
--
2.43.0
>From e9765a146bf27e6769a2563862d52b0efb77eb2e Mon Sep 17 00:00:00 2001
Message-ID:
<e9765a146bf27e6769a2563862d52b0efb77eb2e.1707064153.git.yantar92@posteo.net>
In-Reply-To:
<66bbac4207d7132ebc9f91f60384809ae556c2ef.1707064153.git.yantar92@posteo.net>
References:
<66bbac4207d7132ebc9f91f60384809ae556c2ef.1707064153.git.yantar92@posteo.net>
From: Jack Kamm <jackkamm@gmail.com>
Date: Wed, 31 Jan 2024 20:06:00 -0800
Subject: [PATCH 2/2] ob-comint: Make file results from async sessions respect
:dir header
* lisp/ob-comint.el (org-babel-comint-async-filter): Set
default-directory before calling `org-babel-insert-result'
https://list.orgmode.org/875xz9o4nj.fsf@localhost/T/#t
---
lisp/ob-comint.el | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/lisp/ob-comint.el b/lisp/ob-comint.el
index 7d258ea0e..349524701 100644
--- a/lisp/ob-comint.el
+++ b/lisp/ob-comint.el
@@ -224,6 +224,8 @@ (defun org-babel-comint-async-filter (string)
(file-callback org-babel-comint-async-file-callback)
(combined-string (concat org-babel-comint-async-dangling string))
(new-dangling combined-string)
+ ;; Assumes comint filter called with session buffer current
+ (session-dir default-directory)
;; list of UUID's matched by `org-babel-comint-async-indicator'
uuid-list)
(with-temp-buffer
@@ -248,7 +250,8 @@ (defun org-babel-comint-async-filter (string)
(let* ((info (org-babel-get-src-block-info))
(params (nth 2 info))
(result-params
- (cdr (assq :result-params params))))
+ (cdr (assq :result-params params)))
+ (default-directory session-dir))
(org-babel-insert-result
(funcall file-callback
(nth
@@ -291,7 +294,8 @@ (defun org-babel-comint-async-filter (string)
(let* ((info (org-babel-get-src-block-info))
(params (nth 2 info))
(result-params
- (cdr (assq :result-params params))))
+ (cdr (assq :result-params params)))
+ (default-directory session-dir))
(org-babel-insert-result
res-str result-params info))
t))))
--
2.43.0
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
- Re: Async Python src block behavior with :dir header property, Nasser Alkmim, 2024/02/01
- Re: Async Python src block behavior with :dir header property, Ihor Radchenko, 2024/02/01
- Re: Async Python src block behavior with :dir header property, Jack Kamm, 2024/02/02
- Re: Async Python src block behavior with :dir header property, Ihor Radchenko, 2024/02/03
- Re: Async Python src block behavior with :dir header property, Jack Kamm, 2024/02/03
- Re: Async Python src block behavior with :dir header property,
Ihor Radchenko <=
- Re: Async Python src block behavior with :dir header property, Jack Kamm, 2024/02/04
- Re: Async Python src block behavior with :dir header property, Ihor Radchenko, 2024/02/05
- Re: Async Python src block behavior with :dir header property, Jack Kamm, 2024/02/06
- Re: Async Python src block behavior with :dir header property, Ihor Radchenko, 2024/02/06
- Re: Async Python src block behavior with :dir header property, Jack Kamm, 2024/02/07
- Re: Async Python src block behavior with :dir header property, Ihor Radchenko, 2024/02/08
- Re: Async Python src block behavior with :dir header property, Bruno Barbier, 2024/02/08
- Re: Async Python src block behavior with :dir header property, Jack Kamm, 2024/02/10
- Re: Async Python src block behavior with :dir header property, Ihor Radchenko, 2024/02/10
- Re: Async Python src block behavior with :dir header property, Nasser Alkmim, 2024/02/13