[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: comint-output-filter-functions and multi-line input
From: |
Ihor Radchenko |
Subject: |
Re: comint-output-filter-functions and multi-line input |
Date: |
Tue, 18 Oct 2022 05:28:39 +0000 |
miha@kamnitnik.top writes:
>> Is it possible to distinguish the actual script output, empty lines in
>> the actual script output, and the incomplete prompts?
>
> You could prepend your multiline command with a dummy
> 'echo multiline_starts_here' command have your
> 'comint-output-filter-functions' discard output that arrives before
> "multiline_starts_here".
For context, I am asking because I am trying to figure out how ob-shell
works in Org mode. My multiline command can be arbitrary bash script
containing multiple single- and multi-line commands. It is hard to
figure out which one is which.
> Or maybe inject something like 'oldps=$PS2; PS2=""' before the command
> and 'PS2=$oldps' after the command. But whether this works could depend
> on the shell, some shells might have something like $PS3 or $RPS1, for
> example.
> You could also accept-process-output after sending each individual line
> separately, but this depends on the user not customizing PS2="" in his
> bashrc.
But will accept-process-output correctly work with PS2=""?
Org uses the following black magic to detect that output is actually
produced:
(org-babel-comint-with-output
(session org-babel-sh-eoe-output t body)
(dolist (line (append (split-string (org-trim body) "\n")
(list org-babel-sh-eoe-indicator)))
(insert line)
(comint-send-input nil t)
(while (save-excursion
(goto-char comint-last-input-end)
(not (re-search-forward
comint-prompt-regexp nil t)))
(accept-process-output
(get-buffer-process (current-buffer))))))
Note that in addition to accept-process-output, we have to match against
comint-prompt-regexp. Not doing so sometimes lead to infinite loops.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
Re: comint-output-filter-functions and multi-line input, Stefan Monnier, 2022/10/17