From f155c878ffa9f7244bdae417b824ffa6c4d92742 Mon Sep 17 00:00:00 2001 From: Jack Kamm 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