ob-python: more robust session evaluation
* lisp/ob-python.el (org-babel-python-evaluate-session): Introduced a new local function for sending input with a slight delay to allow pythong to re-draw the prompt. No longer removing newlines inside code block bodies (was due to a defective regexp).
This commit is contained in:
parent
16faa2b6c1
commit
9e7ef71da3
|
@ -238,10 +238,11 @@ last statement in BODY, as elisp."
|
||||||
If RESULT-TYPE equals 'output then return standard output as a
|
If RESULT-TYPE equals 'output then return standard output as a
|
||||||
string. If RESULT-TYPE equals 'value then return the value of the
|
string. If RESULT-TYPE equals 'value then return the value of the
|
||||||
last statement in BODY, as elisp."
|
last statement in BODY, as elisp."
|
||||||
(flet ((dump-last-value
|
(flet ((send-wait () (comint-send-input nil t) (sleep-for 0 5))
|
||||||
|
(dump-last-value
|
||||||
(tmp-file pp)
|
(tmp-file pp)
|
||||||
(mapc
|
(mapc
|
||||||
(lambda (statement) (insert statement) (comint-send-input))
|
(lambda (statement) (insert statement) (send-wait))
|
||||||
(if pp
|
(if pp
|
||||||
(list
|
(list
|
||||||
"import pprint"
|
"import pprint"
|
||||||
|
@ -250,9 +251,9 @@ last statement in BODY, as elisp."
|
||||||
(list (format "open('%s', 'w').write(str(_))"
|
(list (format "open('%s', 'w').write(str(_))"
|
||||||
(org-babel-process-file-name tmp-file 'noquote))))))
|
(org-babel-process-file-name tmp-file 'noquote))))))
|
||||||
(input-body (body)
|
(input-body (body)
|
||||||
(mapc (lambda (statement) (insert statement) (comint-send-input))
|
(mapc (lambda (line) (insert line) (send-wait))
|
||||||
(split-string (org-babel-trim body) "[\r\n]+"))
|
(split-string body "[\r\n]"))
|
||||||
(comint-send-input) (comint-send-input)))
|
(send-wait)))
|
||||||
((lambda (results)
|
((lambda (results)
|
||||||
(if (or (member "code" result-params)
|
(if (or (member "code" result-params)
|
||||||
(member "pp" result-params)
|
(member "pp" result-params)
|
||||||
|
@ -267,11 +268,9 @@ last statement in BODY, as elisp."
|
||||||
(butlast
|
(butlast
|
||||||
(org-babel-comint-with-output
|
(org-babel-comint-with-output
|
||||||
(session org-babel-python-eoe-indicator t body)
|
(session org-babel-python-eoe-indicator t body)
|
||||||
(let ((comint-process-echoes nil))
|
(input-body body)
|
||||||
(mapc
|
(insert org-babel-python-eoe-indicator)
|
||||||
(lambda (line)
|
(send-wait) (send-wait))
|
||||||
(insert line) (comint-send-input nil t))
|
|
||||||
(append (split-string body "[\n\r]") (list org-babel-python-eoe-indicator)))))
|
|
||||||
2) "\n"))
|
2) "\n"))
|
||||||
(value
|
(value
|
||||||
(let ((tmp-file (org-babel-temp-file "python-")))
|
(let ((tmp-file (org-babel-temp-file "python-")))
|
||||||
|
@ -280,9 +279,9 @@ last statement in BODY, as elisp."
|
||||||
(let ((comint-process-echoes nil))
|
(let ((comint-process-echoes nil))
|
||||||
(input-body body)
|
(input-body body)
|
||||||
(dump-last-value tmp-file (member "pp" result-params))
|
(dump-last-value tmp-file (member "pp" result-params))
|
||||||
(comint-send-input) (comint-send-input)
|
(send-wait) (send-wait)
|
||||||
(insert org-babel-python-eoe-indicator)
|
(insert org-babel-python-eoe-indicator)
|
||||||
(comint-send-input)))
|
(send-wait)))
|
||||||
(org-babel-eval-read-file tmp-file)))))))
|
(org-babel-eval-read-file tmp-file)))))))
|
||||||
|
|
||||||
(defun org-babel-python-read-string (string)
|
(defun org-babel-python-read-string (string)
|
||||||
|
|
Loading…
Reference in New Issue