emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jack Kamm <jackkamm@gmail.com>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: emacs-orgmode@gnu.org, matt@excalamus.com, jeremiejuste@gmail.com
Subject: Re: [PATCH] Async sessions: Fix prompt removal regression in ob-R
Date: Sun, 20 Oct 2024 00:01:48 -0700	[thread overview]
Message-ID: <87ed4b45r7.fsf@gmail.com> (raw)
In-Reply-To: <87h698wml2.fsf@localhost>

[-- Attachment #1: Type: text/plain, Size: 1704 bytes --]

Ihor Radchenko <yantar92@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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0002-to-be-squashed-with-previous-commit.patch --]
[-- Type: text/x-patch, Size: 3486 bytes --]

From f155c878ffa9f7244bdae417b824ffa6c4d92742 Mon Sep 17 00:00:00 2001
From: Jack Kamm <jackkamm@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	other threads:[~2024-10-20  7:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-22 21:45 [PATCH] Async sessions: Fix prompt removal regression in ob-R Jack Kamm
2024-10-02 17:05 ` Ihor Radchenko
2024-10-15  7:03   ` Jack Kamm
2024-10-19  7:58     ` Ihor Radchenko
2024-10-20  7:01       ` Jack Kamm [this message]
2024-10-20  9:34         ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ed4b45r7.fsf@gmail.com \
    --to=jackkamm@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=jeremiejuste@gmail.com \
    --cc=matt@excalamus.com \
    --cc=yantar92@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).