mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-07-16 22:16:27 +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
|
||||
last statement in BODY."
|
||||
(org-babel-comint-in-buffer buffer
|
||||
(let ((string-buffer "")
|
||||
(full-body (mapconcat #'org-babel-trim
|
||||
(let* ((full-body (mapconcat #'org-babel-trim
|
||||
(list body org-babel-python-last-value-eval org-babel-python-eoe-indicator) "\n"))
|
||||
results)
|
||||
(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)))
|
||||
(raw (org-babel-comint-with-output buffer org-babel-python-eoe-indicator t
|
||||
;; for some reason python is fussy, and likes enters after every input
|
||||
(mapc (lambda (statement) (insert statement) (comint-send-input))
|
||||
(split-string full-body "[\r\n]+"))
|
||||
(comint-send-input)
|
||||
;; 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'
|
||||
(split-string full-body "[\r\n]+"))))
|
||||
results)
|
||||
(setq results (delete org-babel-python-eoe-indicator
|
||||
(cdr (member org-babel-python-eoe-indicator
|
||||
(reverse (mapcar #'org-babel-trim
|
||||
(split-string string-buffer comint-prompt-regexp)))))))
|
||||
(reverse (mapcar #'org-babel-trim raw))))))
|
||||
(setq results (mapcar #'org-babel-python-read-string results))
|
||||
(org-babel-trim (case result-type
|
||||
(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
|
||||
(insert full-body) (comint-send-input)))
|
||||
results)
|
||||
;; split results with `comint-prompt-regexp'
|
||||
;; clean up results
|
||||
(setq results (cdr (member org-babel-ruby-eoe-indicator
|
||||
(reverse (mapcar #'org-babel-ruby-read-string
|
||||
(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]
|
||||
|
||||
** TODO non-orgtbl formatted lists
|
||||
for example
|
||||
|
||||
|
|
Loading…
Reference in a new issue