org-babel-comint-with-output: Fix for edge case of `comint-prompt-regexp'
* lisp/ob-comint.el (org-babel-comint-with-output): Implement more universal algorithm catching agglomerated prompts. The new approach works for regexps that match ^, but not as the first char in the regexp string. * testing/lisp/test-ob-octave.el (ob-octave/session-multiline): Add new test. Reported-by: Paul Stansell <paulstansell@gmail.com> Link: https://orgmode.org/list/CAMJKaZwuTV-06pPz5nv87CNcoVcqCwFjEodubXTzXs15Q=OFug@mail.gmail.com
This commit is contained in:
parent
f6fc385ed0
commit
13e4ee7371
|
@ -76,7 +76,10 @@ or user `keyboard-quit' during execution of body."
|
||||||
(remove-echo (nth 2 meta))
|
(remove-echo (nth 2 meta))
|
||||||
(full-body (nth 3 meta))
|
(full-body (nth 3 meta))
|
||||||
(org-babel-comint-prompt-separator
|
(org-babel-comint-prompt-separator
|
||||||
"org-babel-comint-prompt-separator"))
|
;; We need newline in case if we do progressive replacement
|
||||||
|
;; of agglomerated comint prompts with `comint-prompt-regexp'
|
||||||
|
;; containing ^.
|
||||||
|
"org-babel-comint-prompt-separator\n"))
|
||||||
`(org-babel-comint-in-buffer ,buffer
|
`(org-babel-comint-in-buffer ,buffer
|
||||||
(let* ((string-buffer "")
|
(let* ((string-buffer "")
|
||||||
(comint-output-filter-functions
|
(comint-output-filter-functions
|
||||||
|
@ -106,21 +109,20 @@ or user `keyboard-quit' during execution of body."
|
||||||
(insert dangling-text)
|
(insert dangling-text)
|
||||||
|
|
||||||
;; Filter out prompts.
|
;; Filter out prompts.
|
||||||
(setq string-buffer
|
(while (string-match-p comint-prompt-regexp string-buffer)
|
||||||
(replace-regexp-in-string
|
(setq string-buffer
|
||||||
;; Sometimes, we get multiple agglomerated
|
(replace-regexp-in-string
|
||||||
;; prompts together in a single output:
|
;; Sometimes, we get multiple agglomerated
|
||||||
;; "prompt prompt prompt output"
|
;; prompts together in a single output:
|
||||||
;; Or even "<whitespace>prompt<whitespace>prompt ...>.
|
;; "prompt prompt prompt output"
|
||||||
;; Remove them progressively, so that
|
;; Or even "<whitespace>prompt<whitespace>prompt ...>.
|
||||||
;; possible "^" in the prompt regexp gets to
|
;; Remove them progressively, so that
|
||||||
;; work as we remove the heading prompt
|
;; possible "^" in the prompt regexp gets to
|
||||||
;; instance.
|
;; work as we remove the heading prompt
|
||||||
(if (string-prefix-p "^" comint-prompt-regexp)
|
;; instance.
|
||||||
(format "^\\([ \t]*%s\\)+" (substring comint-prompt-regexp 1))
|
(format "\\(?:%s\\)?\\(?:%s\\)[ \t]*" ,org-babel-comint-prompt-separator comint-prompt-regexp)
|
||||||
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
|
||||||
(when (and ,remove-echo ,full-body
|
(when (and ,remove-echo ,full-body
|
||||||
(string-match
|
(string-match
|
||||||
|
|
|
@ -122,5 +122,15 @@ sombrero;
|
||||||
(when (get-buffer "*Org-Babel Error Output*")
|
(when (get-buffer "*Org-Babel Error Output*")
|
||||||
(kill-buffer "*Org-Babel Error Output*")))))
|
(kill-buffer "*Org-Babel Error Output*")))))
|
||||||
|
|
||||||
|
(ert-deftest ob-octave/session-multiline ()
|
||||||
|
"Test multiline session input."
|
||||||
|
(dotimes (_ 3)
|
||||||
|
(org-test-with-temp-text
|
||||||
|
"#+begin_src octave :session oct2 :results output
|
||||||
|
x = 1;
|
||||||
|
x = 1;
|
||||||
|
x = 1
|
||||||
|
#+end_src"
|
||||||
|
(should (equal "x = 1" (org-babel-execute-src-block))))))
|
||||||
|
|
||||||
(provide 'test-ob-octave)
|
(provide 'test-ob-octave)
|
||||||
|
|
Loading…
Reference in New Issue