From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: Patch for asynchronous export of ocaml code Date: Fri, 03 May 2013 09:57:48 -0600 Message-ID: <87vc6wxeqw.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:51901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZO8b-0008CG-ER for emacs-orgmode@gnu.org; Mon, 06 May 2013 12:19:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UZO8Z-00045S-NZ for emacs-orgmode@gnu.org; Mon, 06 May 2013 12:19:41 -0400 Received: from mail-qc0-x229.google.com ([2607:f8b0:400d:c01::229]:38634) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZO8Z-00045N-JD for emacs-orgmode@gnu.org; Mon, 06 May 2013 12:19:39 -0400 Received: by mail-qc0-f169.google.com with SMTP id p9so322337qca.14 for ; Mon, 06 May 2013 09:19:39 -0700 (PDT) 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@gnu.org" This looks great, please apply this patch. Thanks, 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. > > 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