diff options
| author | Fabián Ezequiel Gallina | 2014-07-31 21:18:19 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2014-07-31 21:18:19 -0300 |
| commit | bc1ce1df863ffd32d1290b448591f8897029b10b (patch) | |
| tree | b494025cc3479a74a5d6e935c2391d65e61ca6e5 | |
| parent | 1b2567263531e4f584cef5f79ef731cd4dbd741b (diff) | |
| download | emacs-bc1ce1df863ffd32d1290b448591f8897029b10b.tar.gz emacs-bc1ce1df863ffd32d1290b448591f8897029b10b.zip | |
* lisp/progmodes/python.el: Shell output capture enhancements.
(python-shell-accept-process-output): New function.
(inferior-python-mode)
(python-shell-send-setup-code): Use it.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/progmodes/python.el | 34 |
2 files changed, 32 insertions, 9 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5b07bbe6c74..e7496454fcc 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2014-07-31 Fabián Ezequiel Gallina <fgallina@gnu.org> | ||
| 2 | |||
| 3 | * progmodes/python.el: Shell output capture enhancements. | ||
| 4 | (python-shell-accept-process-output): New function. | ||
| 5 | (inferior-python-mode) | ||
| 6 | (python-shell-send-setup-code): Use it. | ||
| 7 | |||
| 1 | 2014-07-30 Christophe Deleuze <christophe.deleuze@free.fr> (tiny change) | 8 | 2014-07-30 Christophe Deleuze <christophe.deleuze@free.fr> (tiny change) |
| 2 | 9 | ||
| 3 | * calendar/icalendar.el (icalendar--decode-isodatetime): Use | 10 | * calendar/icalendar.el (icalendar--decode-isodatetime): Use |
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index d1dd9bef4bc..7d7cd9de19e 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -2129,6 +2129,27 @@ uniqueness for different types of configurations." | |||
| 2129 | directory package package) | 2129 | directory package package) |
| 2130 | (python-shell-get-process))) | 2130 | (python-shell-get-process))) |
| 2131 | 2131 | ||
| 2132 | (defun python-shell-accept-process-output (process &optional timeout regexp) | ||
| 2133 | "Accept PROCESS output with TIMEOUT until REGEXP is found. | ||
| 2134 | Optional argument TIMEOUT is the timeout argument to | ||
| 2135 | `accept-process-output' calls. Optional argument REGEXP | ||
| 2136 | overrides the regexp to match the end of output, defaults to | ||
| 2137 | `comint-prompt-regexp.'. Returns non-nil when output was | ||
| 2138 | properly captured. | ||
| 2139 | |||
| 2140 | This utility is useful in situations where the output may be | ||
| 2141 | received in chunks, since `accept-process-output' gives no | ||
| 2142 | guarantees they will be grabbed in a single call. An example use | ||
| 2143 | case for this would be the CPython shell start-up, where the | ||
| 2144 | banner and the initial prompt are received separetely." | ||
| 2145 | (let ((regexp (or regexp comint-prompt-regexp))) | ||
| 2146 | (catch 'found | ||
| 2147 | (while t | ||
| 2148 | (when (not (accept-process-output process timeout)) | ||
| 2149 | (throw 'found nil)) | ||
| 2150 | (when (looking-back regexp) | ||
| 2151 | (throw 'found t)))))) | ||
| 2152 | |||
| 2132 | (defun python-shell-comint-end-of-output-p (output) | 2153 | (defun python-shell-comint-end-of-output-p (output) |
| 2133 | "Return non-nil if OUTPUT is ends with input prompt." | 2154 | "Return non-nil if OUTPUT is ends with input prompt." |
| 2134 | (string-match | 2155 | (string-match |
| @@ -2380,13 +2401,8 @@ variable. | |||
| 2380 | (when python-shell-font-lock-enable | 2401 | (when python-shell-font-lock-enable |
| 2381 | (python-shell-font-lock-turn-on)) | 2402 | (python-shell-font-lock-turn-on)) |
| 2382 | (compilation-shell-minor-mode 1) | 2403 | (compilation-shell-minor-mode 1) |
| 2383 | ;; Ensure all the output is accepted before running any hooks. | 2404 | (python-shell-accept-process-output |
| 2384 | (accept-process-output (get-buffer-process (current-buffer))) | 2405 | (get-buffer-process (current-buffer)))) |
| 2385 | ;; At this point, all process output should have been received, but | ||
| 2386 | ;; on GNU/Linux, calling `python-shell-internal-send-string' without | ||
| 2387 | ;; a running internal shell fails to grab output properly unless | ||
| 2388 | ;; this `sit-for' is in place. | ||
| 2389 | (sit-for 0.1 t)) | ||
| 2390 | 2406 | ||
| 2391 | (defun python-shell-make-comint (cmd proc-name &optional pop internal) | 2407 | (defun python-shell-make-comint (cmd proc-name &optional pop internal) |
| 2392 | "Create a Python shell comint buffer. | 2408 | "Create a Python shell comint buffer. |
| @@ -2790,8 +2806,8 @@ This function takes the list of setup code to send from the | |||
| 2790 | python-shell-setup-codes | 2806 | python-shell-setup-codes |
| 2791 | "\n\n") | 2807 | "\n\n") |
| 2792 | "\n\nprint ('python.el: sent setup code')"))) | 2808 | "\n\nprint ('python.el: sent setup code')"))) |
| 2793 | (python-shell-send-string code) | 2809 | (python-shell-send-string code process) |
| 2794 | (accept-process-output process))) | 2810 | (python-shell-accept-process-output process))) |
| 2795 | 2811 | ||
| 2796 | (add-hook 'inferior-python-mode-hook | 2812 | (add-hook 'inferior-python-mode-hook |
| 2797 | #'python-shell-send-setup-code) | 2813 | #'python-shell-send-setup-code) |