Browse Source

cleaned up ruby

Eric Schulte 16 years ago
parent
commit
2fd494477b
2 changed files with 36 additions and 30 deletions
  1. 24 25
      lisp/langs/org-babel-ruby.el
  2. 12 5
      org-babel.org

+ 24 - 25
lisp/langs/org-babel-ruby.el

@@ -129,32 +129,31 @@ File.open('%s', 'w'){ |f| f.write((results.class == String) ? results : results.
 '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 result)
-    (if (not session)
-        ;; external process evaluation
-        (save-window-excursion
-          (with-temp-buffer
-            (case result-type
-              (output
-               (insert body)
+  (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
                ;; (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")))
-                 (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
-      (setq raw (org-babel-comint-with-output buffer org-babel-ruby-eoe-indicator t
-                  (insert full-body) (comint-send-input nil t)))
-      (setq results
-            (cdr (member org-babel-ruby-eoe-indicator
-                         (reverse (mapcar #'org-babel-ruby-read-string
-                                          (mapcar #'org-babel-trim raw))))))
+               (shell-command-on-region (point-min) (point-max) "ruby"))
+             (with-temp-buffer (insert-file-contents tmp-file) (buffer-string))))))
+    ;; comint 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
       (case result-type
         (output (mapconcat #'identity (reverse (cdr results)) "\n"))
         (output (mapconcat #'identity (reverse (cdr results)) "\n"))
         (value (car results))))))
         (value (car results))))))

+ 12 - 5
org-babel.org

@@ -522,20 +522,27 @@ Down-sides to sessions
 *** DONE ruby
 *** DONE ruby
 
 
 #+srcname: ruby-task-no-session
 #+srcname: ruby-task-no-session
-#+begin_src ruby :results replace value
+#+begin_src ruby :results replace output
 puts :eric
 puts :eric
 puts :schulte
 puts :schulte
 [1, 2, 3]
 [1, 2, 3]
 #+end_src
 #+end_src
 
 
 #+resname: ruby-task-no-session
 #+resname: ruby-task-no-session
-| 1 | 2 | 3 |
-
-*** TODO R
+| "eric"    |
+| "schulte" |
+*** TODO python
 
 
+#+srcname: task-python-none-session
+#+begin_src python :results replace
+print 'something'
+print 'output'
+[1, 2, 3]
+#+end_src
 
 
-*** TODO python
 *** TODO sh
 *** TODO sh
+
+*** TODO R
 ** 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.