Re: [O] [PATCH] ob-stata.el: new file for stata code evaluation

2014-07-31 Thread Bastien
Hi Ista,

Ista Zahn istaz...@gmail.com writes:

 Here is a patch (against master) adding babel support for evaluating
 stata code. As discussed in a previous thread[1] there is a lot of
 work that should be done to clean it up and make it more useful. It
 does work for basic code evaluation, so I'm submitting it here in the
 hope that others find it useful.

Applied, thanks a lot!

You might also consider adding examples and documentation on Worg.

All best,

-- 
 Bastien



[O] [PATCH] ob-stata.el: new file for stata code evaluation

2014-07-30 Thread Ista Zahn
Here is a patch (against master) adding babel support for evaluating
stata code. As discussed in a previous thread[1] there is a lot of
work that should be done to clean it up and make it more useful. It
does work for basic code evaluation, so I'm submitting it here in the
hope that others find it useful.

Best,
Ista

[1] https://lists.gnu.org/archive/html/emacs-orgmode/2014-06/msg00862.html
From 24d957b8fc3eb207158e94cdec1a362ba2e79ff0 Mon Sep 17 00:00:00 2001
From: Ista Zahn istaz...@gmail.com
Date: Wed, 30 Jul 2014 17:07:16 -0400
Subject: [PATCH] ob-stata.el: new file for stata code evaluation

* contrib/lisp/ob-stata.el: New file based on ob-julia.el.
* contrib/README: Document addition of new file.

ob-stata.el provides basic support for evaluating Stata code.
---
 contrib/README   |   1 +
 contrib/lisp/ob-stata.el | 313 +++
 2 files changed, 314 insertions(+)
 create mode 100644 contrib/lisp/ob-stata.el

diff --git a/contrib/README b/contrib/README
index 2a67b65..e92da14 100644
--- a/contrib/README
+++ b/contrib/README
@@ -80,6 +80,7 @@ ob-fomus.el	 --- Org-babel functions for fomus evaluation
 ob-julia.el  	 	 --- Org-babel functions for julia evaluation
 ob-mathomatic.el   	 --- Org-babel functions for mathomatic evaluation
 ob-oz.el   	 --- Org-babel functions for Oz evaluation
+ob-stata.el  --- Org-babel functions for Stata evaluation
 ob-tcl.el 		 --- Org-babel functions for tcl evaluation
 
 External libraries
diff --git a/contrib/lisp/ob-stata.el b/contrib/lisp/ob-stata.el
new file mode 100644
index 000..8a70754
--- /dev/null
+++ b/contrib/lisp/ob-stata.el
@@ -0,0 +1,313 @@
+;;; ob-stata.el --- org-babel functions for stata code evaluation
+
+;; Copyright (C) 2014 Ista Zahn
+;; Author: Ista Zahn istaz...@gmail.com
+;;  G. Jay Kerns
+;;  Eric Schulte
+;;  Dan Davison
+
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+;;
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+
+;; The file provides Org-Babel support for evaluating stata code.
+;; It is basically result of find-and-replace stata for julia
+;; in ob-julia.el by G. Jay Kerns. Only :results output works: the
+;; header args must include :results output (this is the default).
+;; Note that I'm not sure ':results value' makes sense or is useful 
+;; but I have left all the value-processing stuff inherited from 
+;; ob-julia and ob-R. ':results graphics' would be nice, but I have
+;; not tried to implement it. 
+;; --Ista, 07/30/2014
+
+;;; Requirements:
+;; Stata: http://stata.com
+;; ESS: http://ess.r-project.org
+
+;;; Code:
+(require 'ob)
+(eval-when-compile (require 'cl))
+
+(declare-function orgtbl-to-csv org-table (table params))
+(declare-function stata ext:ess-stata (optional start-args))
+(declare-function inferior-ess-send-input ext:ess-inf ())
+(declare-function ess-make-buffer-current ext:ess-inf ())
+(declare-function ess-eval-buffer ext:ess-inf (vis))
+(declare-function org-number-sequence org-compat (from optional to inc))
+(declare-function org-remove-if-not org (predicate seq))
+
+(defconst org-babel-header-args:stata
+  '((width		 . :any)
+(horizontal		 . :any)
+(results . ((file list vector table scalar verbatim)
+			(raw org html latex code pp wrap)
+			(replace silent append prepend)
+;; NOTE: not sure 'value' makes sense in stata
+;; we may want to remove it from the list
+			(output value graphics
+  stata-specific header arguments.)
+
+(add-to-list 'org-babel-tangle-lang-exts '(stata . do))
+
+;; only ':results output' currently works, so make that the default
+(defvar org-babel-default-header-args:stata '((:results . output)))
+
+(defcustom org-babel-stata-command inferior-STA-program-name
+  Name of command to use for executing stata code.
+  :group 'org-babel
+  :version 24.4
+  :package-version '(Org . 8.3)
+  :type 'string)
+
+(defvar ess-local-process-name) ; dynamically scoped
+(defun org-babel-edit-prep:stata (info)
+  (let ((session (cdr (assoc :session (nth 2 info)
+(when (and session (string-match ^\\*\\(.+?\\)\\*$ session))
+  (save-match-data (org-babel-stata-initiate-session session nil)
+
+(defun