diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 20af0aaf96e..10845b23630 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -1098,28 +1098,40 @@ Don't save anything for STR matching `inferior-python-filter-regexp'." | |||
| 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))) |
| 1113 | "") | 1118 | "") |
| 1114 | ((string= s "_emacs_ok\n") | 1119 | ((string= s "_emacs_ok\n") |
| 1115 | (when python-preoutput-continuation | 1120 | (when python-preoutput-continuation |
| 1116 | (funcall python-preoutput-continuation) | 1121 | (funcall python-preoutput-continuation) |
| 1117 | (setq python-preoutput-continuation nil)) | 1122 | (setq python-preoutput-continuation nil)) |
| 1118 | "") | 1123 | "") |
| 1119 | ((string-match "_emacs_out \\(.*\\)\n" s) | 1124 | ((string-match "_emacs_out \\(.*\\)\n" s) |
| 1120 | (setq python-preoutput-result (match-string 1 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) | ||
| 1121 | "") | 1133 | "") |
| 1122 | (t s))) | 1134 | (t s))) |
| 1123 | 1135 | ||
| 1124 | ;;;###autoload | 1136 | ;;;###autoload |
| 1125 | (defun run-python (&optional cmd noshow) | 1137 | (defun run-python (&optional cmd noshow) |
| @@ -1359,7 +1371,9 @@ 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 |