Ihor Radchenko <yanta...@posteo.net> writes:

> I have one small nipick comment on the patch:
>
>>    (org-babel-comint-async-register
>>     session (current-buffer)
>>     "ob_comint_async_python_\\(start\\|end\\|file\\)_\\(.+\\)"
>> -   'org-babel-chomp 'org-babel-python-async-value-callback)
>> +   'org-babel-chomp 'org-babel-python-async-value-callback
>> +   t)
>
> Rather than `t', I'd use something more descriptive like 
> 'disable-prompt-filtering.

Is the attached patch what you had in mind? If so I will squash it with
the previous patch.

You can also see both commits together in my branch here:
https://github.com/jackkamm/org-mode/tree/2024-ob-r-async-prompt-bugfix2

> Looks reasonable in general.

Thanks, look forward to applying it.

But first -- note that the current patch is on top of bugfix. I had
mentioned this in my original email but want to double check if it's
OK. In particular, I'm not sure if it's acceptable for bugfix branch
anymore, now that I'm changing the function signature of
`org-babel-comint-async-register' (albeit in a backward-compatible way).

I had originally proposed bugfix since I use R's table() function a lot
(as in my original example), and it was causing me problems when I
belatedly upgraded my work machine to Org 9.7.  But if you prefer, I can
rebase onto main.

Another possibility would be to add a hardcoded check on bugfix to skip
the prompt filtering if the major-mode is R or Python; then on main,
revert the hard-coded check, and update the signature of
`org-babel-comint-async-register' to set it properly with a
variable. But not sure it's worth the hassle -- I might just switch to
using main branch on my work machine at that point.

>From f155c878ffa9f7244bdae417b824ffa6c4d92742 Mon Sep 17 00:00:00 2001
From: Jack Kamm <jackk...@gmail.com>
Date: Sat, 19 Oct 2024 23:46:03 -0700
Subject: [PATCH 2/2] to be squashed with previous commit

---
 lisp/ob-R.el      |  2 +-
 lisp/ob-comint.el | 21 +++++++++++++++------
 lisp/ob-python.el |  2 +-
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index 08d8227f0..5a8dfe22c 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -487,7 +487,7 @@ (defun ob-session-async-org-babel-R-evaluate-session
    "^\\(?:[>.+] \\)*\\[1\\] \"ob_comint_async_R_\\(start\\|end\\|file\\)_\\(.+\\)\"$"
    'org-babel-chomp
    'ob-session-async-R-value-callback
-   t)
+   'disable-prompt-filtering)
   (cl-case result-type
     (value
      (let ((tmp-file (org-babel-temp-file "R-")))
diff --git a/lisp/ob-comint.el b/lisp/ob-comint.el
index f37aa5264..ea42eaccd 100644
--- a/lisp/ob-comint.el
+++ b/lisp/ob-comint.el
@@ -360,21 +360,30 @@ (defun org-babel-comint-async-filter (string)
 (defun org-babel-comint-async-register
     (session-buffer org-buffer indicator-regexp
 		    chunk-callback file-callback
-                    &optional inhibit-prompt-removal)
+                    &optional prompt-handling)
   "Set local org-babel-comint-async variables in SESSION-BUFFER.
 ORG-BUFFER is added to `org-babel-comint-async-buffers' if not
 present.  `org-babel-comint-async-indicator',
 `org-babel-comint-async-chunk-callback', and
 `org-babel-comint-async-file-callback' are set to
 INDICATOR-REGEXP, CHUNK-CALLBACK, and FILE-CALLBACK respectively.
-If INHIBIT-PROMPT-REMOVAL,
-`org-babel-comint-async-remove-prompts-p' is set to `nil' to
-prevent prompt detection and removal from async output."
+PROMPT-HANDLING may be either of the symbols `filter-prompts', in
+which case prompts matching `comint-prompt-regexp' are filtered
+from output before it is passed to CHUNK-CALLBACK, or
+`disable-prompt-filtering', in which case this behavior is
+disabled.  For backward-compatibility, the default value of `nil'
+is equivalent to `filter-prompts'."
   (org-babel-comint-in-buffer session-buffer
     (setq org-babel-comint-async-indicator indicator-regexp
 	  org-babel-comint-async-chunk-callback chunk-callback
-	  org-babel-comint-async-file-callback file-callback
-          org-babel-comint-async-remove-prompts-p (not inhibit-prompt-removal))
+	  org-babel-comint-async-file-callback file-callback)
+    (setq org-babel-comint-async-remove-prompts-p
+          (let ((prompt-handling (or prompt-handling 'filter-prompts)))
+            (cond
+             ((eq prompt-handling 'disable-prompt-filtering) nil)
+             ((eq prompt-handling 'filter-prompts) t)
+             (t (error (format "Unrecognized prompt handling behavior %s"
+                               (symbol-name prompt-handling)))))))
     (unless (memq org-buffer org-babel-comint-async-buffers)
       (setq org-babel-comint-async-buffers
 	    (cons org-buffer org-babel-comint-async-buffers)))
diff --git a/lisp/ob-python.el b/lisp/ob-python.el
index 38ebe9147..f41f44dbd 100644
--- a/lisp/ob-python.el
+++ b/lisp/ob-python.el
@@ -539,7 +539,7 @@ (defun org-babel-python-async-evaluate-session
    session (current-buffer)
    "ob_comint_async_python_\\(start\\|end\\|file\\)_\\(.+\\)"
    'org-babel-chomp 'org-babel-python-async-value-callback
-   t)
+   'disable-prompt-filtering)
   (pcase result-type
     (`output
      (let ((uuid (org-id-uuid)))
-- 
2.46.2

Reply via email to