mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-30 00:57:48 +00:00
`org-babel-comint-in-buffer' now declares it's indentation
This commit is contained in:
parent
aa410df722
commit
eacce7b29d
|
@ -36,16 +36,14 @@
|
||||||
(require 'org-babel)
|
(require 'org-babel)
|
||||||
(require 'comint)
|
(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-list nil
|
|
||||||
"list to hold comint output")
|
|
||||||
|
|
||||||
(defun org-babel-comint-buffer-livep (buffer)
|
(defun org-babel-comint-buffer-livep (buffer)
|
||||||
(and (buffer-live-p buffer) (get-buffer buffer) (get-buffer-process buffer)))
|
(and (buffer-live-p buffer) (get-buffer buffer) (get-buffer-process buffer)))
|
||||||
|
|
||||||
(defmacro org-babel-comint-in-buffer (buffer &rest body)
|
(defmacro org-babel-comint-in-buffer (buffer &rest body)
|
||||||
|
"Check BUFFER with `org-babel-comint-buffer-livep' then execute
|
||||||
|
body inside the protection of `save-window-excursion' and
|
||||||
|
`save-match-data'."
|
||||||
|
(declare (indent 1))
|
||||||
`(save-window-excursion
|
`(save-window-excursion
|
||||||
(save-match-data
|
(save-match-data
|
||||||
(unless (org-babel-comint-buffer-livep buffer)
|
(unless (org-babel-comint-buffer-livep buffer)
|
||||||
|
@ -54,34 +52,30 @@
|
||||||
,@body)))
|
,@body)))
|
||||||
|
|
||||||
(defun org-babel-comint-append-output-filter (text)
|
(defun org-babel-comint-append-output-filter (text)
|
||||||
(setq string-buffer (concat string-buffer text))
|
(setq string-buffer (concat string-buffer text)))
|
||||||
(message (format "buffer0=%s" string-buffer)))
|
|
||||||
|
|
||||||
(defmacro org-babel-comint-with-output (&rest body)
|
(defmacro org-babel-comint-with-output (&rest body)
|
||||||
`(let ((string-buffer ""))
|
`(let ((string-buffer ""))
|
||||||
(message (format "buffer=1%s" string-buffer))
|
|
||||||
(add-hook 'comint-output-filter-functions 'org-babel-comint-append-output-filter)
|
(add-hook 'comint-output-filter-functions 'org-babel-comint-append-output-filter)
|
||||||
(condition-case nil (progn ,@body) (t))
|
(condition-case nil (progn ,@body) (t))
|
||||||
(message (format "buffer=1%s" string-buffer))
|
|
||||||
(remove-hook 'comint-output-filter-functions 'org-babel-comint-append-output-filter)
|
(remove-hook 'comint-output-filter-functions 'org-babel-comint-append-output-filter)
|
||||||
(message (format "buffer=1%s" string-buffer))
|
|
||||||
string-buffer))
|
string-buffer))
|
||||||
|
|
||||||
(defun org-babel-comint-wait-for-output (buffer)
|
(defun org-babel-comint-wait-for-output (buffer)
|
||||||
"Wait until output arrives"
|
"Wait until output arrives"
|
||||||
(org-babel-comint-in-buffer buffer
|
(org-babel-comint-in-buffer buffer
|
||||||
(while (progn
|
(while (progn
|
||||||
(goto-char comint-last-input-end)
|
(goto-char comint-last-input-end)
|
||||||
(not (re-search-forward comint-prompt-regexp nil t)))
|
(not (re-search-forward comint-prompt-regexp nil t)))
|
||||||
(accept-process-output (get-buffer-process buffer)))))
|
(accept-process-output (get-buffer-process buffer)))))
|
||||||
|
|
||||||
(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
|
||||||
(goto-char (process-mark (get-buffer-process buffer)))
|
(goto-char (process-mark (get-buffer-process buffer)))
|
||||||
(insert cmd)
|
(insert cmd)
|
||||||
(comint-send-input)
|
(comint-send-input)
|
||||||
(org-babel-comint-wait-for-output buffer)))
|
(org-babel-comint-wait-for-output buffer)))
|
||||||
|
|
||||||
(defun org-babel-comint-command-to-output (buffer cmd)
|
(defun org-babel-comint-command-to-output (buffer cmd)
|
||||||
"Pass CMD to BUFFER using `org-babel-comint-input-command', and
|
"Pass CMD to BUFFER using `org-babel-comint-input-command', and
|
||||||
|
@ -100,14 +94,14 @@ then return the result as a string using
|
||||||
(defun org-babel-comint-last-value (buffer)
|
(defun org-babel-comint-last-value (buffer)
|
||||||
"Return the last comint output in BUFFER as a string."
|
"Return the last comint output in BUFFER as a string."
|
||||||
(org-babel-comint-in-buffer buffer
|
(org-babel-comint-in-buffer buffer
|
||||||
(goto-char (process-mark (get-buffer-process buffer)))
|
(goto-char (process-mark (get-buffer-process buffer)))
|
||||||
(forward-line 0)
|
(forward-line 0)
|
||||||
(org-babel-clean-text-properties
|
(org-babel-clean-text-properties
|
||||||
(buffer-substring (+ comint-last-input-end
|
(buffer-substring (+ comint-last-input-end
|
||||||
;; because comint insists on echoing input
|
;; because comint insists on echoing input
|
||||||
(- comint-last-input-end
|
(- comint-last-input-end
|
||||||
comint-last-input-start))
|
comint-last-input-start))
|
||||||
(- (point) 1)))))
|
(- (point) 1)))))
|
||||||
|
|
||||||
(provide 'org-babel-comint)
|
(provide 'org-babel-comint)
|
||||||
;;; org-babel-comint.el ends here
|
;;; org-babel-comint.el ends here
|
||||||
|
|
Loading…
Reference in a new issue