comparison lisp/progmodes/python.el @ 61037:758ff54158e2

(python-preoutput-leftover): New var. (python-preoutput-filter): Use it. (python-send-receive): Loop until all the result has been received.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 28 Mar 2005 14:36:25 +0000
parents 494d942e49fe
children bf4917ef8f38
comparison
equal deleted inserted replaced
61036:e224865fdbb7 61037:758ff54158e2
1096 "Data from last `_emacs_out' line seen by the preoutput filter.") 1096 "Data from last `_emacs_out' line seen by the preoutput filter.")
1097 1097
1098 (defvar python-preoutput-continuation nil 1098 (defvar python-preoutput-continuation nil
1099 "If non-nil, funcall this when `python-preoutput-filter' sees `_emacs_ok'.") 1099 "If non-nil, funcall this when `python-preoutput-filter' sees `_emacs_ok'.")
1100 1100
1101 (defvar python-preoutput-leftover nil)
1102
1101 ;; Using this stops us getting lines in the buffer like 1103 ;; Using this stops us getting lines in the buffer like
1102 ;; >>> ... ... >>> 1104 ;; >>> ... ... >>>
1103 ;; Also look for (and delete) an `_emacs_ok' string and call 1105 ;; Also look for (and delete) an `_emacs_ok' string and call
1104 ;; `python-preoutput-continuation' if we get it. 1106 ;; `python-preoutput-continuation' if we get it.
1105 (defun python-preoutput-filter (s) 1107 (defun python-preoutput-filter (s)
1106 "`comint-preoutput-filter-functions' function: ignore prompts not at bol." 1108 "`comint-preoutput-filter-functions' function: ignore prompts not at bol."
1109 (when python-preoutput-leftover
1110 (setq s (concat python-preoutput-leftover s))
1111 (setq python-preoutput-leftover nil))
1107 (cond ((and (string-match (rx (and string-start (repeat 3 (any ".>")) 1112 (cond ((and (string-match (rx (and string-start (repeat 3 (any ".>"))
1108 " " string-end)) 1113 " " string-end))
1109 s) 1114 s)
1110 (/= (let ((inhibit-field-text-motion t)) 1115 (/= (let ((inhibit-field-text-motion t))
1111 (line-beginning-position)) 1116 (line-beginning-position))
1112 (point))) 1117 (point)))
1118 "")
1119 ((string= s "_emacs_ok\n")
1120 (when python-preoutput-continuation
1121 (funcall python-preoutput-continuation)
1122 (setq python-preoutput-continuation nil))
1123 "")
1124 ((string-match "_emacs_out \\(.*\\)\n" s)
1125 (setq python-preoutput-result (match-string 1 s))
1126 "")
1127 ((string-match ".*\n" s)
1128 s)
1129 ((or (eq t (compare-strings s nil nil "_emacs_ok\n" nil (length s)))
1130 (eq t (compare-strings s nil nil "_emacs_out " nil
1131 (min (length "_emacs_out ") (length s)))))
1132 (setq python-preoutput-leftover s)
1113 "") 1133 "")
1114 ((string= s "_emacs_ok\n") 1134 (t s)))
1115 (when python-preoutput-continuation
1116 (funcall python-preoutput-continuation)
1117 (setq python-preoutput-continuation nil))
1118 "")
1119 ((string-match "_emacs_out \\(.*\\)\n" s)
1120 (setq python-preoutput-result (match-string 1 s))
1121 "")
1122 (t s)))
1123 1135
1124 ;;;###autoload 1136 ;;;###autoload
1125 (defun run-python (&optional cmd noshow) 1137 (defun run-python (&optional cmd noshow)
1126 "Run an inferior Python process, input and output via buffer *Python*. 1138 "Run an inferior Python process, input and output via buffer *Python*.
1127 CMD is the Python command to run. NOSHOW non-nil means don't show the 1139 CMD is the Python command to run. NOSHOW non-nil means don't show the
1357 "Send STRING to inferior Python (if any) and return result. 1369 "Send STRING to inferior Python (if any) and return result.
1358 The result is what follows `_emacs_out' in the output (or nil)." 1370 The result is what follows `_emacs_out' in the output (or nil)."
1359 (let ((proc (python-proc))) 1371 (let ((proc (python-proc)))
1360 (python-send-string string) 1372 (python-send-string string)
1361 (setq python-preoutput-result nil) 1373 (setq python-preoutput-result nil)
1362 (accept-process-output proc 5) 1374 (while (progn
1375 (accept-process-output proc 5)
1376 python-preoutput-leftover))
1363 python-preoutput-result)) 1377 python-preoutput-result))
1364 1378
1365 ;; Fixme: try to make it work with point in the arglist. Also, is 1379 ;; Fixme: try to make it work with point in the arglist. Also, is
1366 ;; there anything reasonable we can do with random methods? 1380 ;; there anything reasonable we can do with random methods?
1367 ;; (Currently only works with functions.) 1381 ;; (Currently only works with functions.)