From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: ocaml babel no longer works? Date: Wed, 13 Feb 2013 09:24:38 -0700 Message-ID: <87vc9wtc55.fsf@gmail.com> References: <876221i41q.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:46729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5f8q-0007CV-1W for emacs-orgmode@gnu.org; Wed, 13 Feb 2013 11:25:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U5f8i-0007zM-IY for emacs-orgmode@gnu.org; Wed, 13 Feb 2013 11:25:03 -0500 Received: from mail-pa0-f45.google.com ([209.85.220.45]:46897) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U5f8i-0007zA-BO for emacs-orgmode@gnu.org; Wed, 13 Feb 2013 11:24:56 -0500 Received: by mail-pa0-f45.google.com with SMTP id kl14so770544pab.18 for ; Wed, 13 Feb 2013 08:24:54 -0800 (PST) In-Reply-To: (Alan Schmitt's message of "Mon, 11 Feb 2013 22:23:09 +0100") 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: Alan Schmitt Cc: emacs-orgmode , Eric Schulte Alan Schmitt writes: > Hello, > > Eric Schulte writes: > >> Thanks for looking into this. I've applied a patch to ob-ocaml.el which >> should handle the two different tuareg execution functions. > > Thanks a lot. > > About the thing "getting stuck", I made some progress. My error was that > I did not add ";;" at the end of my ocaml phrase, which resulted in an > error in the toplevel: > > #+begin_quote > Objective Caml version 3.12.1 > > # let x = 2 in x > "org-babel-ocaml-eoe";; > Characters 13-14: > let x = 2 in x > ^ > Error: This expression is not a function; it cannot be applied > #+end_quote > > As you see, it's trying to apply the 'x' to the "oeo" thing. My guess is > that babel waits until seeing this special string before sending the > result back. By the way, this allows for some fun things, like this: > > #+BEGIN_SRC ocaml > let f x = () in f > #+END_SRC > > make babel stuck because the interpreter is in this state: > > #+begin_quote > # let f x = () in f > "org-babel-ocaml-eoe";; > - : unit = () > #+end_quote > > So I have a suggestion and two feature requests. > > The suggestion: instead of appending '"org-babel-ocaml-eoe";;' to the > code, how simply put ';;' (which will make sure everything is flushed) > then detect the toplevel is done by seeing the string '# ' at the > beginning of the line? Would there be an issue with the fact that this > line does not have a newline? If so, an alternative suggestion would be > to use the longer ';; "org-babel-ocaml-eoe";;' which makes sure the > phrase in the input won't interact with the marker. > You can customize the `org-babel-ocaml-eoe-output' and `org-babel-ocaml-eoe-indicator' variables so that they match the above. If this proves generally useful then I'd be happy to admit this change to the core. > > The first feature requests: if there is an error, could it be parsed? > (It probably always start with 'Error: '). Then the error could be put > in the result block, instead of waiting for the marker that will never > appear. > In `org-babel-execute:ocaml' first the `raw' variable is assigned to the raw output of the ocaml session, it is then parsed into the `clean' variable. Between these two steps it should be possible to check for an error string and possibly raise an error with `org-babel-eval-error-notify'. > > The second feature request: I want to use this for my ocaml lab classes > (I'm thinking of giving them an org file they have to complete by > writing the caml code). Could it be possible to have an option for the > full output of the compiler (and not just the result) to be printed? I > see it does it when it does not recognize the type of the output. So I > guess such an option would be applied to either > org-babel-ocaml-parse-output or the place where it's called. > I would think adding a ":results verbatim" header argument would suffice, but perhaps this is not the case. > > Thanks a lot for any suggestion as how to implement this. I think I see > how to do the second one (except I don't know how to add a configuration > variable to toggle it). I have no idea about the first one, though. > I hope these pointers are useful. I apologize for not being able to take a look at this myself, but I'm simply too busy. ob-ocaml could certainly use some attention, and I hope that if you do make improvements you consider contributing them back to Org-mode. In general other more mature language modes should serve as a guide to most implementation questions. Cheers, > > Alan -- Eric Schulte http://cs.unm.edu/~eschulte