[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] babel question: how to detect the REPL has finished replying
From: |
Alan Schmitt |
Subject: |
[O] babel question: how to detect the REPL has finished replying |
Date: |
Thu, 11 Feb 2016 16:02:54 +0100 |
User-agent: |
Gnus/5.130014 (Ma Gnus v0.14) Emacs/24.5 (darwin) |
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
signature.asc
Description: PGP signature
- [O] babel question: how to detect the REPL has finished replying,
Alan Schmitt <=