working on org-babel-comint for automatically keeping a ring

This commit is contained in:
Eric Schulte 2009-06-10 17:27:06 -07:00
parent 23c61abf90
commit 8d0fd18933
2 changed files with 93 additions and 2 deletions

View File

@ -36,6 +36,22 @@
(require 'org-babel)
(require 'comint)
(defvar org-babel-comint-output-buffer nil
"this is a string to buffer output, it should be set buffer local")
(defvar org-babel-comint-output-ring nil
"ring to hold comint output")
(defvar org-babel-comint-output-ring-size 10
"number of output to be help")
(defun org-babel-comint-init (buffer)
"Initialize a buffer to use org-babel-comint."
(save-excursion
(set-buffer buffer)
(set (make-local-variable 'org-babel-comint-output-buffer) "")
))
(defun org-babel-comint-buffer-livep (buffer)
(and (buffer-live-p buffer) (get-buffer buffer) (get-buffer-process buffer)))
@ -63,7 +79,14 @@
(comint-send-input)
(org-babel-comint-wait-for-output buffer)))
(defun org-babel-comint-command-to-string (buffer cmd)
(defun org-babel-comint-command-to-output (buffer cmd)
"Pass CMD to BUFFER using `org-babel-comint-input-command', and
then return the result as a string using
`org-babel-comint-last-value'."
(org-babel-comint-input-command buffer cmd)
(org-babel-comint-last-value buffer))
(defun org-babel-comint-command-to-last (buffer cmd)
"Pass CMD to BUFFER using `org-babel-comint-input-command', and
then return the result as a string using
`org-babel-comint-last-value'."
@ -82,5 +105,41 @@ then return the result as a string using
comint-last-input-start))
(- (point) 1)))))
;; output filter
;;
;; This will collect output, stripping away echo'd inputs, splitting
;; it by `comint-prompt-regexp', then sticking it into the
;; `org-babel-comint-output-ring'.
(defun org-babel-comint-hook ()
(set (make-local-variable 'org-babel-comint-output-buffer) "")
(set (make-local-variable 'org-babel-comint-output-ring) (make-ring 10)))
(add-hook 'comint-mode-hook 'org-babel-comint-hook)
(defun org-babel-comint-output-filter (text)
"Filter the text of org-babel-comint"
(setq org-babel-comint-output-buffer (concat org-babel-comint-output-buffer text))
(let ((holder (split-string org-babel-comint-output-buffer comint-prompt-regexp)))
(when (> (length holder) 1)
(mapc (lambda (output) (ring-insert org-babel-comint-output-ring (org-babel-chomp output)))
(butlast holder))
(setq org-babel-comint-output-buffer (or (cdr (last holder)) "")))))
(add-hook 'comint-output-filter-functions 'org-babel-comint-output-filter)
;; debugging functions
(defun org-babel-show-output-buffer ()
(interactive)
(message org-babel-comint-output-buffer))
(defun org-babel-show-output-ring-size ()
(interactive)
(message (format "ring is %d" (ring-size org-babel-comint-output-ring))))
(defun org-babel-show-ring ()
(interactive)
(message (format "%S" (ring-elements org-babel-comint-output-ring))))
(provide 'org-babel-comint)
;;; org-babel-comint.el ends here

View File

@ -115,7 +115,7 @@ and the results to be collected in the same table.
* Tasks [22/38]
** TODO Create objects in top level (global) environment [0/6]
** TODO Create objects in top level (global) environment [0/5]
*sessions*
*** initial requirement statement [DED]
@ -465,6 +465,38 @@ for the execution of source-code blocks.
with the results (this implies the *script* =:results=
argument as well)
*** TODO comint notes
Implementing comint integration in [[file:lisp/org-babel-comint.el][org-babel-comint.el]].
Need to have...
- handling of outputs
- split raw output from process by prompts
- a ring of the outputs, buffer-local, `org-babel-comint-output-ring'
- a switch for dumping all outputs to a buffer
- inputting commands
Lets drop all this language specific stuff, and just use
org-babel-comint to split up our outputs, and return either the last
value of an execution or the combination of values from the
executions.
**** comint filter functions
: ;; comint-input-filter-functions hook process-in-a-buffer
: ;; comint-output-filter-functions hook function modes.
: ;; comint-preoutput-filter-functions hook
: ;; comint-input-filter function ...
#+srcname: obc-filter-ruby
#+begin_src ruby :results last
1
2
3
4
5
#+end_src
*** TODO rework evaluation lang-by-lang [0/4]
This should include...