emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* 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

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).