forked from mirrors/org-mode
ob-ruby: Fix ruby tests
* lisp/ob-ruby.el (org-babel-ruby-prompt): (org-babel-ruby-define-prompt): New variables used to set appropriate unique prompt and disable echo in session. (org-babel-ruby-initiate-session): Setup prompt and echo during session initialization. (org-babel-ruby-evaluate): Rely on `org-babel-ruby-initiate-session' to setup prompt and echo. Re-setting the prompt back after every evaluation can be tricky because of async nature of the prompt, so it is now dropped.
This commit is contained in:
parent
c905565fa8
commit
430c72924c
|
@ -152,10 +152,16 @@ Emacs-lisp table, otherwise return the results as a string."
|
||||||
(let ((res (org-babel-script-escape results)))
|
(let ((res (org-babel-script-escape results)))
|
||||||
(if (listp res)
|
(if (listp res)
|
||||||
(mapcar (lambda (el) (if (not el)
|
(mapcar (lambda (el) (if (not el)
|
||||||
org-babel-ruby-nil-to el))
|
org-babel-ruby-nil-to el))
|
||||||
res)
|
res)
|
||||||
res)))
|
res)))
|
||||||
|
|
||||||
|
(defvar org-babel-ruby-prompt "_org_babel_ruby_prompt "
|
||||||
|
"String used for unique prompt.")
|
||||||
|
|
||||||
|
(defvar org-babel-ruby-define-prompt
|
||||||
|
(format "IRB.conf[:PROMPT][:CUSTOM] = { :PROMPT_I => \"%s\" }" org-babel-ruby-prompt))
|
||||||
|
|
||||||
(defun org-babel-ruby-initiate-session (&optional session params)
|
(defun org-babel-ruby-initiate-session (&optional session params)
|
||||||
"Initiate a ruby session.
|
"Initiate a ruby session.
|
||||||
If there is not a current inferior-process-buffer in SESSION
|
If there is not a current inferior-process-buffer in SESSION
|
||||||
|
@ -166,6 +172,7 @@ then create one. Return the initialized session."
|
||||||
(assoc inf-ruby-default-implementation
|
(assoc inf-ruby-default-implementation
|
||||||
inf-ruby-implementations))))
|
inf-ruby-implementations))))
|
||||||
(buffer (get-buffer (format "*%s*" session)))
|
(buffer (get-buffer (format "*%s*" session)))
|
||||||
|
(new-session? (not buffer))
|
||||||
(session-buffer (or buffer (save-window-excursion
|
(session-buffer (or buffer (save-window-excursion
|
||||||
(run-ruby-or-pop-to-buffer
|
(run-ruby-or-pop-to-buffer
|
||||||
(if (functionp command)
|
(if (functionp command)
|
||||||
|
@ -176,16 +183,30 @@ then create one. Return the initialized session."
|
||||||
(inf-ruby-buffer)))
|
(inf-ruby-buffer)))
|
||||||
(current-buffer)))))
|
(current-buffer)))))
|
||||||
(if (org-babel-comint-buffer-livep session-buffer)
|
(if (org-babel-comint-buffer-livep session-buffer)
|
||||||
(progn (sit-for .25) session-buffer)
|
(progn
|
||||||
|
(sit-for .25)
|
||||||
|
;; Setup machine-readable prompt: no echo, prompts matching
|
||||||
|
;; uniquely by regexp.
|
||||||
|
(when new-session?
|
||||||
|
(with-current-buffer session-buffer
|
||||||
|
(setq-local comint-prompt-regexp (concat "^" org-babel-ruby-prompt))
|
||||||
|
(insert org-babel-ruby-define-prompt ";")
|
||||||
|
(insert "_org_prompt_mode=conf.prompt_mode;conf.prompt_mode=:CUSTOM;")
|
||||||
|
(insert "conf.echo=false")
|
||||||
|
(comint-send-input nil t)))
|
||||||
|
session-buffer)
|
||||||
(sit-for .5)
|
(sit-for .5)
|
||||||
(org-babel-ruby-initiate-session session)))))
|
(org-babel-ruby-initiate-session session)))))
|
||||||
|
|
||||||
(defvar org-babel-ruby-eoe-indicator ":org_babel_ruby_eoe"
|
(defvar org-babel-ruby-eoe-indicator ":org_babel_ruby_eoe"
|
||||||
"String to indicate that evaluation has completed.")
|
"String to indicate that evaluation has completed.")
|
||||||
|
|
||||||
(defvar org-babel-ruby-f-write
|
(defvar org-babel-ruby-f-write
|
||||||
"File.open('%s','w'){|f| f.write((_.class == String) ? _ : _.inspect)}")
|
"File.open('%s','w'){|f| f.write((_.class == String) ? _ : _.inspect)}")
|
||||||
|
|
||||||
(defvar org-babel-ruby-pp-f-write
|
(defvar org-babel-ruby-pp-f-write
|
||||||
"File.open('%s','w'){|f| $stdout = f; pp(results); $stdout = orig_out}")
|
"File.open('%s','w'){|f| $stdout = f; pp(results); $stdout = orig_out}")
|
||||||
|
|
||||||
(defvar org-babel-ruby-wrapper-method
|
(defvar org-babel-ruby-wrapper-method
|
||||||
"
|
"
|
||||||
def main()
|
def main()
|
||||||
|
@ -194,6 +215,7 @@ end
|
||||||
results = main()
|
results = main()
|
||||||
File.open('%s', 'w'){ |f| f.write((results.class == String) ? results : results.inspect) }
|
File.open('%s', 'w'){ |f| f.write((results.class == String) ? results : results.inspect) }
|
||||||
")
|
")
|
||||||
|
|
||||||
(defvar org-babel-ruby-pp-wrapper-method
|
(defvar org-babel-ruby-pp-wrapper-method
|
||||||
"
|
"
|
||||||
require 'pp'
|
require 'pp'
|
||||||
|
@ -237,7 +259,6 @@ return the value of the last statement in BODY, as elisp."
|
||||||
(org-babel-comint-with-output
|
(org-babel-comint-with-output
|
||||||
(buffer org-babel-ruby-eoe-indicator t eoe-string)
|
(buffer org-babel-ruby-eoe-indicator t eoe-string)
|
||||||
(insert eoe-string) (comint-send-input nil t))
|
(insert eoe-string) (comint-send-input nil t))
|
||||||
;; Now we can start the evaluation.
|
|
||||||
(mapconcat
|
(mapconcat
|
||||||
#'identity
|
#'identity
|
||||||
(butlast
|
(butlast
|
||||||
|
@ -246,14 +267,9 @@ return the value of the last statement in BODY, as elisp."
|
||||||
#'org-trim
|
#'org-trim
|
||||||
(org-babel-comint-with-output
|
(org-babel-comint-with-output
|
||||||
(buffer org-babel-ruby-eoe-indicator t body)
|
(buffer org-babel-ruby-eoe-indicator t body)
|
||||||
(mapc
|
(insert (org-babel-chomp body) "\n" eoe-string)
|
||||||
(lambda (line)
|
(comint-send-input nil t))
|
||||||
(insert (org-babel-chomp line)) (comint-send-input nil t))
|
"\n") "[\r\n]")) "\n")))
|
||||||
(list "conf.echo=false;_org_prompt_mode=conf.prompt_mode;conf.prompt_mode=:NULL"
|
|
||||||
body
|
|
||||||
"conf.prompt_mode=_org_prompt_mode;conf.echo=true"
|
|
||||||
eoe-string)))
|
|
||||||
"\n") "[\r\n]") 4) "\n")))
|
|
||||||
(`value
|
(`value
|
||||||
(let* ((tmp-file (org-babel-temp-file "ruby-"))
|
(let* ((tmp-file (org-babel-temp-file "ruby-"))
|
||||||
(ppp (or (member "code" result-params)
|
(ppp (or (member "code" result-params)
|
||||||
|
|
Loading…
Reference in New Issue