Bladeren bron

started working on ruby 'script' execution

Eric Schulte 16 jaren geleden
bovenliggende
commit
9c70974391
2 gewijzigde bestanden met toevoegingen van 13 en 14 verwijderingen
  1. 12 9
      lisp/org-babel-script.el
  2. 1 5
      org-babel.org

+ 12 - 9
lisp/org-babel-script.el

@@ -71,9 +71,14 @@ executed through org-babel."
     (cond
      ((member "script" results-params) ;; collect all output
       (let ((tmp-file (make-temp-file "org-babel-R-script-output")))
-        (org-babel-comint-input-command org-babel-R-buffer (format "sink(%S)" tmp-file))
-        (org-babel-comint-input-command org-babel-R-buffer body)
-        (org-babel-comint-input-command org-babel-R-buffer "sink()")
+        ;; this is totally not working well
+        (org-babel-script-input-command interpreter (concat
+                                                     "org_babel_io_holder = $stdout;"
+                                                     (format "org_babel_tmp_file_holder = File.open('%s', 'w'); "  tmp-file)
+                                                     "$stdout = org_babel_tmp_file_holder; "
+                                                     body
+                                                     "org_babel_tmp_file_holder.flush; "
+                                                     "$stdout = org_babel_io_holder;"))
         (with-temp-buffer (insert-file-contents tmp-file) (buffer-string))))
      ((member "last" results-params) ;; the value of the last statement
       (org-babel-script-input-command interpreter full-body)
@@ -126,14 +131,12 @@ then create.  Return the initialized session."
                                              (current-buffer))))))
 
 (defun org-babel-script-input-command (interpreter cmd)
-  (setq cmd (org-babel-chomp cmd))
-  (message (format "input = %S" cmd))
-  (org-babel-comint-input-command (eval (org-babel-script-session interpreter)) cmd))
+  (org-babel-comint-input-command
+   (eval (org-babel-script-session interpreter)) (org-babel-chomp cmd)))
 
 (defun org-babel-script-command-to-string (interpreter cmd)
-  (setq cmd (org-babel-chomp cmd))
-  (message (format "string = %S" cmd))
-  (org-babel-comint-command-to-string (eval (org-babel-script-session interpreter)) cmd))
+  (org-babel-comint-command-to-string
+   (eval (org-babel-script-session interpreter)) (org-babel-chomp cmd)))
 
 (provide 'org-babel-script)
 ;;; org-babel-script.el ends here

+ 1 - 5
org-babel.org

@@ -525,17 +525,13 @@ twoentyseven
 - [ ] rename buffer after session
 
 #+srcname: ruby-use-last-output
-#+begin_src ruby :results replace last
+#+begin_src ruby :results replace script
 a = 2
 b = 4
 c = a + b
 c * (a + b)
 #+end_src
 
-#+resname: ruby-use-last-output
-: 36
-
-
 **** TODO Python
 
 **** TODO Shells