mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-08-26 05:32:53 +00:00
now using org-babel-comint-with-output in org-babel-python.el
This commit is contained in:
parent
47810f8e14
commit
f4a1193a6e
|
@ -111,35 +111,16 @@ then create. Return the initialized session."
|
||||||
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."
|
||||||
(org-babel-comint-in-buffer buffer
|
(org-babel-comint-in-buffer buffer
|
||||||
(let ((string-buffer "")
|
(let* ((full-body (mapconcat #'org-babel-trim
|
||||||
(full-body (mapconcat #'org-babel-trim
|
|
||||||
(list body org-babel-python-last-value-eval org-babel-python-eoe-indicator) "\n"))
|
(list body org-babel-python-last-value-eval org-babel-python-eoe-indicator) "\n"))
|
||||||
results)
|
(raw (org-babel-comint-with-output buffer org-babel-python-eoe-indicator t
|
||||||
(flet ((my-filt (text) (setq string-buffer (concat string-buffer text))))
|
|
||||||
;; setup filter
|
|
||||||
(add-hook 'comint-output-filter-functions 'my-filt)
|
|
||||||
;; pass FULL-BODY to process
|
|
||||||
(goto-char (process-mark (get-buffer-process buffer)))
|
|
||||||
;; for some reason python is fussy, and likes enters after every input
|
;; for some reason python is fussy, and likes enters after every input
|
||||||
(mapc (lambda (statement) (insert statement) (comint-send-input))
|
(mapc (lambda (statement) (insert statement) (comint-send-input))
|
||||||
(split-string full-body "[\r\n]+"))
|
(split-string full-body "[\r\n]+"))))
|
||||||
(comint-send-input)
|
results)
|
||||||
;; wait for end-of-evaluation indicator
|
|
||||||
(while (progn
|
|
||||||
(goto-char comint-last-input-end)
|
|
||||||
(not (save-excursion (and (re-search-forward comint-prompt-regexp nil t)
|
|
||||||
(re-search-forward (regexp-quote org-babel-python-eoe-indicator) nil t)))))
|
|
||||||
(accept-process-output (get-buffer-process buffer)))
|
|
||||||
;; remove filter
|
|
||||||
(remove-hook 'comint-output-filter-functions 'my-filt))
|
|
||||||
;; remove echo'd FULL-BODY from input
|
|
||||||
(if (string-match (replace-regexp-in-string "\n" "\r\n" (regexp-quote full-body)) string-buffer)
|
|
||||||
(setq string-buffer (substring string-buffer (match-end 0))))
|
|
||||||
;; split results with `comint-prompt-regexp'
|
|
||||||
(setq results (delete org-babel-python-eoe-indicator
|
(setq results (delete org-babel-python-eoe-indicator
|
||||||
(cdr (member org-babel-python-eoe-indicator
|
(cdr (member org-babel-python-eoe-indicator
|
||||||
(reverse (mapcar #'org-babel-trim
|
(reverse (mapcar #'org-babel-trim raw))))))
|
||||||
(split-string string-buffer comint-prompt-regexp)))))))
|
|
||||||
(setq results (mapcar #'org-babel-python-read-string results))
|
(setq results (mapcar #'org-babel-python-read-string results))
|
||||||
(org-babel-trim (case result-type
|
(org-babel-trim (case result-type
|
||||||
(output (mapconcat #'identity (reverse (cdr results)) "\n"))
|
(output (mapconcat #'identity (reverse (cdr results)) "\n"))
|
||||||
|
|
|
@ -102,7 +102,7 @@ last statement in BODY."
|
||||||
(raw (org-babel-comint-with-output buffer org-babel-ruby-eoe-indicator t
|
(raw (org-babel-comint-with-output buffer org-babel-ruby-eoe-indicator t
|
||||||
(insert full-body) (comint-send-input)))
|
(insert full-body) (comint-send-input)))
|
||||||
results)
|
results)
|
||||||
;; split results with `comint-prompt-regexp'
|
;; clean up results
|
||||||
(setq results (cdr (member org-babel-ruby-eoe-indicator
|
(setq results (cdr (member org-babel-ruby-eoe-indicator
|
||||||
(reverse (mapcar #'org-babel-ruby-read-string
|
(reverse (mapcar #'org-babel-ruby-read-string
|
||||||
(mapcar #'org-babel-trim raw))))))
|
(mapcar #'org-babel-trim raw))))))
|
||||||
|
|
|
@ -1700,7 +1700,6 @@ This could probably be added to [[file:lisp/org-babel-script.el][org-babel-scrip
|
||||||
|
|
||||||
|
|
||||||
* Bugs [12/15]
|
* Bugs [12/15]
|
||||||
|
|
||||||
** TODO non-orgtbl formatted lists
|
** TODO non-orgtbl formatted lists
|
||||||
for example
|
for example
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue