annotate lisp/org/ob-comint.el @ 112275:6378d1b57038

Add 2011 to remaining FSF/AIST copyright years.
author Glenn Morris <rgm@gnu.org>
date Sat, 15 Jan 2011 14:10:37 -0800
parents a7740098b594
children ef719132ddfa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
1 ;;; ob-comint.el --- org-babel functions for interaction with comint buffers
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
2
112275
6378d1b57038 Add 2011 to remaining FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents: 111880
diff changeset
3 ;; Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
4
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
5 ;; Author: Eric Schulte
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
6 ;; Keywords: literate programming, reproducible research, comint
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
7 ;; Homepage: http://orgmode.org
111880
a7740098b594 Update to Org mode 7.4
Carsten Dominik <carsten.dominik@gmail.com>
parents: 111506
diff changeset
8 ;; Version: 7.4
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
9
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
11
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
15 ;; (at your option) any later version.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
16
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
20 ;; GNU General Public License for more details.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
21
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
24
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
25 ;;; Commentary:
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
26
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
27 ;; These functions build on comint to ease the sending and receiving
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
28 ;; of commands and results from comint buffers.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
29
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
30 ;; Note that the buffers in this file are analogous to sessions in
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
31 ;; org-babel at large.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
32
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
33 ;;; Code:
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
34 (require 'ob)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
35 (require 'comint)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
36 (eval-when-compile (require 'cl))
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
37 (declare-function with-parsed-tramp-file-name "tramp" (filename var &rest body))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
38 (declare-function tramp-flush-directory-property "tramp" (vec directory))
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
39
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
40 (defun org-babel-comint-buffer-livep (buffer)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
41 "Check if BUFFER is a comint buffer with a live process."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
42 (let ((buffer (if buffer (get-buffer buffer))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
43 (and buffer (buffer-live-p buffer) (get-buffer-process buffer) buffer)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
44
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
45 (defmacro org-babel-comint-in-buffer (buffer &rest body)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
46 "Check BUFFER and execute BODY.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
47 BUFFER is checked with `org-babel-comint-buffer-livep'. BODY is
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
48 executed inside the protection of `save-excursion' and
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
49 `save-match-data'."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
50 (declare (indent 1))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
51 `(save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
52 (save-match-data
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
53 (unless (org-babel-comint-buffer-livep ,buffer)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
54 (error "buffer %s doesn't exist or has no process" ,buffer))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
55 (set-buffer ,buffer)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
56 ,@body)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
57
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
58 (defmacro org-babel-comint-with-output (meta &rest body)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
59 "Evaluate BODY in BUFFER and return process output.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
60 Will wait until EOE-INDICATOR appears in the output, then return
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
61 all process output. If REMOVE-ECHO and FULL-BODY are present and
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
62 non-nil, then strip echo'd body from the returned output. META
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
63 should be a list containing the following where the last two
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
64 elements are optional.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
65
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
66 (BUFFER EOE-INDICATOR REMOVE-ECHO FULL-BODY)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
67
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
68 This macro ensures that the filter is removed in case of an error
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
69 or user `keyboard-quit' during execution of body."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
70 (declare (indent 1))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
71 (let ((buffer (car meta))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
72 (eoe-indicator (cadr meta))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
73 (remove-echo (cadr (cdr meta)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
74 (full-body (cadr (cdr (cdr meta)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
75 `(org-babel-comint-in-buffer ,buffer
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
76 (let ((string-buffer "") dangling-text raw)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
77 (flet ((my-filt (text)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
78 (setq string-buffer (concat string-buffer text))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
79 ;; setup filter
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
80 (add-hook 'comint-output-filter-functions 'my-filt)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
81 (unwind-protect
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
82 (progn
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
83 ;; got located, and save dangling text
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
84 (goto-char (process-mark (get-buffer-process (current-buffer))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
85 (let ((start (point))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
86 (end (point-max)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
87 (setq dangling-text (buffer-substring start end))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
88 (delete-region start end))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
89 ;; pass FULL-BODY to process
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
90 ,@body
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
91 ;; wait for end-of-evaluation indicator
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
92 (while (progn
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
93 (goto-char comint-last-input-end)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
94 (not (save-excursion
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
95 (and (re-search-forward
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
96 comint-prompt-regexp nil t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
97 (re-search-forward
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
98 (regexp-quote ,eoe-indicator) nil t)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
99 (accept-process-output (get-buffer-process (current-buffer)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
100 ;; thought the following this would allow async
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
101 ;; background running, but I was wrong...
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
102 ;; (run-with-timer .5 .5 'accept-process-output
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
103 ;; (get-buffer-process (current-buffer)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
104 )
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
105 ;; replace cut dangling text
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
106 (goto-char (process-mark (get-buffer-process (current-buffer))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
107 (insert dangling-text))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
108 ;; remove filter
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
109 (remove-hook 'comint-output-filter-functions 'my-filt)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
110 ;; remove echo'd FULL-BODY from input
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
111 (if (and ,remove-echo ,full-body
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
112 (string-match
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
113 (replace-regexp-in-string
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
114 "\n" "[\r\n]+" (regexp-quote (or ,full-body "")))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
115 string-buffer))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
116 (setq raw (substring string-buffer (match-end 0))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
117 (split-string string-buffer comint-prompt-regexp)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
118
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
119 (defun org-babel-comint-input-command (buffer cmd)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
120 "Pass CMD to BUFFER.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
121 The input will not be echoed."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
122 (org-babel-comint-in-buffer buffer
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
123 (goto-char (process-mark (get-buffer-process buffer)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
124 (insert cmd)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
125 (comint-send-input)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
126 (org-babel-comint-wait-for-output buffer)))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
127
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
128 (defun org-babel-comint-wait-for-output (buffer)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
129 "Wait until output arrives from BUFFER.
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
130 Note: this is only safe when waiting for the result of a single
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
131 statement (not large blocks of code)."
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
132 (org-babel-comint-in-buffer buffer
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
133 (while (progn
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
134 (goto-char comint-last-input-end)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
135 (not (and (re-search-forward comint-prompt-regexp nil t)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
136 (goto-char (match-beginning 0))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
137 (string= (face-name (face-at-point))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
138 "comint-highlight-prompt"))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
139 (accept-process-output (get-buffer-process buffer)))))
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
140
111506
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
141 (defun org-babel-comint-eval-invisibly-and-wait-for-file
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
142 (buffer file string &optional period)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
143 "Evaluate STRING in BUFFER invisibly.
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
144 Don't return until FILE exists. Code in STRING must ensure that
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
145 FILE exists at end of evaluation."
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
146 (unless (org-babel-comint-buffer-livep buffer)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
147 (error "buffer %s doesn't exist or has no process" buffer))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
148 (if (file-exists-p file) (delete-file file))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
149 (process-send-string
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
150 (get-buffer-process buffer)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
151 (if (string-match "\n$" string) string (concat string "\n")))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
152 ;; From Tramp 2.1.19 the following cache flush is not necessary
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
153 (if (file-remote-p default-directory)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
154 (let (v)
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
155 (with-parsed-tramp-file-name default-directory nil
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
156 (tramp-flush-directory-property v ""))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
157 (while (not (file-exists-p file)) (sit-for (or period 0.25))))
5cb272c831e8 Install org-mode version 7.3
Carsten Dominik <carsten.dominik@gmail.com>
parents: 109462
diff changeset
158
109462
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
159 (provide 'ob-comint)
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
160
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
161 ;; arch-tag: 9adddce6-0864-4be3-b0b5-6c5157dc7889
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
162
a150e8a14679 Install version 7.01 of Org-mode
Carsten Dominik <carsten.dominik@gmail.com>
parents:
diff changeset
163 ;;; ob-comint.el ends here