diff options
Diffstat (limited to 'lisp/org/ob-ruby.el')
-rw-r--r-- | lisp/org/ob-ruby.el | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/lisp/org/ob-ruby.el b/lisp/org/ob-ruby.el index 90956271cf5..5ed29f8891a 100644 --- a/lisp/org/ob-ruby.el +++ b/lisp/org/ob-ruby.el @@ -30,16 +30,17 @@ ;; - ruby and irb executables :: http://www.ruby-lang.org/ ;; ;; - ruby-mode :: Can be installed through ELPA, or from -;; http://github.com/eschulte/rinari/raw/master/util/ruby-mode.el +;; https://github.com/eschulte/rinari/raw/master/util/ruby-mode.el ;; ;; - inf-ruby mode :: Can be installed through ELPA, or from -;; http://github.com/eschulte/rinari/raw/master/util/inf-ruby.el +;; https://github.com/eschulte/rinari/raw/master/util/inf-ruby.el ;;; Code: (require 'ob) (require 'org-macs) -(declare-function run-ruby "ext:inf-ruby" (&optional command name)) +(declare-function run-ruby-or-pop-to-buffer "ext:inf-ruby" (command &optional name buffer)) +(declare-function inf-ruby-buffer "ext:inf-ruby" ()) (declare-function xmp "ext:rcodetools" (&optional option)) (defvar inf-ruby-default-implementation) @@ -51,7 +52,8 @@ (defvar org-babel-default-header-args:ruby '()) (defvar org-babel-ruby-command "ruby" - "Name of command to use for executing ruby code.") + "Name of command to use for executing ruby code. +It's possible to override it by using a header argument `:ruby'") (defcustom org-babel-ruby-hline-to "nil" "Replace hlines in incoming tables with this when translating to ruby." @@ -71,9 +73,12 @@ "Execute a block of Ruby code with Babel. This function is called by `org-babel-execute-src-block'." (let* ((session (org-babel-ruby-initiate-session - (cdr (assq :session params)))) + (cdr (assq :session params)) params)) (result-params (cdr (assq :result-params params))) (result-type (cdr (assq :result-type params))) + (org-babel-ruby-command + (or (cdr (assq :ruby params)) + org-babel-ruby-command)) (full-body (org-babel-expand-body:generic body params (org-babel-variable-assignments:ruby params))) (result (if (member "xmp" result-params) @@ -103,7 +108,8 @@ This function is called by `org-babel-execute-src-block'." (mapc (lambda (var) (insert var) (comint-send-input nil t) (org-babel-comint-wait-for-output session) - (sit-for .1) (goto-char (point-max))) var-lines)) + (sit-for .1) (goto-char (point-max))) + var-lines)) session)) (defun org-babel-load-session:ruby (session body params) @@ -147,17 +153,21 @@ Emacs-lisp table, otherwise return the results as a string." res) res))) -(defun org-babel-ruby-initiate-session (&optional session _params) +(defun org-babel-ruby-initiate-session (&optional session params) "Initiate a ruby session. If there is not a current inferior-process-buffer in SESSION then create one. Return the initialized session." (unless (string= session "none") (require 'inf-ruby) - (let* ((cmd (cdr (assoc inf-ruby-default-implementation - inf-ruby-implementations))) + (let* ((cmd (cdr (or (assq :ruby params) + (assoc inf-ruby-default-implementation + inf-ruby-implementations)))) (buffer (get-buffer (format "*%s*" session))) (session-buffer (or buffer (save-window-excursion - (run-ruby cmd session) + (run-ruby-or-pop-to-buffer + cmd (or session "ruby") + (unless session + (inf-ruby-buffer))) (current-buffer))))) (if (org-babel-comint-buffer-livep session-buffer) (progn (sit-for .25) session-buffer) @@ -263,6 +273,4 @@ return the value of the last statement in BODY, as elisp." (provide 'ob-ruby) - - ;;; ob-ruby.el ends here |