Browse Source

babel: all languages compiling cleanly (but R has a small problem)

  For some reason ob-R refuses to compile when it requires ob-comint.

  When (require 'ob-comint) is not included in  ob-R.el everything
  compiles without error, but warnings are thrown because the
  arguments to a macro defined in ob-comint are mis-interpreted as
  functions.

  When (require 'ob-comint) is added to ob-R.el then it throws errors
  complaining that the last argument to a function is nil and should
  be a string.  I don't understand this error at all and can't fix it.
Eric Schulte 14 years ago
parent
commit
6c2e35003f
22 changed files with 241 additions and 126 deletions
  1. 2 1
      lisp/ob-C.el
  2. 13 0
      lisp/ob-R.el
  3. 3 0
      lisp/ob-asymptote.el
  4. 28 9
      lisp/ob-clojure.el
  5. 2 1
      lisp/ob-comint.el
  6. 1 0
      lisp/ob-ditaa.el
  7. 20 4
      lisp/ob-gnuplot.el
  8. 19 9
      lisp/ob-haskell.el
  9. 7 3
      lisp/ob-latex.el
  10. 2 35
      lisp/ob-matlab.el
  11. 9 2
      lisp/ob-ocaml.el
  12. 74 28
      lisp/ob-octave.el
  13. 5 8
      lisp/ob-perl.el
  14. 10 5
      lisp/ob-python.el
  15. 13 4
      lisp/ob-ruby.el
  16. 0 1
      lisp/ob-sass.el
  17. 19 10
      lisp/ob-screen.el
  18. 1 0
      lisp/ob-sh.el
  19. 5 1
      lisp/ob-sql.el
  20. 4 0
      lisp/ob-sqlite.el
  21. 3 3
      lisp/ob.el
  22. 1 2
      lisp/org.el

+ 2 - 1
lisp/ob-C.el

@@ -35,7 +35,8 @@
 (require 'org)
 (require 'cc-mode)
 
-(declare-function org-entry-get "org" (&optional inherit))
+(declare-function org-entry-get "org"
+		  (pom property &optional inherit literal-nil))
 
 (add-to-list 'org-babel-tangle-lang-exts '("c++" . "cpp"))
 

+ 13 - 0
lisp/ob-R.el

@@ -28,6 +28,17 @@
 
 ;;; Code:
 (require 'ob)
+(require 'ob-ref)
+(eval-when-compile (require 'cl))
+
+(declare-function org-babel-comint-in-buffer "ob-comint" (buffer &rest body))
+(declare-function comint-send-input "ob-comint" (el'.))
+(declare-function org-babel-comint-wait-for-output "ob-comint" (buffer))
+(declare-function org-babel-comint-buffer-livep "ob-comint" (buffer))
+(declare-function org-babel-comint-with-output "ob-comint" (meta &rest body))
+(declare-function orgtbl-to-tsv "ob-table" (table params))
+(declare-function R "essd-r" (&optional start-args))
+(declare-function inferior-ess-send-input "ess-inf" ())
 
 (defconst org-babel-header-arg-names:R
   '(width height bg units pointsize antialias quality compression
@@ -171,6 +182,8 @@ called by `org-babel-execute-src-block'."
 (defvar org-babel-R-wrapper-method "main <- function ()\n{\n%s\n}
 write.table(main(), file=\"%s\", sep=\"\\t\", na=\"nil\",row.names=%s, col.names=%s, quote=FALSE)")
 
+(defvar inferior-ess-primary-prompt)
+(defvar inferior-ess-secondary-prompt)
 (defun org-babel-R-evaluate (session body result-type column-names-p row-names-p)
   "Pass BODY to the R process in SESSION.  If RESULT-TYPE equals
 'output then return a list of the outputs of the statements in

+ 3 - 0
lisp/ob-asymptote.el

@@ -46,6 +46,9 @@
 (require 'ob)
 (eval-when-compile (require 'cl))
 
+(declare-function orgtbl-to-generic "org-table" (table params))
+(declare-function org-combine-plists "org" (&rest plists))
+
 (add-to-list 'org-babel-tangle-lang-exts '("asymptote" . "asy"))
 
 (defvar org-babel-default-header-args:asymptote

+ 28 - 9
lisp/ob-clojure.el

@@ -39,9 +39,16 @@
 
 ;;; Code:
 (require 'ob)
-(require 'cl)
-(require 'slime)
-(require 'swank-clojure)
+(eval-when-compile
+  (require 'cl))
+
+(declare-function slime-eval-async "slime" (sexp &optional cont package))
+(declare-function slime-eval "slime" (sexp &optional package))
+(declare-function swank-clojure-concat-paths "slime" (paths))
+(declare-function org-babel-ref-variables "slime" (params))
+(declare-function slime "slime" (&optional command coding-system))
+(declare-function slime-output-buffer "slime" (&optional noprompt))
+(declare-function slime-filter-buffers "slime" (predicate))
 
 (add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj"))
 
@@ -76,6 +83,12 @@
   (slime-eval `(swank:eval-and-grab-output ,string)))
 
 ;;taken from swank-clojure.el
+(defvar swank-clojure-binary)
+(defvar swank-clojure-classpath)
+(defvar swank-clojure-java-path)
+(defvar swank-clojure-extra-vm-args)
+(defvar swank-clojure-library-paths)
+(defvar swank-clojure-extra-classpaths)
 (defun org-babel-clojure-babel-clojure-cmd ()
   "Create the command to start clojure according to current settings."
   (if (and (not swank-clojure-binary) (not swank-clojure-classpath))
@@ -84,8 +97,8 @@
         (if (listp swank-clojure-binary)
             swank-clojure-binary
           (list swank-clojure-binary))
-      (delete-if
-       'null
+      (delq
+       nil
        (append
         (list swank-clojure-java-path)
         swank-clojure-extra-vm-args
@@ -132,6 +145,7 @@ specifying a var of the same value."
 
 (defun org-babel-prep-session:clojure (session params)
   "Prepare SESSION according to the header arguments specified in PARAMS."
+  (require 'slime) (require 'swank-clojure)
   (let* ((session-buf (org-babel-clojure-initiate-session session))
          (vars (org-babel-ref-variables params))
          (var-lines (mapcar ;; define any top level session variables
@@ -143,6 +157,7 @@ specifying a var of the same value."
 
 (defun org-babel-load-session:clojure (session body params)
   "Load BODY into SESSION."
+  (require 'slime) (require 'swank-clojure)
   (save-window-excursion
     (let ((buffer (org-babel-prep-session:clojure session params)))
       (with-current-buffer buffer
@@ -188,6 +203,7 @@ then create one.  Return the initialized session."
 (defun org-babel-clojure-initiate-session (&optional session params)
   "Return the slime-clojure repl buffer bound to this session
 or nil if \"none\" is specified."
+  (require 'slime) (require 'swank-clojure)
   (unless (and (stringp session) (string= session "none"))
     (org-babel-clojure-session-buffer (org-babel-clojure-initiate-session-by-key session))))
 
@@ -254,16 +270,18 @@ repl buffer."
       (set-buffer buffer)
       (setq raw (org-babel-clojure-slime-eval-sync body))
       (setq results (reverse (mapcar #'org-babel-trim raw)))
-      (case result-type
-        (output (mapconcat #'identity (reverse (cdr results)) "\n"))
-        (value (org-babel-clojure-table-or-string (car results)))))))
+      (cond
+       ((equal result-type 'output)
+	(mapconcat #'identity (reverse (cdr results)) "\n"))
+       ((equal result-type 'value)
+	(org-babel-clojure-table-or-string (car results)))))))
 
 (defun org-babel-clojure-evaluate (buffer body &optional result-type)
   "Pass BODY to the Clojure process in BUFFER.  If RESULT-TYPE equals
 'output then return a list of the outputs of the statements in
 BODY, if RESULT-TYPE equals 'value then return the value of the
 last statement in BODY, as elisp."
-  (if session
+  (if buffer
       (org-babel-clojure-evaluate-session buffer body result-type)
     (org-babel-clojure-evaluate-external-process buffer body result-type)))
 
@@ -274,6 +292,7 @@ last statement in BODY, as elisp."
 
 (defun org-babel-execute:clojure (body params)
   "Execute a block of Clojure code with org-babel."
+  (require 'slime) (require 'swank-clojure)
   (let* ((processed-params (org-babel-process-params params))
          (body (org-babel-expand-body:clojure body params processed-params))
          (session (org-babel-clojure-initiate-session (first processed-params))))

+ 2 - 1
lisp/ob-comint.el

@@ -33,6 +33,7 @@
 ;;; Code:
 (require 'ob)
 (require 'comint)
+(eval-when-compile (require 'cl))
 
 (defun org-babel-comint-buffer-livep (buffer)
   "Check if BUFFER is a comint buffer with a live process."
@@ -68,7 +69,7 @@ or user `keyboard-quit' during execution of body."
 	(remove-echo (cadr (cdr meta)))
 	(full-body (cadr (cdr (cdr meta)))))
     `(org-babel-comint-in-buffer ,buffer
-       (let ((string-buffer "") dangling-text)
+       (let ((string-buffer "") dangling-text raw)
 	 (flet ((my-filt (text)
 			 (setq string-buffer (concat string-buffer text))))
 	   ;; setup filter

+ 1 - 0
lisp/ob-ditaa.el

@@ -46,6 +46,7 @@
 (defun org-babel-expand-body:ditaa (body params &optional processed-params)
   "Expand BODY according to PARAMS, return the expanded body." body)
 
+(defvar org-ditaa-jar-path)
 (defun org-babel-execute:ditaa (body params)
   "Execute a block of Ditaa code with org-babel.  This function is
 called by `org-babel-execute-src-block'."

+ 20 - 4
lisp/ob-gnuplot.el

@@ -40,7 +40,16 @@
 
 ;;; Code:
 (require 'ob)
-(require 'gnuplot)
+(require 'ob-ref)
+(require 'ob-comint)
+(eval-when-compile (require 'cl))
+
+(declare-function org-time-string-to-time "org" (s))
+(declare-function org-combine-plists "org" (&rest plists))
+(declare-function orgtbl-to-generic "org-table" (table params))
+(declare-function gnuplot-mode "gnuplot-mode" ())
+(declare-function gnuplot-send-string-to-gnuplot "gnuplot-mode" (string text))
+(declare-function gnuplot-send-buffer-to-gnuplot "gnuplot-mode" ())
 
 (defvar org-babel-default-header-args:gnuplot
   '((:results . "file") (:exports . "results") (:session . nil))
@@ -124,10 +133,12 @@ code."
   "Execute a block of Gnuplot code with org-babel.  This function is
 called by `org-babel-execute-src-block'."
   (message "executing Gnuplot source code block")
+  (require 'gnuplot)
   (let ((session (cdr (assoc :session params)))
         (result-type (cdr (assoc :results params)))
         (out-file (cdr (assoc :file params)))
-        (body (org-babel-expand-body:gnuplot body params)))
+        (body (org-babel-expand-body:gnuplot body params))
+	output)
     (save-window-excursion
       ;; evaluate the code body with gnuplot
       (if (string= session "none")
@@ -170,18 +181,23 @@ called by `org-babel-execute-src-block'."
         (insert (org-babel-chomp body)))
       buffer)))
 
+(defvar gnuplot-buffer)
 (defun org-babel-gnuplot-initiate-session (&optional session params)
   "If there is not a current inferior-process-buffer in SESSION
 then create one.  Return the initialized session.  The current
 `gnuplot-mode' doesn't provide support for multiple sessions."
+  (require 'gnuplot)
   (unless (string= session "none")
-    (save-window-excursion (gnuplot-send-string-to-gnuplot "" "line")
-                           gnuplot-buffer)))
+    (save-window-excursion
+      (gnuplot-send-string-to-gnuplot "" "line")
+      gnuplot-buffer)))
 
 (defun org-babel-gnuplot-quote-timestamp-field (s)
   "Convert field S from timestamp to Unix time and export to gnuplot."
   (format-time-string org-babel-gnuplot-timestamp-fmt (org-time-string-to-time s)))
 
+(defvar org-table-number-regexp)
+(defvar org-ts-regexp3)
 (defun org-babel-gnuplot-quote-tsv-field (s)
   "Quote field S for export to gnuplot."
   (unless (stringp s)

+ 19 - 9
lisp/ob-haskell.el

@@ -41,8 +41,15 @@
 
 ;;; Code:
 (require 'ob)
-(require 'haskell-mode)
-(require 'inf-haskell)
+(require 'ob-comint)
+(require 'comint)
+(eval-when-compile (require 'cl))
+
+(declare-function org-remove-indentation "org" (code &optional n))
+(declare-function haskell-mode "ext:haskell-mode" ())
+(declare-function run-haskell "ext:inf-haskell" (&optional arg))
+(declare-function inferior-haskell-load-file
+		  "ext:inf-haskell" (&optional reload))
 
 (add-to-list 'org-babel-tangle-lang-exts '("haskell" . "hs"))
 
@@ -66,7 +73,7 @@
   "Execute a block of Haskell code with org-babel."
   (message "executing haskell source code block")
   (let* ((processed-params (org-babel-process-params params))
-         (session (first processed-params))
+         (session (nth 0 processed-params))
          (vars (nth 1 processed-params))
          (result-type (nth 3 processed-params))
          (full-body (org-babel-expand-body:haskell body params processed-params))
@@ -82,9 +89,11 @@
                    (cdr (member org-babel-haskell-eoe
                                 (reverse (mapcar #'org-babel-trim raw)))))))
     (org-babel-reassemble-table
-     (case result-type
-       (output (mapconcat #'identity (reverse (cdr results)) "\n"))
-       (value (org-babel-haskell-table-or-string (car results))))
+     (cond 
+      ((equal result-type 'output)
+       (mapconcat #'identity (reverse (cdr results)) "\n"))
+      ((equal result-type 'value)
+       (org-babel-haskell-table-or-string (car results))))
      (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
      (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params))))))
 
@@ -97,7 +106,7 @@
 (defun org-babel-haskell-initiate-session (&optional session params)
   "If there is not a current inferior-process-buffer in SESSION
 then create one.  Return the initialized session."
-  ;; TODO: make it possible to have multiple sessions
+  (require 'inf-haskell)
   (or (get-buffer "*haskell*")
       (save-window-excursion (run-haskell) (sleep-for 0.25) (current-buffer))))
 
@@ -114,13 +123,13 @@ then create one.  Return the initialized session."
       buffer)))
 
 (defun org-babel-prep-session:haskell
-  (session params &optional processesed-params)
+  (session params &optional processed-params)
   "Prepare SESSION according to the header arguments specified in PARAMS."
   (save-window-excursion
     (let ((pp (or processed-params (org-babel-process-params params)))
 	  (buffer (org-babel-haskell-initiate-session session)))
       (org-babel-comint-in-buffer buffer
-      	(mapcar
+      	(mapc
       	 (lambda (pair)
       	   (insert (format "let %s = %s"
       			   (car pair)
@@ -150,6 +159,7 @@ specifying a var of the same value."
       (concat "[" (mapconcat #'org-babel-haskell-var-to-haskell var ", ") "]")
     (format "%S" var)))
 
+(defvar org-src-preserve-indentation)
 (defun org-babel-haskell-export-to-lhs (&optional arg)
   "Export to a .lhs file with all haskell code blocks escaped
 appropriately.  When called with a prefix argument the resulting

+ 7 - 3
lisp/ob-latex.el

@@ -32,6 +32,7 @@
 
 ;;; Code:
 (require 'ob)
+(require 'org-latex)
 
 (add-to-list 'org-babel-tangle-lang-exts '("latex" . "tex"))
 
@@ -85,9 +86,12 @@ called by `org-babel-execute-src-block'."
   (with-temp-file tex-file
     (insert (org-splice-latex-header
 	       org-format-latex-header
-	       (remove-if
-                (lambda (el) (and (listp el) (string= "hyperref" (cadr el))))
-                org-export-latex-default-packages-alist)
+	       (delq
+		nil
+		(mapcar
+		 (lambda (el) (unless (and (listp el) (string= "hyperref" (cadr el)))
+			   el))
+		 org-export-latex-default-packages-alist))
 	       org-export-latex-packages-alist
 	       org-format-latex-header-extra)
             (if height (concat "\n" (format "\\pdfpageheight %s" height)) "")

+ 2 - 35
lisp/ob-matlab.el

@@ -36,43 +36,10 @@
 ;; http://matlab-emacs.sourceforge.net/
 
 ;;; Code:
-(require 'matlab)
+(require 'ob)
 (require 'ob-octave)
 
-(defvar org-babel-default-header-args:matlab '())
-
-(defvar org-babel-matlab-shell-command "matlab -nosplash"
-  "Shell command to use to run matlab as an external process.")
-
-(defun org-babel-expand-body:matlab (body params &optional processed-params)
-  "Expand BODY according to PARAMS, return the expanded body." body)
-
-(defvar org-babel-matlab-with-emacs-link nil
-  "If non-nil use matlab-shell-run-region for session
-  evaluation. This will use EmacsLink if (matlab-with-emacs-link)
-  evaluates to a non-nil value.")
-
-(defvar org-babel-matlab-emacs-link-wrapper-method
-   "%s
-if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans); fclose(fid);
-else, save -ascii %s ans
-end
-delete('%s')
-")
-
-(defun org-babel-execute:matlab (body params)
-  "Execute a block of matlab code with org-babel."
-  (org-babel-execute:octave body params 'matlab))
-
-(defun org-babel-prep-session:matlab (session params)
-  "Prepare SESSION according to PARAMS."
-  (org-babel-prep-session:octave session params 'matlab))
-
-(defun org-babel-matlab-initiate-session (&optional session params)
-  "Create a matlab inferior process buffer.  If there is not a
-current inferior-process-buffer in SESSION then create. Return
-the initialized session."
-  (org-babel-octave-initiate-session session params 'matlab))
+;; see ob-octave for matlab implementation
 
 (provide 'ob-matlab)
 

+ 9 - 2
lisp/ob-ocaml.el

@@ -37,7 +37,11 @@
 
 ;;; Code:
 (require 'ob)
-(require 'tuareg)
+(require 'ob-comint)
+(require 'comint)
+(eval-when-compile (require 'cl))
+
+(declare-function tuareg-run-caml "taureg" ())
 
 (add-to-list 'org-babel-tangle-lang-exts '("ocaml" . "ml"))
 
@@ -60,7 +64,8 @@
   (let* ((processed-params (org-babel-process-params params))
          (vars (nth 1 processed-params))
          (full-body (org-babel-expand-body:ocaml body params processed-params))
-         (session (org-babel-prep-session:ocaml session params))
+         (session (org-babel-prep-session:ocaml
+		   (cdr (assoc :session params)) params))
          (raw (org-babel-comint-with-output
 		  (session org-babel-ocaml-eoe-output t full-body)
                 (insert (concat (org-babel-chomp full-body) " ;;"))
@@ -72,8 +77,10 @@
      (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
      (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params))))))
 
+(defvar tuareg-interactive-buffer-name)
 (defun org-babel-prep-session:ocaml (session params)
   "Prepare SESSION according to the header arguments specified in PARAMS."
+  (require 'tuareg)
   (let ((tuareg-interactive-buffer-name (if (and (not (string= session "none"))
                                                  (not (string= session "default"))
                                                  (stringp session))

+ 74 - 28
lisp/ob-octave.el

@@ -31,13 +31,23 @@
 
 ;;; Code:
 (require 'ob)
-(require 'octave-inf)
+(require 'ob-ref)
+(require 'ob-comint)
+(eval-when-compile (require 'cl))
 
+(declare-function matlab-shell "matlab-mode")
+(declare-function matlab-shell-run-region "matlab-mode")
+
+(defvar org-babel-default-header-args:matlab '())
 (defvar org-babel-default-header-args:octave '())
 
+(defvar org-babel-matlab-shell-command "matlab -nosplash"
+  "Shell command to use to run matlab as an external process.")
 (defvar org-babel-octave-shell-command "octave -q"
   "Shell command to use to run octave as an external process.")
 
+(defun org-babel-expand-body:matlab (body params &optional processed-params)
+  "Expand BODY according to PARAMS, return the expanded body." body)
 (defun org-babel-expand-body:octave (body params &optional processed-params)
   "Expand BODY according to PARAMS, return the expanded body."
   (let ((vars (nth 1 (or processed-params (org-babel-process-params params)))))
@@ -51,13 +61,32 @@
                 (org-babel-octave-var-to-octave (cdr pair))))
       vars "\n") "\n" body "\n")))
 
+(defvar org-babel-matlab-with-emacs-link nil
+  "If non-nil use matlab-shell-run-region for session
+  evaluation. This will use EmacsLink if (matlab-with-emacs-link)
+  evaluates to a non-nil value.")
+
+(defvar org-babel-matlab-emacs-link-wrapper-method
+   "%s
+if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans); fclose(fid);
+else, save -ascii %s ans
+end
+delete('%s')
+")
+
+(defun org-babel-execute:matlab (body params)
+  "Execute a block of matlab code with org-babel."
+  (require 'matlab)
+  (org-babel-execute:octave body params 'matlab))
 (defun org-babel-execute:octave (body params &optional matlabp)
   "Execute a block of octave code with org-babel."
   (message (format "executing %s source code block" (if matlabp "matlab" "octave")))
   (let* ((processed-params (org-babel-process-params params))
          ;; set the session if the session variable is non-nil
-         (session (funcall (intern (format "org-babel-%s-initiate-session" lang))
-			   (first processed-params) params))
+         (session
+	  (funcall (intern (format "org-babel-%s-initiate-session"
+				   (if matlabp "matlab" "octave")))
+		   (nth 0 processed-params) params))
          (vars (nth 1 processed-params))
          (result-params (nth 2 processed-params))
          (result-type (nth 3 processed-params))
@@ -70,6 +99,10 @@
          (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
          (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params)))))))
 
+(defun org-babel-prep-session:matlab (session params)
+  "Prepare SESSION according to PARAMS."
+  (require 'matlab)
+  (org-babel-prep-session:octave session params 'matlab))
 (defun org-babel-octave-var-to-octave (var)
   "Convert an emacs-lisp variable into an octave variable.
 Converts an emacs-lisp variable into a string of octave code
@@ -94,10 +127,17 @@ specifying a variable of the same value."
               (org-babel-comint-wait-for-output session)) var-lines))
     session))
 
+(defun org-babel-matlab-initiate-session (&optional session params)
+  "Create a matlab inferior process buffer.  If there is not a
+current inferior-process-buffer in SESSION then create. Return
+the initialized session."
+  (require 'matlab)
+  (org-babel-octave-initiate-session session params 'matlab))
 (defun org-babel-octave-initiate-session (&optional session params matlabp)
   "Create an octave inferior process buffer.  If there is not a
 current inferior-process-buffer in SESSION then create. Return
 the initialized session."
+  (require 'octave-inf)
   (unless (string= session "none")
     (let ((session (or session (if matlabp "*Inferior Matlab*" "*Inferior Octave*"))))
       (if (org-babel-comint-buffer-livep session) session
@@ -117,7 +157,8 @@ end")
 
 (defvar org-babel-octave-eoe-output "ans = org_babel_eoe")
 
-(defun org-babel-octave-evaluate (session body result-type lang)
+(defun org-babel-octave-evaluate
+  (session body result-type lang &optional matlabp)
   "Pass BODY to the octave process in SESSION.  If RESULT-TYPE
 equals 'output then return the outputs of the statements in BODY,
 if RESULT-TYPE equals 'value then return the value of the last
@@ -130,24 +171,25 @@ statement in BODY, as elisp."
   "Evaluate BODY in an external octave process."
   (let ((cmd (if matlabp org-babel-matlab-shell-command org-babel-octave-shell-command)))
     (save-excursion
-      (case result-type
-	(output
-	 (with-temp-buffer
-	   (insert body)
-	   (org-babel-shell-command-on-region (point-min) (point-max) cmd 'current-buffer 'replace)
-	   (buffer-string)))
-	(value
-	 (let* ((tmp-file (make-temp-file "org-babel-results-")) exit-code
-		(stderr
-		 (with-temp-buffer
-		   (insert (format org-babel-octave-wrapper-method body tmp-file tmp-file))
-		   (setq exit-code (org-babel-shell-command-on-region
-				    (point-min) (point-max) cmd nil 'replace (current-buffer)))
-		   (buffer-string))))
-	   (if (> exit-code 0) (org-babel-error-notify exit-code stderr))
-	   (org-babel-octave-import-elisp-from-file (org-babel-maybe-remote-file tmp-file))))))))
-
-(defun org-babel-octave-evaluate-session (session body result-type &optional matlabp)
+      (cond
+       ((equal result-type 'output)
+	(with-temp-buffer
+	  (insert body)
+	  (org-babel-shell-command-on-region (point-min) (point-max) cmd 'current-buffer 'replace)
+	  (buffer-string)))
+       ((equal result-type 'value)
+	(let* ((tmp-file (make-temp-file "org-babel-results-")) exit-code
+	       (stderr
+		(with-temp-buffer
+		  (insert (format org-babel-octave-wrapper-method body tmp-file tmp-file))
+		  (setq exit-code (org-babel-shell-command-on-region
+				   (point-min) (point-max) cmd nil 'replace (current-buffer)))
+		  (buffer-string))))
+	  (if (> exit-code 0) (org-babel-error-notify exit-code stderr))
+	  (org-babel-octave-import-elisp-from-file (org-babel-maybe-remote-file tmp-file))))))))
+
+(defun org-babel-octave-evaluate-session
+  (session body result-type &optional matlabp)
   "Evaluate BODY in SESSION."
   (let* ((tmp-file (make-temp-file "org-babel-results-"))
 	 (wait-file (make-temp-file "org-babel-matlab-emacs-link-wait-signal-"))
@@ -164,7 +206,8 @@ statement in BODY, as elisp."
 			  body tmp-file tmp-file wait-file) "\n")
 	       (mapconcat
 		#'org-babel-chomp
-		(list (format org-babel-octave-wrapper-method body tmp-file tmp-file)
+		(list (format org-babel-octave-wrapper-method
+			      body tmp-file tmp-file)
 		      org-babel-octave-eoe-indicator) "\n")))))
 	 (raw (if (and matlabp org-babel-matlab-with-emacs-link)
 		  (save-window-excursion
@@ -187,16 +230,19 @@ statement in BODY, as elisp."
 		  (insert full-body) (comint-send-input nil t)))) results)
     (case result-type
       (value
-       (org-babel-octave-import-elisp-from-file (org-babel-maybe-remote-file tmp-file)))
+       (org-babel-octave-import-elisp-from-file
+	(org-babel-maybe-remote-file tmp-file)))
       (output
        (progn
 	 (setq results
 	       (if matlabp
-		   (cdr (reverse (delq "" (mapcar #'org-babel-octave-read-string
-						  (mapcar #'org-babel-trim raw)))))
+		   (cdr (reverse (delq "" (mapcar
+					   #'org-babel-octave-read-string
+					   (mapcar #'org-babel-trim raw)))))
 		 (cdr (member org-babel-octave-eoe-output
-			      (reverse (mapcar #'org-babel-octave-read-string
-					       (mapcar #'org-babel-trim raw)))))))
+			      (reverse (mapcar
+					#'org-babel-octave-read-string
+					(mapcar #'org-babel-trim raw)))))))
 	 (mapconcat #'identity (reverse results) "\n"))))))
 
 (defun org-babel-octave-import-elisp-from-file (file-name)

+ 5 - 8
lisp/ob-perl.el

@@ -49,7 +49,7 @@
 called by `org-babel-execute-src-block'."
   (message "executing Perl source code block")
   (let* ((processed-params (org-babel-process-params params))
-         (session (first processed-params))
+         (session (nth 0 processed-params))
          (vars (nth 1 processed-params))
          (result-params (nth 2 processed-params))
          (result-type (nth 3 processed-params))
@@ -100,22 +100,19 @@ last statement in BODY, as elisp."
   (if (not session)
       ;; external process evaluation
       (save-excursion
-        (case result-type
-          (output
+        (cond
+	 ((equal result-type 'output)
            (with-temp-buffer
              (insert body)
              ;; (message "buffer=%s" (buffer-string)) ;; debugging
              (org-babel-shell-command-on-region (point-min) (point-max) "perl" 'current-buffer 'replace)
              (buffer-string)))
-          (value
+          ((equal result-type 'value)
            (let* ((tmp-file (make-temp-file "perl-functional-results")) exit-code
 		 (stderr
 		  (with-temp-buffer
 		    (insert
-		     (format
-		      (if (member "pp" result-params)
-			  (error "Pretty-printing not implemented for perl")
-			org-babel-perl-wrapper-method) body tmp-file))
+		     (format org-babel-perl-wrapper-method body tmp-file))
 		    (setq exit-code
 			  (org-babel-shell-command-on-region
 			   (point-min) (point-max) "perl" nil 'replace (current-buffer)))

+ 10 - 5
lisp/ob-python.el

@@ -28,9 +28,12 @@
 
 ;;; Code:
 (require 'ob)
-(require 'ob-tangle)
+(require 'ob-ref)
 (require 'ob-comint)
 (require (if (featurep 'xemacs) 'python-mode 'python))
+(eval-when-compile (require 'cl))
+
+(declare-function org-remove-indentation "org" )
 
 (add-to-list 'org-babel-tangle-lang-exts '("python" . "py"))
 
@@ -57,7 +60,8 @@ called by `org-babel-execute-src-block'."
          (result-type (nth 3 processed-params))
          (full-body (org-babel-expand-body:python
                      body params processed-params)) ;; then the source block body
-         (result (org-babel-python-evaluate session full-body result-type)))
+         (result (org-babel-python-evaluate
+		  session full-body result-type result-params)))
     (or (cdr (assoc :file params))
         (org-babel-reassemble-table
          result
@@ -177,12 +181,13 @@ def main():
 
 open('%s', 'w').write( pprint.pformat(main()) )")
 
-(defun org-babel-python-evaluate (buffer body &optional result-type)
+(defun org-babel-python-evaluate
+  (buffer body &optional result-type result-params)
   "Pass BODY to the Python process in BUFFER.  If RESULT-TYPE equals
 'output then return a list of the outputs of the statements in
 BODY, if RESULT-TYPE equals 'value then return the value of the
 last statement in BODY, as elisp."
-  (if (not session)
+  (if (not buffer)
       ;; external process evaluation
       (save-excursion
         (case result-type
@@ -220,7 +225,7 @@ last statement in BODY, as elisp."
     ;; comint session evaluation
     (org-babel-comint-in-buffer buffer
       (let* ((raw (org-babel-comint-with-output
-		      (buffer org-babel-python-eoe-indicator t full-body)
+		      (buffer org-babel-python-eoe-indicator t body)
                     ;; for some reason python is fussy, and likes enters after every input
 		    (let ((comint-process-echoes nil))
 		      (mapc (lambda (statement) (insert statement) (comint-send-input))

+ 13 - 4
lisp/ob-ruby.el

@@ -38,7 +38,12 @@
 
 ;;; Code:
 (require 'ob)
-(require 'inf-ruby)
+(require 'ob-ref)
+(require 'ob-comint)
+(eval-when-compile
+  (require 'cl))
+
+(declare-function run-ruby "inf-ruby" (&optional command name))
 
 (add-to-list 'org-babel-tangle-lang-exts '("ruby" . "rb"))
 
@@ -46,6 +51,7 @@
 
 (defun org-babel-expand-body:ruby (body params &optional processed-params)
   "Expand BODY according to PARAMS, return the expanded body."
+  (require 'inf-ruby)
   (let ((vars (nth 1 (or processed-params (org-babel-process-params params)))))
     (concat
      (mapconcat ;; define any variables
@@ -65,7 +71,8 @@ called by `org-babel-execute-src-block'."
          (result-type (nth 3 processed-params))
          (full-body (org-babel-expand-body:ruby
                      body params processed-params))
-         (result (org-babel-ruby-evaluate session full-body result-type)))
+         (result (org-babel-ruby-evaluate
+		  session full-body result-type result-params)))
     (or (cdr (assoc :file params))
         (org-babel-reassemble-table
          result
@@ -129,6 +136,7 @@ Emacs-lisp table, otherwise return the results as a string."
 (defun org-babel-ruby-initiate-session (&optional session params)
   "If there is not a current inferior-process-buffer in SESSION
 then create one.  Return the initialized session."
+  (require 'inf-ruby)
   (unless (string= session "none")
     (let ((session-buffer (save-window-excursion
 			    (run-ruby nil session) (current-buffer))))
@@ -164,12 +172,13 @@ File.open('%s', 'w') do |f|
 end
 ")
 
-(defun org-babel-ruby-evaluate (buffer body &optional result-type)
+(defun org-babel-ruby-evaluate
+  (buffer body &optional result-type result-params)
   "Pass BODY to the Ruby process in BUFFER.  If RESULT-TYPE equals
 'output then return a list of the outputs of the statements in
 BODY, if RESULT-TYPE equals 'value then return the value of the
 last statement in BODY, as elisp."
-  (if (not session)
+  (if (not buffer)
       ;; external process evaluation
       (save-excursion
         (case result-type

+ 0 - 1
lisp/ob-sass.el

@@ -40,7 +40,6 @@
 
 ;;; Code:
 (require 'ob)
-(require 'sass-mode)
 
 (defvar org-babel-default-header-args:sass '())
 

+ 19 - 10
lisp/ob-screen.el

@@ -35,6 +35,7 @@
 
 ;;; Code:
 (require 'ob)
+(require 'ob-ref)
 
 (defvar org-babel-screen-location "screen"
   "The command location for screen. 
@@ -53,7 +54,7 @@ In case you want to use a different screen than one selected by your $PATH")
   (message "Sending source code block to interactive terminal session...")
   (save-window-excursion
     (let* ((processed-params (org-babel-process-params params))
-           (session (first processed-params))
+           (session (nth 0 processed-params))
            (socket (org-babel-screen-session-socketname session)))
       (unless socket (org-babel-prep-session:screen session params))
       (org-babel-screen-session-execute-string
@@ -62,7 +63,7 @@ In case you want to use a different screen than one selected by your $PATH")
 (defun org-babel-prep-session:screen (session params)
   "Prepare SESSION according to the header arguments specified in PARAMS."
   (let* ((processed-params (org-babel-process-params params))
-         (session (first processed-params))
+         (session (nth 0 processed-params))
          (vars (nth 1 processed-params))
          (socket (org-babel-screen-session-socketname session))
          (vars (org-babel-ref-variables params))
@@ -94,14 +95,22 @@ In case you want to use a different screen than one selected by your $PATH")
 (defun org-babel-screen-session-socketname (session)
   "Check if SESSION exist by parsing output of \"screen -ls\"."
   (let* ((screen-ls (shell-command-to-string "screen -ls"))
-         (sockets (remove-if-not
-                   '(lambda (x)
-                     (string-match (rx (or "(Attached)" "(Detached)")) x))
-                   (split-string screen-ls "\n")))
-         (match-socket (find-if
-                        '(lambda (x)
-                          (string-match (concat "org-babel-session-" session) x))
-                        sockets)))
+         (sockets (delq
+		   nil
+                   (mapcar
+		    (lambda (x)
+		      (when (string-match (rx (or "(Attached)" "(Detached)")) x)
+			x))
+		    (split-string screen-ls "\n"))))
+         (match-socket (car
+			(delq
+			 nil
+			 (mapcar
+			  (lambda (x)
+			    (when (string-match
+				   (concat "org-babel-session-" session) x)
+			      x))
+			  sockets)))))
     (when match-socket (car (split-string match-socket)))))
 
 (defun org-babel-screen-session-write-temp-file (session body)

+ 1 - 0
lisp/ob-sh.el

@@ -28,6 +28,7 @@
 
 ;;; Code:
 (require 'ob)
+(require 'ob-comint)
 (require 'shell)
 (eval-when-compile
   (require 'cl))

+ 5 - 1
lisp/ob-sql.el

@@ -44,6 +44,9 @@
 
 ;;; Code:
 (require 'ob)
+(eval-when-compile (require 'cl))
+
+(declare-function org-table-import "org-table" (file arg))
 
 (defvar org-babel-default-header-args:sql '())
 
@@ -55,6 +58,7 @@
 called by `org-babel-execute-src-block'."
   (message "executing Sql source code block")
   (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
+	 (processed-params (org-babel-process-params params))
          (cmdline (cdr (assoc :cmdline params)))
          (engine (cdr (assoc :engine params)))
          (in-file (make-temp-file "org-babel-sql-in"))
@@ -63,7 +67,7 @@ called by `org-babel-execute-src-block'."
          (command (case (intern engine)
                     ('mysql (format "mysql %s -e \"source %s\" > %s"
                                     (or cmdline "") in-file out-file))
-                    (t (error "no support for the %s sql engine")))))
+                    (t (error "no support for the %s sql engine" engine)))))
     (with-temp-file in-file
       (insert (org-babel-expand-body:sql body params)))
     (message command)

+ 4 - 0
lisp/ob-sqlite.el

@@ -28,6 +28,10 @@
 
 ;;; Code:
 (require 'ob)
+(require 'ob-ref)
+
+(declare-function org-table-convert-region
+		  "org-table" (beg0 end0 &optional separator))
 
 (defvar org-babel-default-header-args:sqlite '())
 

+ 3 - 3
lisp/ob.el

@@ -62,7 +62,7 @@
 (declare-function org-babel-ref-resolve-reference "ob-ref" (ref &optional params))
 
 (defcustom org-confirm-babel-evaluate t
-  "Require confirmation before interactively evaluating code
+    "Require confirmation before interactively evaluating code
 blocks in Org-mode buffers.  The default value of this variable
 is t, meaning confirmation is required for any code block
 evaluation.  This variable can be set to nil to inhibit any
@@ -78,8 +78,8 @@ remove code block execution from C-c C-c as further protection
 against accidental code block evaluation.  The
 `org-babel-no-eval-on-ctrl-c-ctrl-c' variable can be used to
 remove code block execution from the C-c C-c keybinding."
-  :group 'org-babel
-  :type '(choice boolean function))
+    :group 'org-babel
+    :type '(choice boolean function))
 ;; don't allow this variable to be changed through file settings
 (put 'org-confirm-babel-evaluate 'safe-local-variable (lambda (x) (eq x t)))
 

+ 1 - 2
lisp/org.el

@@ -121,6 +121,7 @@
 (require 'ob-keys)
 
 ;; load languages based on value of `org-babel-load-languages'
+(defvar org-babel-load-languages)
 (defun org-babel-do-load-languages (sym value)
   "Load the languages defined in `org-babel-load-languages'."
   (set-default sym value)
@@ -128,10 +129,8 @@
 	  (let ((active (cdr pair)) (lang (symbol-name (car pair))))
 	    (if active
 		(progn
-		  (message "Activating %s..." lang)
 		  (require (intern (concat "ob-" lang))))
 	      (progn
-		(message "Disabling %s..." lang)
 		(funcall 'fmakunbound
 			 (intern (concat "org-babel-execute:" lang)))
 		(funcall 'fmakunbound