Browse Source

Merge branch 'master' into tangle

Eric Schulte 16 years ago
parent
commit
9e5f634135
6 changed files with 291 additions and 143 deletions
  1. 64 46
      lisp/langs/org-babel-R.el
  2. 48 16
      lisp/langs/org-babel-python.el
  3. 43 16
      lisp/langs/org-babel-ruby.el
  4. 23 13
      lisp/langs/org-babel-sh.el
  5. 18 15
      lisp/org-babel.el
  6. 95 37
      org-babel.org

+ 64 - 46
lisp/langs/org-babel-R.el

@@ -39,21 +39,24 @@ called by `org-babel-execute-src-block'."
   (message "executing R source code block...")
   (message "executing R source code block...")
   (save-window-excursion
   (save-window-excursion
     (let* ((vars (org-babel-ref-variables params))
     (let* ((vars (org-babel-ref-variables params))
+           (full-body (concat
+                       (mapconcat ;; define any variables
+                        (lambda (pair)
+                          (org-babel-R-assign-elisp (car pair) (cdr pair)))
+                        vars "\n") "\n" body "\n"))
            (result-params (split-string (or (cdr (assoc :results params)) "")))
            (result-params (split-string (or (cdr (assoc :results params)) "")))
            (result-type (cond ((member "output" result-params) 'output)
            (result-type (cond ((member "output" result-params) 'output)
                               ((member "value" result-params) 'value)
                               ((member "value" result-params) 'value)
                               (t 'value)))
                               (t 'value)))
            (session (org-babel-R-initiate-session (cdr (assoc :session params))))
            (session (org-babel-R-initiate-session (cdr (assoc :session params))))
            results)
            results)
-      ;; assign variables
-      (mapc (lambda (pair) (org-babel-R-assign-elisp session (car pair) (cdr pair))) vars)
       ;; ;;; debugging statements
       ;; ;;; debugging statements
       ;; (message (format "result-type=%S" result-type))
       ;; (message (format "result-type=%S" result-type))
       ;; (message (format "body=%S" body))
       ;; (message (format "body=%S" body))
       ;; (message (format "session=%S" session))
       ;; (message (format "session=%S" session))
       ;; (message (format "result-params=%S" result-params))
       ;; (message (format "result-params=%S" result-params))
       ;; evaluate body and convert the results to ruby
       ;; evaluate body and convert the results to ruby
-      (setq results (org-babel-R-evaluate session body result-type))
+      (setq results (org-babel-R-evaluate session full-body result-type))
       (setq results (if (member "scalar" result-params)
       (setq results (if (member "scalar" result-params)
                         results
                         results
                       (let ((tmp-file (make-temp-file "org-babel-R")))
                       (let ((tmp-file (make-temp-file "org-babel-R")))
@@ -77,62 +80,77 @@ called by `org-babel-execute-src-block'."
       (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
       (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
     (format "%S" s)))
     (format "%S" s)))
 
 
-(defun org-babel-R-assign-elisp (session name value)
-  "Read the elisp VALUE into a variable named NAME in the current
-R process in `org-babel-R-buffer'."
-  (unless session (error "No active R buffer"))
-  (org-babel-comint-input-command
-   session
-   (if (listp value)
-       (let ((transition-file (make-temp-file "org-babel-R-import")))
-	 ;; ensure VALUE has an orgtbl structure (depth of at least 2)
-	 (unless (listp (car value)) (setq value (list value)))
-	 (with-temp-file transition-file
-	   (insert (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field)))
-	   (insert "\n"))
-	 (format "%s <- read.table(\"%s\", header=FALSE, sep=\"\\t\", as.is=TRUE)"
-		 name transition-file))
-     (format "%s <- %s" name (org-babel-R-quote-tsv-field value)))))
+(defun org-babel-R-assign-elisp (name value)
+  "Read the elisp VALUE into a variable named NAME."
+  (if (listp value)
+      (let ((transition-file (make-temp-file "org-babel-R-import")))
+        ;; ensure VALUE has an orgtbl structure (depth of at least 2)
+        (unless (listp (car value)) (setq value (list value)))
+        (with-temp-file transition-file
+          (insert (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field)))
+          (insert "\n"))
+        (format "%s <- read.table(\"%s\", header=FALSE, sep=\"\\t\", as.is=TRUE)"
+                name transition-file))
+    (format "%s <- %s" name (org-babel-R-quote-tsv-field value))))
 
 
 (defun org-babel-R-initiate-session (session)
 (defun org-babel-R-initiate-session (session)
   "If there is not a current R process then create one."
   "If there is not a current R process then create one."
-  (setq session (or session "*R*"))
-  (if (org-babel-comint-buffer-livep session)
-      session
-    (save-window-excursion (R) (rename-buffer (if (bufferp session) (buffer-name session)
-                                                (if (stringp session) session (buffer-name)))) (current-buffer))))
+  (unless (string= session "none")
+    (setq session (or session "*R*"))
+    (if (org-babel-comint-buffer-livep session)
+        session
+      (save-window-excursion (R) (rename-buffer (if (bufferp session) (buffer-name session)
+                                                  (if (stringp session) session (buffer-name)))) (current-buffer)))))
 
 
 (defvar org-babel-R-eoe-indicator "'org_babel_R_eoe'")
 (defvar org-babel-R-eoe-indicator "'org_babel_R_eoe'")
 (defvar org-babel-R-eoe-output "[1] \"org_babel_R_eoe\"")
 (defvar org-babel-R-eoe-output "[1] \"org_babel_R_eoe\"")
+(defvar org-babel-R-wrapper-method "main <- function ()\n{\n%s\n}
+write.table(main(), file=\"%s\", sep=\"\\t\", na=\"nil\",row.names=FALSE, col.names=FALSE, quote=FALSE)")
 
 
 (defun org-babel-R-evaluate (buffer body result-type)
 (defun org-babel-R-evaluate (buffer body result-type)
   "Pass BODY to the R process in BUFFER.  If RESULT-TYPE equals
   "Pass BODY to the R process in BUFFER.  If RESULT-TYPE equals
 'output then return a list of the outputs of the statements in
 'output then return a list of the outputs of the statements in
 BODY, if RESULT-TYPE equals 'value then return the value of the
 BODY, if RESULT-TYPE equals 'value then return the value of the
 last statement in BODY."
 last statement in BODY."
-  (org-babel-comint-in-buffer buffer
-    (let* ((tmp-file (make-temp-file "org-babel-R"))
-           (last-value-eval
-            (format "write.table(.Last.value, file=\"%s\", sep=\"\\t\", na=\"nil\",row.names=FALSE, col.names=FALSE, quote=FALSE)"
-                    tmp-file))
-           (full-body (mapconcat #'org-babel-chomp (list body last-value-eval org-babel-R-eoe-indicator) "\n"))
-           (raw (org-babel-comint-with-output buffer org-babel-R-eoe-output nil
-                  (insert full-body) (inferior-ess-send-input)))
-           (results (let ((broke nil))
-                      (delete nil (mapcar (lambda (el)
-                                            (if (or broke
-                                                    (and (string-match (regexp-quote org-babel-R-eoe-output) el) (setq broke t)))
-                                                nil
-                                              (if (= (length el) 0)
+  (if (not session)
+      ;; external process evaluation
+      (let ((in-tmp-file (make-temp-file "R-in-functional-results"))
+            (out-tmp-file (make-temp-file "R-out-functional-results")))
+        (case result-type
+          (output
+           (with-temp-file in-tmp-file (insert body))
+           ;; (message "R --slave --no-save < '%s' > '%s'" in-tmp-file out-tmp-file)
+           (shell-command-to-string (format "R --slave --no-save < '%s' > '%s'" in-tmp-file out-tmp-file)))
+          (value
+           (with-temp-file in-tmp-file
+             (insert (format org-babel-R-wrapper-method body out-tmp-file)))
+           ;; (message "R --no-save < '%s'" in-tmp-file)
+           (shell-command (format "R --no-save < '%s'" in-tmp-file))))
+        (with-temp-buffer (insert-file-contents out-tmp-file) (buffer-string)))
+    ;; comint session evaluation
+    (org-babel-comint-in-buffer buffer
+      (let* ((tmp-file (make-temp-file "org-babel-R"))
+             (last-value-eval
+              (format "write.table(.Last.value, file=\"%s\", sep=\"\\t\", na=\"nil\",row.names=FALSE, col.names=FALSE, quote=FALSE)"
+                      tmp-file))
+             (full-body (mapconcat #'org-babel-chomp (list body last-value-eval org-babel-R-eoe-indicator) "\n"))
+             (raw (org-babel-comint-with-output buffer org-babel-R-eoe-output nil
+                    (insert full-body) (inferior-ess-send-input)))
+             (results (let ((broke nil))
+                        (delete nil (mapcar (lambda (el)
+                                              (if (or broke
+                                                      (and (string-match (regexp-quote org-babel-R-eoe-output) el) (setq broke t)))
                                                   nil
                                                   nil
-                                                (if (string-match comint-prompt-regexp el)
-                                                    (substring el (match-end 0))
-                                                  el))))
-                                          (mapcar #'org-babel-trim raw))))))
-      (case result-type
-        (output (org-babel-trim (mapconcat #'identity results "\n")))
-        (value (org-babel-trim (with-temp-buffer (insert-file-contents tmp-file) (buffer-string))))
-        (t (reverse results))))))
+                                                (if (= (length el) 0)
+                                                    nil
+                                                  (if (string-match comint-prompt-regexp el)
+                                                      (substring el (match-end 0))
+                                                    el))))
+                                            (mapcar #'org-babel-trim raw))))))
+        (case result-type
+          (output (org-babel-trim (mapconcat #'identity results "\n")))
+          (value (org-babel-trim (with-temp-buffer (insert-file-contents tmp-file) (buffer-string))))
+          (t (reverse results)))))))
 
 
 (provide 'org-babel-R)
 (provide 'org-babel-R)
 ;;; org-babel-R.el ends here
 ;;; org-babel-R.el ends here

+ 48 - 16
lisp/langs/org-babel-python.el

@@ -116,33 +116,65 @@ then create.  Return the initialized session."
       session)))
       session)))
 
 
 (defun org-babel-python-initiate-session (&optional session)
 (defun org-babel-python-initiate-session (&optional session)
-  (org-babel-python-session-buffer (org-babel-python-initiate-session-by-key session)))
+  (unless (string= session "none")
+    (org-babel-python-session-buffer (org-babel-python-initiate-session-by-key session))))
 
 
 (defvar org-babel-python-last-value-eval "_"
 (defvar org-babel-python-last-value-eval "_"
   "When evaluated by Python this returns the return value of the last statement.")
   "When evaluated by Python this returns the return value of the last statement.")
 (defvar org-babel-python-eoe-indicator "'org_babel_python_eoe'"
 (defvar org-babel-python-eoe-indicator "'org_babel_python_eoe'"
   "Used to indicate that evaluation is has completed.")
   "Used to indicate that evaluation is has completed.")
+(defvar org-babel-python-wrapper-method
+  "
+def main():
+%s
+
+open('%s', 'w').write( str(main()) )")
 
 
 (defun org-babel-python-evaluate (buffer body &optional result-type)
 (defun org-babel-python-evaluate (buffer body &optional result-type)
   "Pass BODY to the Python process in BUFFER.  If RESULT-TYPE equals
   "Pass BODY to the Python process in BUFFER.  If RESULT-TYPE equals
 'output then return a list of the outputs of the statements in
 'output then return a list of the outputs of the statements in
 BODY, if RESULT-TYPE equals 'value then return the value of the
 BODY, if RESULT-TYPE equals 'value then return the value of the
 last statement in BODY."
 last statement in BODY."
-  (org-babel-comint-in-buffer buffer
-    (let* ((full-body (mapconcat #'org-babel-trim
-                                 (list body org-babel-python-last-value-eval org-babel-python-eoe-indicator) "\n"))
-           (raw (org-babel-comint-with-output buffer org-babel-python-eoe-indicator t
-                  ;; for some reason python is fussy, and likes enters after every input
-                  (mapc (lambda (statement) (insert statement) (comint-send-input nil t))
-                        (split-string full-body "[\r\n]+"))))
-           (results (delete org-babel-python-eoe-indicator
-                            (cdr (member org-babel-python-eoe-indicator
-                                         (reverse (mapcar #'org-babel-trim raw)))))))
-      (setq results (mapcar #'org-babel-python-read-string results))
-      (org-babel-trim (case result-type
-                        (output (mapconcat #'identity (reverse (cdr results)) "\n"))
-                        (value (car results))
-                        (t (reverse results)))))))
+  (if (not session)
+      ;; external process evaluation
+      (save-window-excursion
+        (case result-type
+          (output
+           (with-temp-buffer
+             (insert body)
+             ;; (message "buffer=%s" (buffer-string)) ;; debugging
+             (shell-command-on-region (point-min) (point-max) "python" 'replace)
+             (buffer-string)))
+          (value
+           (let ((tmp-file (make-temp-file "python-functional-results")))
+             (with-temp-buffer
+               (insert (format org-babel-python-wrapper-method
+                               (let ((lines (split-string (org-remove-indentation (org-babel-trim body)) "[\r\n]")))
+                                 (concat
+                                  (mapconcat
+                                   (lambda (line) (format "\t%s" line))
+                                   (butlast lines) "\n")
+                                  (format "\n\treturn %s" (last lines))))
+                               tmp-file))
+               ;; (message "buffer=%s" (buffer-string)) ;; debugging
+               (shell-command-on-region (point-min) (point-max) "python"))
+             (with-temp-buffer (insert-file-contents tmp-file) (buffer-string))))))
+    ;; comint session evaluation
+    (org-babel-comint-in-buffer buffer
+      (let* ((full-body (mapconcat #'org-babel-trim
+                                   (list body org-babel-python-last-value-eval org-babel-python-eoe-indicator) "\n"))
+             (raw (org-babel-comint-with-output buffer org-babel-python-eoe-indicator t
+                    ;; for some reason python is fussy, and likes enters after every input
+                    (mapc (lambda (statement) (insert statement) (comint-send-input nil t))
+                          (split-string full-body "[\r\n]+"))))
+             (results (delete org-babel-python-eoe-indicator
+                              (cdr (member org-babel-python-eoe-indicator
+                                           (reverse (mapcar #'org-babel-trim raw)))))))
+        (setq results (mapcar #'org-babel-python-read-string results))
+        (org-babel-trim (case result-type
+                          (output (mapconcat #'identity (reverse (cdr results)) "\n"))
+                          (value (car results))
+                          (t (reverse results))))))))
 
 
 (defun org-babel-python-read-string (string)
 (defun org-babel-python-read-string (string)
   "Strip 's from around ruby string"
   "Strip 's from around ruby string"

+ 43 - 16
lisp/langs/org-babel-ruby.el

@@ -104,33 +104,60 @@ Emacs-lisp table, otherwise return the results as a string."
 (defun org-babel-ruby-initiate-session (&optional session)
 (defun org-babel-ruby-initiate-session (&optional session)
   "If there is not a current inferior-process-buffer in SESSION
   "If there is not a current inferior-process-buffer in SESSION
 then create.  Return the initialized session."
 then create.  Return the initialized session."
-  (let ((session-buffer (save-window-excursion (run-ruby nil session) (current-buffer))))
-    (if (org-babel-comint-buffer-livep session-buffer)
-        session-buffer
-      (sit-for .5)
-      (org-babel-ruby-initiate-session session))))
+  (unless (string= session "none")
+    (let ((session-buffer (save-window-excursion (run-ruby nil session) (current-buffer))))
+      (if (org-babel-comint-buffer-livep session-buffer)
+          session-buffer
+        (sit-for .5)
+        (org-babel-ruby-initiate-session session)))))
 
 
 (defvar org-babel-ruby-last-value-eval "_"
 (defvar org-babel-ruby-last-value-eval "_"
   "When evaluated by Ruby this returns the return value of the last statement.")
   "When evaluated by Ruby this returns the return value of the last statement.")
 (defvar org-babel-ruby-eoe-indicator ":org_babel_ruby_eoe"
 (defvar org-babel-ruby-eoe-indicator ":org_babel_ruby_eoe"
   "Used to indicate that evaluation is has completed.")
   "Used to indicate that evaluation is has completed.")
+(defvar org-babel-ruby-wrapper-method
+  "
+def main()
+%s
+end
+results = main()
+File.open('%s', 'w'){ |f| f.write((results.class == String) ? results : results.inspect) }
+")
 
 
 (defun org-babel-ruby-evaluate (buffer body &optional result-type)
 (defun org-babel-ruby-evaluate (buffer body &optional result-type)
   "Pass BODY to the Ruby process in BUFFER.  If RESULT-TYPE equals
   "Pass BODY to the Ruby process in BUFFER.  If RESULT-TYPE equals
 'output then return a list of the outputs of the statements in
 'output then return a list of the outputs of the statements in
 BODY, if RESULT-TYPE equals 'value then return the value of the
 BODY, if RESULT-TYPE equals 'value then return the value of the
 last statement in BODY."
 last statement in BODY."
-  (let* ((full-body (mapconcat #'org-babel-chomp
-                               (list body org-babel-ruby-last-value-eval org-babel-ruby-eoe-indicator) "\n"))
-         (raw (org-babel-comint-with-output buffer org-babel-ruby-eoe-indicator t
-                (insert full-body) (comint-send-input nil t)))
-         (results (cdr (member org-babel-ruby-eoe-indicator
-                               (reverse (mapcar #'org-babel-ruby-read-string
-                                                (mapcar #'org-babel-trim raw)))))))
-    (case result-type
-      (output (mapconcat #'identity (reverse (cdr results)) "\n"))
-      (value (car results))
-      (t (reverse results)))))
+  (if (not session)
+      ;; external process evaluation
+      (save-window-excursion
+        (case result-type
+          (output
+           (with-temp-buffer
+             (insert body)
+             ;; (message "buffer=%s" (buffer-string)) ;; debugging
+             (shell-command-on-region (point-min) (point-max) "ruby" 'replace)
+             (buffer-string)))
+          (value
+           (let ((tmp-file (make-temp-file "ruby-functional-results")))
+             (with-temp-buffer
+               (insert (format org-babel-ruby-wrapper-method body tmp-file))
+               ;; (message "buffer=%s" (buffer-string)) ;; debugging
+               (shell-command-on-region (point-min) (point-max) "ruby"))
+             (with-temp-buffer (insert-file-contents tmp-file) (buffer-string))))))
+    ;; comint session evaluation
+    (message "session evaluation")
+    (let* ((full-body (mapconcat #'org-babel-chomp
+                                 (list body org-babel-ruby-last-value-eval org-babel-ruby-eoe-indicator) "\n"))
+           (raw (org-babel-comint-with-output buffer org-babel-ruby-eoe-indicator t
+                  (insert full-body) (comint-send-input nil t)))
+           (results (cdr (member org-babel-ruby-eoe-indicator
+                                 (reverse (mapcar #'org-babel-ruby-read-string
+                                                  (mapcar #'org-babel-trim raw)))))))
+      (case result-type
+        (output (mapconcat #'identity (reverse (cdr results)) "\n"))
+        (value (car results))))))
 
 
 (defun org-babel-ruby-read-string (string)
 (defun org-babel-ruby-read-string (string)
   "Strip \\\"s from around ruby string"
   "Strip \\\"s from around ruby string"

+ 23 - 13
lisp/langs/org-babel-sh.el

@@ -120,7 +120,8 @@ then create.  Return the initialized session."
       session)))
       session)))
 
 
 (defun org-babel-sh-initiate-session (&optional session)
 (defun org-babel-sh-initiate-session (&optional session)
-  (org-babel-sh-session-buffer (org-babel-sh-initiate-session-by-key session)))
+  (unless (string= session "none")
+    (org-babel-sh-session-buffer (org-babel-sh-initiate-session-by-key session))))
 
 
 (defvar org-babel-sh-eoe-indicator "echo 'org_babel_sh_eoe'"
 (defvar org-babel-sh-eoe-indicator "echo 'org_babel_sh_eoe'"
   "Used to indicate that evaluation is has completed.")
   "Used to indicate that evaluation is has completed.")
@@ -132,18 +133,27 @@ then create.  Return the initialized session."
 'output then return a list of the outputs of the statements in
 'output then return a list of the outputs of the statements in
 BODY, if RESULT-TYPE equals 'value then return the value of the
 BODY, if RESULT-TYPE equals 'value then return the value of the
 last statement in BODY."
 last statement in BODY."
-  (let* ((full-body (mapconcat #'org-babel-chomp
-                               (list body org-babel-sh-eoe-indicator) "\n"))
-         (raw (org-babel-comint-with-output buffer org-babel-sh-eoe-output nil
-                (insert full-body) (comint-send-input nil t)))
-         (results (cdr (member org-babel-sh-eoe-output
-                                    (reverse (mapcar #'org-babel-sh-strip-weird-long-prompt
-                                                     (mapcar #'org-babel-trim raw)))))))
-    ;; (message (replace-regexp-in-string "%" "%%" (format "processed-results=%S" results))) ;; debugging
-    (or (case result-type
-          (output (org-babel-trim (mapconcat #'org-babel-trim (reverse results) "\n")))
-          (value (car results))
-          (t (reverse results))) "")))
+  (if (not session)
+      ;; external process evaluation
+      (save-window-excursion
+        (with-temp-buffer ;; TODO: figure out how to return non-output values from shell scripts
+          (insert body)
+          ;; (message "buffer=%s" (buffer-string)) ;; debugging
+          (shell-command-on-region (point-min) (point-max) "sh" 'replace)
+          (buffer-string)))
+    ;; comint session evaluation
+    (let* ((full-body (mapconcat #'org-babel-chomp
+                                 (list body org-babel-sh-eoe-indicator) "\n"))
+           (raw (org-babel-comint-with-output buffer org-babel-sh-eoe-output nil
+                  (insert full-body) (comint-send-input nil t)))
+           (results (cdr (member org-babel-sh-eoe-output
+                                 (reverse (mapcar #'org-babel-sh-strip-weird-long-prompt
+                                                  (mapcar #'org-babel-trim raw)))))))
+      ;; (message (replace-regexp-in-string "%" "%%" (format "processed-results=%S" results))) ;; debugging
+      (or (case result-type
+            (output (org-babel-trim (mapconcat #'org-babel-trim (reverse results) "\n")))
+            (value (car results))
+            (t (reverse results))) ""))))
 
 
 (defun org-babel-sh-strip-weird-long-prompt (string)
 (defun org-babel-sh-strip-weird-long-prompt (string)
   (while (string-match "^% +[\r\n$]+ *" string)
   (while (string-match "^% +[\r\n$]+ *" string)

+ 18 - 15
lisp/org-babel.el

@@ -49,7 +49,7 @@ then run `org-babel-pop-to-session'."
 
 
 (add-hook 'org-metadown-hook 'org-babel-pop-to-session-maybe)
 (add-hook 'org-metadown-hook 'org-babel-pop-to-session-maybe)
 
 
-(defvar org-babel-default-header-args '()
+(defvar org-babel-default-header-args '((:session . "none"))
   "Default arguments to use when evaluating a source block.")
   "Default arguments to use when evaluating a source block.")
 
 
 (defvar org-babel-default-inline-header-args '((:results . "silent") (:exports . "results"))
 (defvar org-babel-default-inline-header-args '((:results . "silent") (:exports . "results"))
@@ -58,9 +58,6 @@ then run `org-babel-pop-to-session'."
 (defvar org-babel-src-block-regexp nil
 (defvar org-babel-src-block-regexp nil
   "Regexp used to test when inside of a org-babel src-block")
   "Regexp used to test when inside of a org-babel src-block")
 
 
-(defvar org-babel-named-src-block-regexp nil
-  "Regexp used to match an org-babel src-block with srcname")
-
 (defvar org-babel-inline-src-block-regexp nil
 (defvar org-babel-inline-src-block-regexp nil
   "Regexp used to test when on an inline org-babel src-block")
   "Regexp used to test when on an inline org-babel src-block")
 
 
@@ -77,9 +74,6 @@ then run `org-babel-pop-to-session'."
 		"\\)[ \t]*"
 		"\\)[ \t]*"
                 "\\([ \t]+\\([^\n]+\\)\\)?\n" ;; match header arguments
                 "\\([ \t]+\\([^\n]+\\)\\)?\n" ;; match header arguments
                 "\\([^\000]+?\\)#\\+end_src"))
                 "\\([^\000]+?\\)#\\+end_src"))
-  (setq org-babel-named-src-block-regexp
-	(concat "#\\+srcname:[ \t]*\\([^ \t\n]+\\)[ \t\n]*"
-		org-babel-src-block-regexp))
   (setq org-babel-inline-src-block-regexp
   (setq org-babel-inline-src-block-regexp
 	(concat "src_\\("
 	(concat "src_\\("
 		(mapconcat 'regexp-quote value "\\|")
 		(mapconcat 'regexp-quote value "\\|")
@@ -165,7 +159,7 @@ the header arguments specified at the source code block."
          (params (org-combine-plists params (third info)))
          (params (org-combine-plists params (third info)))
          (cmd (intern (concat "org-babel-execute:" lang)))
          (cmd (intern (concat "org-babel-execute:" lang)))
          result)
          result)
-    ;; (message (format "params=%S" params)) ;; debugging statement
+    ;; (message "params=%S" params) ;; debugging statement
     (unless (member lang org-babel-interpreters)
     (unless (member lang org-babel-interpreters)
       (error "Language is not in `org-babel-interpreters': %s" lang))
       (error "Language is not in `org-babel-interpreters': %s" lang))
     (setq result (funcall cmd body params))
     (setq result (funcall cmd body params))
@@ -242,8 +236,9 @@ of the following form.  (language body header-arguments-alist)"
   "Parse a string of header arguments returning an alist."
   "Parse a string of header arguments returning an alist."
   (delq nil
   (delq nil
         (mapcar
         (mapcar
-         (lambda (arg) (if (string-match "\\([^ \f\t\n\r\v]+\\)[ \f\t\n\r\v]*\\([^ \f\t\n\r\v]+.*\\)" arg)
-                           (cons (intern (concat ":" (match-string 1 arg))) (org-babel-chomp (match-string 2 arg)))))
+         (lambda (arg) (if (string-match "\\([^ \f\t\n\r\v]+\\)[ \f\t\n\r\v]+\\([^ \f\t\n\r\v]+.*\\)" arg)
+                           (cons (intern (concat ":" (match-string 1 arg))) (org-babel-chomp (match-string 2 arg)))
+                         (cons (intern (concat ":" arg)) nil)))
          (split-string (concat " " arg-string) "[ \f\t\n\r\v]+:" t))))
          (split-string (concat " " arg-string) "[ \f\t\n\r\v]+:" t))))
 
 
 (defun org-babel-where-is-src-block-head ()
 (defun org-babel-where-is-src-block-head ()
@@ -269,6 +264,15 @@ If the point is not on a source block then return nil."
         (goto-char top) (looking-at org-babel-src-block-regexp)
         (goto-char top) (looking-at org-babel-src-block-regexp)
         (point))))))
         (point))))))
 
 
+(defun org-babel-goto-named-source-block (&optional name)
+  "Go to a named source-code block."
+  (interactive "ssource-block name: ")
+  (let ((point (org-babel-find-named-block name)))
+    (if point
+        ;; taken from `org-open-at-point'
+        (progn (goto-char point) (org-show-context))
+      (message "source-code block '%s' not found in this buffer" name))))
+
 (defun org-babel-find-named-block (name)
 (defun org-babel-find-named-block (name)
   "Find a named source-code block.
   "Find a named source-code block.
 Return the location of the source block identified by
 Return the location of the source block identified by
@@ -277,11 +281,10 @@ according to org-babel-named-src-block-regexp."
   (save-excursion
   (save-excursion
     (let ((case-fold-search t)
     (let ((case-fold-search t)
 	  (regexp (org-babel-named-src-block-regexp-for-name name)) msg)
 	  (regexp (org-babel-named-src-block-regexp-for-name name)) msg)
-      (unless (or (re-search-forward regexp nil t)
-		  (re-search-backward regexp nil t))
-	(progn (setq msg (format "source-code block '%s' not found in this buffer" name))
-	       (message msg) (error msg))))
-    (point)))
+      (goto-char (point-min))
+      (when (or (re-search-forward regexp nil t)
+                (re-search-backward regexp nil t))
+        (match-beginning 0)))))
 
 
 (defun org-babel-find-named-result (name)
 (defun org-babel-find-named-result (name)
   "Return the location of the result named NAME in the current
   "Return the location of the result named NAME in the current

+ 95 - 37
org-babel.org

@@ -114,14 +114,7 @@ table, allowing the test suite to be run be evaluation of the table
 and the results to be collected in the same table.
 and the results to be collected in the same table.
 
 
 
 
-* Tasks [25/42]
-** TODO add a function to jump to a source-block by name
-   I've had an initial stab at that in org-babel-find-named-block
-   (library-of-babel branch).
-
-   At the same time I introduced org-babel-named-src-block-regexp, to
-   match src-blocks with srcname.
-
+* Tasks [27/42]
 ** TODO support for working with =*Org Edit Src Example*= buffers [1/4]
 ** TODO support for working with =*Org Edit Src Example*= buffers [1/4]
 *** TODO set buffer-local-process variables appropriately [DED]
 *** TODO set buffer-local-process variables appropriately [DED]
     I think something like this would be great. You've probably
     I think something like this would be great. You've probably
@@ -497,28 +490,6 @@ tabel
 
 
 Another example is in the [[*operations%20in%20on%20tables][grades example]].
 Another example is in the [[*operations%20in%20on%20tables][grades example]].
 
 
-** PROPOSED add =:none= session argument (for purely functional execution)
-This would allow source blocks to be run in their own new process
-
-- These blocks could then also be run in the background (since we can
-  detach and just wait for the process to signal that it has terminated)
-- We wouldn't be drowning in session buffers after running the tests
-- we can re-use much of the session code to run in a more /functional/
-  mode
-
-While session provide a lot of cool features, like persistent
-environments, [[* DONE function to bring up inferior-process buffer][pop-to-session]], and hints at exportation for
-org-babel-tangle, they also have some down sides and I'm thinking that
-session-based execution maybe shouldn't be the default behavior.
-
-Down-sides to sessions
-- *much* more complicated than functional evaluation
-  - maintaining the state of the session has weird issues
-  - waiting for evaluation to finish
-  - prompt issues like [[* TODO weird escaped characters in shell prompt break shell evaluation][shell-prompt-escapes-bug]]
-- can't run in background
-- litter emacs with session buffers
-
 ** PROPOSED Are we happy with current behaviour regarding vector/scalar output?
 ** PROPOSED Are we happy with current behaviour regarding vector/scalar output?
 This simple example of multilingual chaining produces vector output if
 This simple example of multilingual chaining produces vector output if
 there are spaces in the message and scalar otherwise.
 there are spaces in the message and scalar otherwise.
@@ -768,6 +739,88 @@ $0
 [[file:snippets/org-mode/sb][sb -- snippet]]
 [[file:snippets/org-mode/sb][sb -- snippet]]
 
 
 waiting for guidance from those more familiar with yasnippets
 waiting for guidance from those more familiar with yasnippets
+** DONE add a function to jump to a source-block by name
+   I've had an initial stab at that in org-babel-find-named-block
+   (library-of-babel branch).
+
+   At the same time I introduced org-babel-named-src-block-regexp, to
+   match src-blocks with srcname.
+
+   This is now working with the command
+   `org-babel-goto-named-source-block', all we need is a good key
+   binding.
+
+** DONE add =:none= session argument (for purely functional execution) [4/4]
+This would allow source blocks to be run in their own new process
+
+- These blocks could then also be run in the background (since we can
+  detach and just wait for the process to signal that it has terminated)
+- We wouldn't be drowning in session buffers after running the tests
+- we can re-use much of the session code to run in a more /functional/
+  mode
+
+While session provide a lot of cool features, like persistent
+environments, [[* DONE function to bring up inferior-process buffer][pop-to-session]], and hints at exportation for
+org-babel-tangle, they also have some down sides and I'm thinking that
+session-based execution maybe shouldn't be the default behavior.
+
+Down-sides to sessions
+- *much* more complicated than functional evaluation
+  - maintaining the state of the session has weird issues
+  - waiting for evaluation to finish
+  - prompt issues like [[* TODO weird escaped characters in shell prompt break shell evaluation][shell-prompt-escapes-bug]]
+- can't run in background
+- litter emacs with session buffers
+
+*** DONE ruby
+
+#+srcname: ruby-task-no-session
+#+begin_src ruby :results replace output
+puts :eric
+puts :schulte
+[1, 2, 3]
+#+end_src
+
+#+resname: ruby-task-no-session
+| "eric"    |
+| "schulte" |
+*** DONE python
+
+#+srcname: task-python-none-session
+#+begin_src python :session none :results replace value
+print 'something'
+print 'output'
+[1, 2, 3]
+#+end_src
+
+#+resname: task-python-none-session
+| 1 | 2 | 3 |
+
+*** DONE sh
+
+#+srcname: task-session-none-sh
+#+begin_src sh :results replace
+echo "first"
+echo "second"
+#+end_src
+
+#+resname: task-session-none-sh
+| "first"  |
+| "second" |
+
+*** DONE R
+
+#+srcname: task-no-session-R
+#+begin_src R :results replace output
+a <- 8
+b <- 9
+a + b
+b - a
+#+end_src
+
+#+resname: task-no-session-R
+| "[1]" | 17 |
+| "[1]" |  1 |
 
 
 ** DONE fully purge org-babel-R of direct comint interaction
 ** DONE fully purge org-babel-R of direct comint interaction
 try to remove all code under the [[file:lisp/org-babel-R.el::functions%20for%20evaluation%20of%20R%20code][;; functions for evaluation of R code]] line
 try to remove all code under the [[file:lisp/org-babel-R.el::functions%20for%20evaluation%20of%20R%20code][;; functions for evaluation of R code]] line
@@ -1775,7 +1828,12 @@ This could probably be added to [[file:lisp/org-babel-script.el][org-babel-scrip
 (see [[* file result types][file result types]])
 (see [[* file result types][file result types]])
 
 
 
 
-* Bugs [16/20]
+* Bugs [16/21]
+** PROPOSED external shell execution can't isolate return values
+I have no idea how to do this as of yet.  The result is that when
+shell functions are run w/o a session there is no difference between
+the =output= and =value= result arguments.
+
 ** TODO weird escaped characters in shell prompt break shell evaluation
 ** TODO weird escaped characters in shell prompt break shell evaluation
    E.g. this doesn't work. Should the shell sessions set a sane prompt
    E.g. this doesn't work. Should the shell sessions set a sane prompt
    when they start up? Or is it a question of altering
    when they start up? Or is it a question of altering
@@ -2368,35 +2426,35 @@ triv.class.name
 ** sessions
 ** sessions
 
 
 #+srcname: set-ruby-session-var
 #+srcname: set-ruby-session-var
-#+begin_src ruby :session rb-new-testing :results silent
+#+begin_src ruby :session :results silent
 var = [1, 2, 3]
 var = [1, 2, 3]
 :set
 :set
 #+end_src
 #+end_src
 
 
 #+srcname: get-ruby-session-var
 #+srcname: get-ruby-session-var
-#+begin_src ruby :session rb-new-testing :results silent
+#+begin_src ruby :session :results silent
 var.size
 var.size
 #+end_src
 #+end_src
 
 
 #+srcname: set-python-session-var
 #+srcname: set-python-session-var
-#+begin_src python :session py-testing
+#+begin_src python :session
 var=4
 var=4
 'set'
 'set'
 #+end_src
 #+end_src
 
 
 #+srcname: get-python-session-var
 #+srcname: get-python-session-var
-#+begin_src python :session py-testing
+#+begin_src python :session
 var
 var
 #+end_src
 #+end_src
 
 
 #+srcname: set-R-session-var
 #+srcname: set-R-session-var
-#+begin_src R :session R-testing
+#+begin_src R :session
 a <- 5
 a <- 5
 'set'
 'set'
 #+end_src
 #+end_src
 
 
 #+srcname: get-R-session-var
 #+srcname: get-R-session-var
-#+begin_src R :session R-testing
+#+begin_src R :session
 a
 a
 #+end_src
 #+end_src