From: Alan Schmitt <alan.schmitt@polytechnique.org>
To: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: babel question: how to detect the REPL has finished replying
Date: Thu, 11 Feb 2016 16:02:54 +0100 [thread overview]
Message-ID: <m2k2mbs31d.fsf@charm-ecran.irisa.fr> (raw)
[-- 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 --]
next reply other threads:[~2016-02-11 15:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-11 15:02 Alan Schmitt [this message]
2016-02-11 19:57 ` babel question: how to detect the REPL has finished replying Aaron Ecay
2016-02-15 13:01 ` Alan Schmitt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2k2mbs31d.fsf@charm-ecran.irisa.fr \
--to=alan.schmitt@polytechnique.org \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).