emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <schulte.eric@gmail.com>
To: Alan Schmitt <alan.schmitt@polytechnique.org>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: ocaml babel no longer works?
Date: Fri, 03 May 2013 09:57:08 -0600	[thread overview]
Message-ID: <871u9kytbe.fsf@gmail.com> (raw)
In-Reply-To: m2obct7ltz.fsf@polytechnique.org

Alan Schmitt <alan.schmitt@polytechnique.org> writes:

> Hello,
>
> I'm resurrecting this old thread as I've made some progress but I
> still have questions.
>
> Eric Schulte writes:
>
>>> 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.
>
> I did this very tiny change and it makes interacting with the top-level
> much nicer as one can forget putting ';;'. Here is a tiny diff, which I
> can commit if you agree with the change. (As I've added other changes
> while writing this email, I attach a proper patch as well for all the
> changes.)
>
> ,----
> | diff --git a/lisp/ob-ocaml.el b/lisp/ob-ocaml.el
> | index 6a83908..e5ad447 100644
> | --- a/lisp/ob-ocaml.el
> | +++ b/lisp/ob-ocaml.el
> | @@ -63,7 +63,7 @@
> |                   (session org-babel-ocaml-eoe-output t full-body)
> |                 (insert
> |                  (concat
> | -                 (org-babel-chomp full-body)"\n"org-babel-ocaml-eoe-indicator))
> | +                 (org-babel-chomp full-body)";;\n"org-babel-ocaml-eoe-indicator))
> |                 (tuareg-interactive-send-input)))
> |          (clean
> |           (car (let ((re (regexp-quote org-babel-ocaml-eoe-output)) out)
> `----
>
>>> 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.
>
> Unfortunately this does not seem to work. I've finally managed to
> understand how the code work, and here is a patch to solve this. The
> idea is that we do not trim the type information if verbatim is
> specified.
>
> ,----
> | @@ -74,10 +74,13 @@
> |                                          (progn (setq out t) nil))))
> |                                    (mapcar #'org-babel-trim (reverse raw))))))))
> |      (org-babel-reassemble-table
> | -     (let ((raw (org-babel-trim clean)))
> | -       (org-babel-result-cond (cdr (assoc :result-params params))
> | -        ;; strip type information from output
> | -        (if (string-match "= \\(.+\\)$" raw) (match-string 1 raw) raw)
> | +     (let ((raw (org-babel-trim clean))
> | +          (result-params (cdr (assoc :result-params params))))
> | +       (org-babel-result-cond result-params
> | +        ;; strip type information from output unless verbatim is specified
> | +        (if (and (not (member "verbatim" result-params))
> | +                 (string-match "= \\(.+\\)$" raw))
> | +            (match-string 1 raw) raw)
> |          (org-babel-ocaml-parse-output raw)))
> |       (org-babel-pick-name
> |        (cdr (assoc :colname-names params)) (cdr (assoc :colnames params)))
> `----
>
> Finally I found a bug with `org-babel-ocaml-parse-output': if the type
> returned by the toplevel was something like "int -> int = <fun>", then
> the matching against "int" would be triggered, and the conversion of
> "<fun>" to an integer would result in "0". To solve this, I made the
> regexp more precise as the value returned by the toplevel is:
> (identifier | -) : type = value
> where the identifier cannot have the ':' character.
>
> Here is the corresponding diff:
>
> ,----
> | @@ -113,7 +116,7 @@
> |  (defun org-babel-ocaml-parse-output (output)
> |    "Parse OUTPUT.
> |  OUTPUT is string output from an ocaml process."
> | -  (let ((regexp "%s = \\(.+\\)$"))
> | +  (let ((regexp "[^:]+ : %s = \\(.+\\)$"))
> |      (cond
> |       ((string-match (format regexp "string") output)
> |        (org-babel-read (match-string 1 output)))
> `----
>
> Hopefully this will be helpful.
>

Hi Alan,

I think each of these patches in an improvement over the existing
behavior.  Please do apply them all.

Thanks!

>
> Alan
>
>

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

  reply	other threads:[~2013-05-06 16:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-08 14:23 ocaml babel no longer works? Alan Schmitt
2013-02-09 12:06 ` Alan Schmitt
2013-02-09 21:09   ` Eric Schulte
2013-02-09 21:17     ` Sebastien Vauban
2013-02-11 21:23     ` Alan Schmitt
2013-02-13 16:24       ` Eric Schulte
2013-02-14  7:40         ` Alan Schmitt
2013-02-14 17:34           ` Eric Schulte
2013-05-02  9:49         ` Alan Schmitt
2013-05-03 15:57           ` Eric Schulte [this message]
2013-05-07  7:56             ` Alan Schmitt
2013-05-06  6:20           ` 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=871u9kytbe.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=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).