From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alan Schmitt Subject: babel question: how to detect the REPL has finished replying Date: Thu, 11 Feb 2016 16:02:54 +0100 Message-ID: Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48500) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTsls-000733-1C for emacs-orgmode@gnu.org; Thu, 11 Feb 2016 10:03:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aTslm-0001b9-DO for emacs-orgmode@gnu.org; Thu, 11 Feb 2016 10:03:03 -0500 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:42179) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aTslm-0001ar-6i for emacs-orgmode@gnu.org; Thu, 11 Feb 2016 10:02:58 -0500 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello, I=E2=80=99m tweaking ob-coq and I=E2=80=99m 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=3D (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=E2=80=99s replies may= be on several lines, and I have seen some of the output not being captured sometimes. I=E2=80=99m wondering if it is possible to make this more robust, for insta= nce 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 < =E2=96=A0 #+end example Could one try to match "Coq < $" on the buffer-substring, and only return when it matches? Thanks, Alan =2D-=20 OpenPGP Key ID : 040D0A3B4ED2E5C7 Monthly Athmospheric CO=E2=82=82 (2016-01, Mauna Loa Obs.): 402.52 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBCgAGBQJWvKKeAAoJEAQNCjtO0uXH/nMH/0Z4JHo3gUkYWjIuPLfxQ9t2 9Ah8xEPAUvTx1XrsSTiwE/etH0ZQO/LGlQNa9jixJkSkQFACdES5olt/A3XsvIAV xWzjzcQFMls7obGuo/YPrFJzeLzlt/ufyPeVzpVItbHoOx5Y9CbBh7f1b6qPMDch CpXOruBujsvbtbH1bXnZA1ke7r1tyb/yWPaOgCALfugSnuZ/N70+dBNqsHeCptrw tg9GLcXvCnpKlFgAE0EEY5A4sbHfYasCOOemna+5XHQbetAbSjzos1XrZj59hhLo cI9tXT9AHjDUDu5NKP+N3dP+WfShceyil1lf9fizcYaOtBbzSFVI7PyIFo3+rcE= =NlU3 -----END PGP SIGNATURE----- --=-=-=--