forked from mirrors/org-mode
extracted the "capture all output from comint session" behavior into a macro
This commit is contained in:
parent
6f9985a749
commit
dd0392a4f2
|
@ -97,39 +97,19 @@ then create. Return the initialized session."
|
||||||
'output then return a list of the outputs of the statements in
|
'output then return a list of the outputs of the statements in
|
||||||
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
|
(let* ((full-body (mapconcat #'org-babel-chomp
|
||||||
(let ((string-buffer "")
|
|
||||||
(full-body (mapconcat #'org-babel-chomp
|
|
||||||
(list body org-babel-ruby-last-value-eval org-babel-ruby-eoe-indicator) "\n"))
|
(list body org-babel-ruby-last-value-eval org-babel-ruby-eoe-indicator) "\n"))
|
||||||
|
(raw (org-babel-comint-with-output buffer org-babel-ruby-eoe-indicator t
|
||||||
|
(insert full-body) (comint-send-input)))
|
||||||
results)
|
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)))
|
|
||||||
(insert full-body)
|
|
||||||
(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-ruby-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 results with `comint-prompt-regexp'
|
||||||
(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
|
(mapcar #'org-babel-trim raw))))))
|
||||||
(split-string string-buffer comint-prompt-regexp)))))))
|
|
||||||
(message "near-final=%S" results)
|
|
||||||
(case result-type
|
(case result-type
|
||||||
(output (mapconcat #'identity (reverse (cdr results)) "\n"))
|
(output (mapconcat #'identity (reverse (cdr results)) "\n"))
|
||||||
(value (car results))
|
(value (car results))
|
||||||
(t (reverse results))))))
|
(t (reverse results)))))
|
||||||
|
|
||||||
(defun org-babel-ruby-read-string (string)
|
(defun org-babel-ruby-read-string (string)
|
||||||
"Strip \\\"s from around ruby string"
|
"Strip \\\"s from around ruby string"
|
||||||
|
|
|
@ -52,6 +52,31 @@ body inside the protection of `save-window-excursion' and
|
||||||
(set-buffer buffer)
|
(set-buffer buffer)
|
||||||
,@body)))
|
,@body)))
|
||||||
|
|
||||||
|
(defmacro org-babel-comint-with-output (buffer eoe-indicator remove-echo &rest body)
|
||||||
|
"Evaluate BODY in BUFFER, wait until EOE-INDICATOR appears in
|
||||||
|
output, then return all process output."
|
||||||
|
(declare (indent 3))
|
||||||
|
`(org-babel-comint-in-buffer buffer
|
||||||
|
(let ((string-buffer ""))
|
||||||
|
(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 (current-buffer))))
|
||||||
|
(progn ,@body)
|
||||||
|
;; 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 ,eoe-indicator) nil t)))))
|
||||||
|
(accept-process-output (get-buffer-process (current-buffer))))
|
||||||
|
;; remove filter
|
||||||
|
(remove-hook 'comint-output-filter-functions 'my-filt))
|
||||||
|
;; remove echo'd FULL-BODY from input
|
||||||
|
(if (and ,remove-echo (string-match (replace-regexp-in-string "\n" "\r\n" (regexp-quote ,full-body)) string-buffer))
|
||||||
|
(setq raw (substring string-buffer (match-end 0))))
|
||||||
|
(split-string string-buffer comint-prompt-regexp))))
|
||||||
|
|
||||||
(defun org-babel-comint-input-command (buffer cmd)
|
(defun org-babel-comint-input-command (buffer cmd)
|
||||||
"Pass CMD to BUFFER The input will not be echoed."
|
"Pass CMD to BUFFER The input will not be echoed."
|
||||||
(org-babel-comint-in-buffer buffer
|
(org-babel-comint-in-buffer buffer
|
||||||
|
|
|
@ -299,7 +299,10 @@ relies on `org-babel-insert-result'."
|
||||||
(interactive)
|
(interactive)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char (org-babel-where-is-src-block-result)) (forward-line 1)
|
(goto-char (org-babel-where-is-src-block-result)) (forward-line 1)
|
||||||
(delete-region (point)
|
(delete-region (point) (org-babel-result-end))))
|
||||||
|
|
||||||
|
(defun org-babel-result-end ()
|
||||||
|
"Return the point at the end of the current set of results"
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(if (org-at-table-p)
|
(if (org-at-table-p)
|
||||||
(org-table-end)
|
(org-table-end)
|
||||||
|
@ -308,7 +311,7 @@ relies on `org-babel-insert-result'."
|
||||||
(forward-line 1)) t))
|
(forward-line 1)) t))
|
||||||
(forward-line 1))
|
(forward-line 1))
|
||||||
(forward-line -1)
|
(forward-line -1)
|
||||||
(point))))))
|
(point))))
|
||||||
|
|
||||||
(defun org-babel-result-to-file (result)
|
(defun org-babel-result-to-file (result)
|
||||||
"Return an `org-mode' link with the path being the value or
|
"Return an `org-mode' link with the path being the value or
|
||||||
|
@ -347,8 +350,7 @@ string.
|
||||||
|
|
||||||
This is taken almost directly from `org-read-prop'."
|
This is taken almost directly from `org-read-prop'."
|
||||||
(if (and (stringp cell) (not (equal cell "")))
|
(if (and (stringp cell) (not (equal cell "")))
|
||||||
(if (org-babel-number-p cell)
|
(or (org-babel-number-p cell)
|
||||||
(string-to-number cell)
|
|
||||||
(if (or (equal "(" (substring cell 0 1))
|
(if (or (equal "(" (substring cell 0 1))
|
||||||
(equal "'" (substring cell 0 2)))
|
(equal "'" (substring cell 0 2)))
|
||||||
(read cell)
|
(read cell)
|
||||||
|
@ -357,7 +359,8 @@ This is taken almost directly from `org-read-prop'."
|
||||||
|
|
||||||
(defun org-babel-number-p (string)
|
(defun org-babel-number-p (string)
|
||||||
"Return t if STRING represents a number"
|
"Return t if STRING represents a number"
|
||||||
(string-match "^[[:digit:]]*\\.?[[:digit:]]*$" string))
|
(if (string-match "^[[:digit:]]*\\.?[[:digit:]]*$" string)
|
||||||
|
(string-to-number string)))
|
||||||
|
|
||||||
(defun org-babel-import-elisp-from-file (file-name)
|
(defun org-babel-import-elisp-from-file (file-name)
|
||||||
"Read the results located at FILE-NAME into an elisp table. If
|
"Read the results located at FILE-NAME into an elisp table. If
|
||||||
|
|
|
@ -1699,19 +1699,7 @@ This could probably be added to [[file:lisp/org-babel-script.el][org-babel-scrip
|
||||||
(see [[* file result types][file result types]])
|
(see [[* file result types][file result types]])
|
||||||
|
|
||||||
|
|
||||||
* Bugs [11/15]
|
* Bugs [12/15]
|
||||||
|
|
||||||
** TODO when reading results from =#+resname= line
|
|
||||||
|
|
||||||
Errors when trying to read from resname lines.
|
|
||||||
|
|
||||||
#+resname: bug-in-resname
|
|
||||||
: 8
|
|
||||||
|
|
||||||
#+srcname: bug-in-resname-reader
|
|
||||||
#+begin_src emacs-lisp :var buggy=bug-in-resname() :results silent
|
|
||||||
buggy
|
|
||||||
#+end_src
|
|
||||||
|
|
||||||
** TODO non-orgtbl formatted lists
|
** TODO non-orgtbl formatted lists
|
||||||
for example
|
for example
|
||||||
|
@ -1745,6 +1733,18 @@ even a third"
|
||||||
org-babel-execute:R. (I never learned how to do this properly: org-R
|
org-babel-execute:R. (I never learned how to do this properly: org-R
|
||||||
jumps all over the place...)
|
jumps all over the place...)
|
||||||
|
|
||||||
|
** DONE when reading results from =#+resname= line
|
||||||
|
|
||||||
|
Errors when trying to read from resname lines.
|
||||||
|
|
||||||
|
#+resname: bug-in-resname
|
||||||
|
: 8
|
||||||
|
|
||||||
|
#+srcname: bug-in-resname-reader
|
||||||
|
#+begin_src emacs-lisp :var buggy=bug-in-resname() :results silent
|
||||||
|
buggy
|
||||||
|
#+end_src
|
||||||
|
|
||||||
** DONE R-code broke on "org-babel" rename
|
** DONE R-code broke on "org-babel" rename
|
||||||
|
|
||||||
#+srcname: bug-R-babels
|
#+srcname: bug-R-babels
|
||||||
|
|
Loading…
Reference in New Issue