* babel question: how to detect the REPL has finished replying
@ 2016-02-11 15:02 Alan Schmitt
2016-02-11 19:57 ` Aaron Ecay
0 siblings, 1 reply; 3+ messages in thread
From: Alan Schmitt @ 2016-02-11 15:02 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1: Type: text/plain, Size: 1666 bytes --]
Hello,
I’m tweaking ob-coq and I’m trying to make it more robust. I have
a question about the way the code detects that the toplevel has finished
replying. Here is the current code (the function name has changed, but
the code is the same):
#+begin_src emacs-lisp
(defun org-babel-coq-run-one-phrase (phrase session)
(let ((pt (lambda ()
(marker-position
(process-mark (get-buffer-process (current-buffer)))))))
(org-babel-coq-clean-prompt
(org-babel-comint-in-buffer session
(let ((start (funcall pt)))
(with-temp-buffer
(insert phrase)
(comint-send-region (coq-proc) (point-min) (point-max))
(comint-send-string (coq-proc)
(if (string= (buffer-substring (- (point-max) 1) (point-max)) ".")
"\n"
".\n")))
(while (equal start (funcall pt)) (sleep-for 0.1))
(buffer-substring start (funcall pt)))))))
#+end_src
If I read this correctly, this code waits until the REPL has sent
something, and then it returns it. Unfortunately, Coq’s replies may be
on several lines, and I have seen some of the output not being captured
sometimes.
I’m wondering if it is possible to make this more robust, for instance
by detecting the prompt.
Here is an example of an interaction with the toplevel (the square
denotes the position of the cursor after the interaction):
#+begin_example
Coq < Check S.
S
: nat -> nat
Coq < ■
#+end example
Could one try to match "Coq < $" on the buffer-substring, and only
return when it matches?
Thanks,
Alan
--
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-01, Mauna Loa Obs.): 402.52
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: babel question: how to detect the REPL has finished replying
2016-02-11 15:02 babel question: how to detect the REPL has finished replying Alan Schmitt
@ 2016-02-11 19:57 ` Aaron Ecay
2016-02-15 13:01 ` Alan Schmitt
0 siblings, 1 reply; 3+ messages in thread
From: Aaron Ecay @ 2016-02-11 19:57 UTC (permalink / raw)
To: Alan Schmitt; +Cc: orgmode
Hi Alan,
Other backends send an unlikely string literal to the interpreter as the
last command, which will be echoed back verbatim. The code detects the
presence of this string in the output stream, and thus knows that the
interaction has finished. Check out the ‘org-babel-comint-with-output’
macro for the implementation.
(This is the usual function of the org-babel-coq-eoe variable that your
last patch deleted. It was probably cargo-culted in from another
backend and never properly implemented.)
Hope this is helpful,
--
Aaron Ecay
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: babel question: how to detect the REPL has finished replying
2016-02-11 19:57 ` Aaron Ecay
@ 2016-02-15 13:01 ` Alan Schmitt
0 siblings, 0 replies; 3+ messages in thread
From: Alan Schmitt @ 2016-02-15 13:01 UTC (permalink / raw)
To: orgmode
[-- Attachment #1: Type: text/plain, Size: 865 bytes --]
Hello Aaron,
On 2016-02-11 20:57, Aaron Ecay <aaronecay@gmail.com> writes:
> Hi Alan,
>
> Other backends send an unlikely string literal to the interpreter as the
> last command, which will be echoed back verbatim. The code detects the
> presence of this string in the output stream, and thus knows that the
> interaction has finished. Check out the ‘org-babel-comint-with-output’
> macro for the implementation.
>
> (This is the usual function of the org-babel-coq-eoe variable that your
> last patch deleted. It was probably cargo-culted in from another
> backend and never properly implemented.)
>
> Hope this is helpful,
It is, thank you for the suggestion. I’m going to look into how it’s
used in other languages.
Alan
--
OpenPGP Key ID : 040D0A3B4ED2E5C7
Monthly Athmospheric CO₂ (2016-01, Mauna Loa Obs.): 402.52
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-02-15 13:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-11 15:02 babel question: how to detect the REPL has finished replying Alan Schmitt
2016-02-11 19:57 ` Aaron Ecay
2016-02-15 13:01 ` Alan Schmitt
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).