Re: [O] Patch for asynchronous export of ocaml code

2013-05-07 Thread Alan Schmitt

Eric Schulte writes:

 This looks great, please apply this patch.

Done.

Alan



Re: [O] Patch for asynchronous export of ocaml code

2013-05-07 Thread Alan Schmitt
Hello,

I just applied a small bugfix for this: it seems that the first time the
toplevel is started, something is mixed up in the buffers and the first
exported result end up in the toplevel buffer instead of the export
buffer. I put back the `save-window-excursion' around the code that
starts the toplevel to correct this.

Please let me know if it's again the custom to apply such tiny patch
without discussing it first on the list.

Best,

Alan



Re: [O] Patch for asynchronous export of ocaml code

2013-05-07 Thread Eric Schulte
Alan Schmitt alan.schm...@polytechnique.org writes:

 Hello,

 I just applied a small bugfix for this: it seems that the first time the
 toplevel is started, something is mixed up in the buffers and the first
 exported result end up in the toplevel buffer instead of the export
 buffer. I put back the `save-window-excursion' around the code that
 starts the toplevel to correct this.

 Please let me know if it's again the custom to apply such tiny patch
 without discussing it first on the list.


I think such small patches, especially patches which do not change the
externally visible behavior, e.g., bug fixes and refactoring, may safely
be applied w/o discussion.


 Best,

 Alan

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



Re: [O] Patch for asynchronous export of ocaml code

2013-05-06 Thread Alan Schmitt
Hello,

Can I apply this patch?

Thanks,

Alan

Alan Schmitt writes:

 Hello,

 It is not currently possible to asynchronously export the results of the
 evaluation an ocaml babel block because the evaluation needs to start a 
 toplevel
 and thus asks the user what program to run. This of course blocks the
 asynchronous export.

 The attached patch adds a custom variable to specify the name of the command
 to run, and directly calls the tuareg function that starts the toplevel given
 the command.



Re: [O] Patch for asynchronous export of ocaml code

2013-05-06 Thread Eric Schulte
This looks great, please apply this patch.

Thanks,

Alan Schmitt alan.schm...@polytechnique.org writes:

 Hello,

 It is not currently possible to asynchronously export the results of the
 evaluation an ocaml babel block because the evaluation needs to start a 
 toplevel
 and thus asks the user what program to run. This of course blocks the
 asynchronous export.

 The attached patch adds a custom variable to specify the name of the command
 to run, and directly calls the tuareg function that starts the toplevel given
 the command.

 For some context, here is the code that starts the caml session.

 #+BEGIN_SRC emacs-lisp
 (defvar tuareg-interactive-buffer-name)
 (defun org-babel-prep-session:ocaml (session params)
   Prepare SESSION according to the header arguments in PARAMS.
   (require 'tuareg)
   (let ((tuareg-interactive-buffer-name (if (and (not (string= session 
 none))
  (not (string= session 
 default))
  (stringp session))
 session
   tuareg-interactive-buffer-name)))
 (save-window-excursion
   (if (fboundp 'tuareg-run-caml) (tuareg-run-caml) (tuareg-run-ocaml))
   (get-buffer tuareg-interactive-buffer-name
 #+END_SRC

 And this is the code from tuareg that is run.

 #+BEGIN_SRC emacs-lisp
 ;;;###autoload
 (defun tuareg-run-ocaml ()
   Run an OCaml toplevel process. I/O via buffer `*ocaml-toplevel*'.
   (interactive)
   (tuareg-run-process-if-needed)
   (display-buffer tuareg-interactive-buffer-name))

 (defun tuareg-run-process-if-needed (optional cmd)
   Run an OCaml toplevel process if needed, with an optional command name.
 I/O via buffer `*ocaml-toplevel*'.
   (if cmd
   (setq tuareg-interactive-program cmd)
 (unless (comint-check-proc tuareg-interactive-buffer-name)
   (setq tuareg-interactive-program
 (read-shell-command OCaml toplevel to run: 
 tuareg-interactive-program
   (unless (comint-check-proc tuareg-interactive-buffer-name)
 (let ((cmdlist (tuareg-args-to-list tuareg-interactive-program))
   (process-connection-type nil))
   (set-buffer (apply (function make-comint) ocaml-toplevel
  (car cmdlist) nil (cdr cmdlist)))
   (tuareg-interactive-mode)
   (sleep-for 1
 #+END_SRC

 With this patch (and setting `org-confirm-babel-evaluate' to nil), I'm able to
 export documents requiring the evaluation of caml code asynchronously.

 Alan



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



[O] Patch for asynchronous export of ocaml code

2013-05-02 Thread Alan Schmitt
Hello,

It is not currently possible to asynchronously export the results of the
evaluation an ocaml babel block because the evaluation needs to start a toplevel
and thus asks the user what program to run. This of course blocks the
asynchronous export.

The attached patch adds a custom variable to specify the name of the command
to run, and directly calls the tuareg function that starts the toplevel given
the command.

For some context, here is the code that starts the caml session.

#+BEGIN_SRC emacs-lisp
(defvar tuareg-interactive-buffer-name)
(defun org-babel-prep-session:ocaml (session params)
  Prepare SESSION according to the header arguments in PARAMS.
  (require 'tuareg)
  (let ((tuareg-interactive-buffer-name (if (and (not (string= session none))
 (not (string= session 
default))
 (stringp session))
session
  tuareg-interactive-buffer-name)))
(save-window-excursion
  (if (fboundp 'tuareg-run-caml) (tuareg-run-caml) (tuareg-run-ocaml))
  (get-buffer tuareg-interactive-buffer-name
#+END_SRC

And this is the code from tuareg that is run.

#+BEGIN_SRC emacs-lisp
;;;###autoload
(defun tuareg-run-ocaml ()
  Run an OCaml toplevel process. I/O via buffer `*ocaml-toplevel*'.
  (interactive)
  (tuareg-run-process-if-needed)
  (display-buffer tuareg-interactive-buffer-name))

(defun tuareg-run-process-if-needed (optional cmd)
  Run an OCaml toplevel process if needed, with an optional command name.
I/O via buffer `*ocaml-toplevel*'.
  (if cmd
  (setq tuareg-interactive-program cmd)
(unless (comint-check-proc tuareg-interactive-buffer-name)
  (setq tuareg-interactive-program
(read-shell-command OCaml toplevel to run: 
tuareg-interactive-program
  (unless (comint-check-proc tuareg-interactive-buffer-name)
(let ((cmdlist (tuareg-args-to-list tuareg-interactive-program))
  (process-connection-type nil))
  (set-buffer (apply (function make-comint) ocaml-toplevel
 (car cmdlist) nil (cdr cmdlist)))
  (tuareg-interactive-mode)
  (sleep-for 1
#+END_SRC

With this patch (and setting `org-confirm-babel-evaluate' to nil), I'm able to
export documents requiring the evaluation of caml code asynchronously.

Alan

From 065cba70ae83b9483636b399604a64c0530eb463 Mon Sep 17 00:00:00 2001
From: Alan Schmitt alan.schm...@polytechnique.org
Date: Thu, 2 May 2013 16:57:29 +0200
Subject: [PATCH] Babel ocaml: allow ocaml code to run during asynchronous
 export

* lisp/ob-ocaml.el: Add a custom variable `org-babel-ocaml-command' to specify
the name of the toplevel to run.
(org-babel-prep-session:ocaml): Directly call `tuareg-run-process-if-needed'
with `org-babel-ocaml-command' as argument.
---
 lisp/ob-ocaml.el | 14 +++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-ocaml.el b/lisp/ob-ocaml.el
index 03500bb..1a194d8 100644
--- a/lisp/ob-ocaml.el
+++ b/lisp/ob-ocaml.el
@@ -51,6 +51,13 @@
 (defvar org-babel-ocaml-eoe-indicator \org-babel-ocaml-eoe\;;)
 (defvar org-babel-ocaml-eoe-output org-babel-ocaml-eoe)
 
+(defcustom org-babel-ocaml-command ocaml
+  Name of the command for executing Ocaml code.
+  :version 24.4
+  :package-version '(Org . 8.0)
+  :group 'org-babel
+  :type 'string)
+
 (defun org-babel-execute:ocaml (body params)
   Execute a block of Ocaml code with Babel.
   (let* ((vars (mapcar #'cdr (org-babel-get-header params :var)))
@@ -96,9 +103,10 @@
  (stringp session))
 session
   tuareg-interactive-buffer-name)))
-(save-window-excursion
-  (if (fboundp 'tuareg-run-caml) (tuareg-run-caml) (tuareg-run-ocaml))
-  (get-buffer tuareg-interactive-buffer-name
+(if (fboundp 'tuareg-run-process-if-needed)
+(tuareg-run-process-if-needed org-babel-ocaml-command)
+  (tuareg-run-caml))
+(get-buffer tuareg-interactive-buffer-name)))
 
 (defun org-babel-variable-assignments:ocaml (params)
   Return list of ocaml statements assigning the block's variables.
-- 
1.8.2.1