org-babel-comint-with-output: Fix edge case for partial prompts
* lisp/ob-comint.el (org-babel-comint-with-output): Do not try to filter out prompts in `comint-output-filter-functions'. The prompts may arrive there arbitrarily - multiple prompts together, partial prompts, full prompts, etc. For example "ghci> " prompt may arrive as "gh" + "ci> " with second part still matching `comint-prompt-regexp'. As a result, if we keep using `comint-output-filter-functions', the split prompts may sometimes retain their initial part, littering the results. Now, we postpone filtering to after receiving the output, still making sure that agglomerated prompts gets filtered using a custom regexp derived from `comint-prompt-regexp'.
This commit is contained in:
parent
a8a516ba33
commit
866ed1a3c5
|
@ -81,28 +81,7 @@ or user `keyboard-quit' during execution of body."
|
||||||
(let* ((string-buffer "")
|
(let* ((string-buffer "")
|
||||||
(comint-output-filter-functions
|
(comint-output-filter-functions
|
||||||
(cons (lambda (text)
|
(cons (lambda (text)
|
||||||
(setq string-buffer
|
(setq string-buffer (concat string-buffer text)))
|
||||||
(concat
|
|
||||||
string-buffer
|
|
||||||
;; Upon concatenation, the prompt may no
|
|
||||||
;; longer match `comint-prompt-regexp'.
|
|
||||||
;; In particular, when the regexp has ^
|
|
||||||
;; and the output does not contain
|
|
||||||
;; trailing newline. Use more reliable
|
|
||||||
;; match to split the output later.
|
|
||||||
(replace-regexp-in-string
|
|
||||||
;; Sometimes, we get multiple agglomerated
|
|
||||||
;; prompts together in a single output:
|
|
||||||
;; "prompt prompt prompt output"
|
|
||||||
;; Remove them progressively, so that
|
|
||||||
;; possible "^" in the prompt regexp gets to
|
|
||||||
;; work as we remove the heading prompt
|
|
||||||
;; instance.
|
|
||||||
(if (string-prefix-p "^" comint-prompt-regexp)
|
|
||||||
(format "^\\(%s\\)+" (substring comint-prompt-regexp 1))
|
|
||||||
comint-prompt-regexp)
|
|
||||||
,org-babel-comint-prompt-separator
|
|
||||||
text))))
|
|
||||||
comint-output-filter-functions))
|
comint-output-filter-functions))
|
||||||
dangling-text)
|
dangling-text)
|
||||||
;; got located, and save dangling text
|
;; got located, and save dangling text
|
||||||
|
@ -117,21 +96,28 @@ or user `keyboard-quit' during execution of body."
|
||||||
(while (progn
|
(while (progn
|
||||||
(goto-char comint-last-input-end)
|
(goto-char comint-last-input-end)
|
||||||
(not (save-excursion
|
(not (save-excursion
|
||||||
(and (re-search-forward
|
(and (re-search-forward
|
||||||
(regexp-quote ,eoe-indicator) nil t)
|
(regexp-quote ,eoe-indicator) nil t)
|
||||||
(re-search-forward
|
(re-search-forward
|
||||||
comint-prompt-regexp nil t)))))
|
comint-prompt-regexp nil t)))))
|
||||||
(accept-process-output (get-buffer-process (current-buffer))))
|
(accept-process-output (get-buffer-process (current-buffer))))
|
||||||
;; replace cut dangling text
|
;; replace cut dangling text
|
||||||
(goto-char (process-mark (get-buffer-process (current-buffer))))
|
(goto-char (process-mark (get-buffer-process (current-buffer))))
|
||||||
(insert dangling-text)
|
(insert dangling-text)
|
||||||
|
|
||||||
;; Replace partially supplied input lines.
|
;; Filter out prompts.
|
||||||
;; This is needed when output filter spits partial lines that
|
|
||||||
;; do not include a full prompt at a time.
|
|
||||||
(setq string-buffer
|
(setq string-buffer
|
||||||
(replace-regexp-in-string
|
(replace-regexp-in-string
|
||||||
comint-prompt-regexp
|
;; Sometimes, we get multiple agglomerated
|
||||||
|
;; prompts together in a single output:
|
||||||
|
;; "prompt prompt prompt output"
|
||||||
|
;; Remove them progressively, so that
|
||||||
|
;; possible "^" in the prompt regexp gets to
|
||||||
|
;; work as we remove the heading prompt
|
||||||
|
;; instance.
|
||||||
|
(if (string-prefix-p "^" comint-prompt-regexp)
|
||||||
|
(format "^\\(%s\\)+" (substring comint-prompt-regexp 1))
|
||||||
|
comint-prompt-regexp)
|
||||||
,org-babel-comint-prompt-separator
|
,org-babel-comint-prompt-separator
|
||||||
string-buffer))
|
string-buffer))
|
||||||
;; remove echo'd FULL-BODY from input
|
;; remove echo'd FULL-BODY from input
|
||||||
|
|
Loading…
Reference in New Issue