1098 |
(defvar python-preoutput-continuation nil |
(defvar python-preoutput-continuation nil |
1099 |
"If non-nil, funcall this when `python-preoutput-filter' sees `_emacs_ok'.") |
"If non-nil, funcall this when `python-preoutput-filter' sees `_emacs_ok'.") |
1100 |
|
|
1101 |
|
(defvar python-preoutput-leftover nil) |
1102 |
|
|
1103 |
;; Using this stops us getting lines in the buffer like |
;; Using this stops us getting lines in the buffer like |
1104 |
;; >>> ... ... >>> |
;; >>> ... ... >>> |
1105 |
;; Also look for (and delete) an `_emacs_ok' string and call |
;; Also look for (and delete) an `_emacs_ok' string and call |
1106 |
;; `python-preoutput-continuation' if we get it. |
;; `python-preoutput-continuation' if we get it. |
1107 |
(defun python-preoutput-filter (s) |
(defun python-preoutput-filter (s) |
1108 |
"`comint-preoutput-filter-functions' function: ignore prompts not at bol." |
"`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)) |
1112 |
(cond ((and (string-match (rx (and string-start (repeat 3 (any ".>")) |
(cond ((and (string-match (rx (and string-start (repeat 3 (any ".>")) |
1113 |
" " string-end)) |
" " string-end)) |
1114 |
s) |
s) |
1115 |
(/= (let ((inhibit-field-text-motion t)) |
(/= (let ((inhibit-field-text-motion t)) |
1116 |
(line-beginning-position)) |
(line-beginning-position)) |
1117 |
(point))) |
(point))) |
1118 |
"") |
"") |
1119 |
((string= s "_emacs_ok\n") |
((string= s "_emacs_ok\n") |
1120 |
(when python-preoutput-continuation |
(when python-preoutput-continuation |
1121 |
(funcall python-preoutput-continuation) |
(funcall python-preoutput-continuation) |
1122 |
(setq python-preoutput-continuation nil)) |
(setq python-preoutput-continuation nil)) |
1123 |
"") |
"") |
1124 |
((string-match "_emacs_out \\(.*\\)\n" s) |
((string-match "_emacs_out \\(.*\\)\n" s) |
1125 |
(setq python-preoutput-result (match-string 1 s)) |
(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) |
1133 |
"") |
"") |
1134 |
(t s))) |
(t s))) |
1135 |
|
|
1136 |
;;;###autoload |
;;;###autoload |
1137 |
(defun run-python (&optional cmd noshow) |
(defun run-python (&optional cmd noshow) |
1371 |
(let ((proc (python-proc))) |
(let ((proc (python-proc))) |
1372 |
(python-send-string string) |
(python-send-string string) |
1373 |
(setq python-preoutput-result nil) |
(setq python-preoutput-result nil) |
1374 |
(accept-process-output proc 5) |
(while (progn |
1375 |
|
(accept-process-output proc 5) |
1376 |
|
python-preoutput-leftover)) |
1377 |
python-preoutput-result)) |
python-preoutput-result)) |
1378 |
|
|
1379 |
;; Fixme: try to make it work with point in the arglist. Also, is |
;; Fixme: try to make it work with point in the arglist. Also, is |