diff options
| author | Fabián Ezequiel Gallina | 2012-09-30 21:53:44 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2012-09-30 21:53:44 -0300 |
| commit | 0478776bb7f04bfb60ff7a2397546c955a1f3ce2 (patch) | |
| tree | f862ae9faf3c60ccd1acdb4854ab0cc8e875192e /lisp/progmodes/python.el | |
| parent | 07f133bf5d9e1c3da32eca2e2024b47cbfaef26d (diff) | |
| download | emacs-0478776bb7f04bfb60ff7a2397546c955a1f3ce2.tar.gz emacs-0478776bb7f04bfb60ff7a2397546c955a1f3ce2.zip | |
Shell output catching a la gud-gdb.
* progmodes/python.el (python-shell-fetch-lines-in-progress)
(python-shell-fetch-lines-string, python-shell-fetched-lines): New
Vars.
(python-shell-fetch-lines-filter): New function.
(python-shell-send-string-no-output): Use them.
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index c5ba9a6aecb..26758105218 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -1867,31 +1867,45 @@ When MSG is non-nil messages the first line of STRING." | |||
| 1867 | (string-match "\n[ \t].*\n?$" string)) | 1867 | (string-match "\n[ \t].*\n?$" string)) |
| 1868 | (comint-send-string process "\n"))))) | 1868 | (comint-send-string process "\n"))))) |
| 1869 | 1869 | ||
| 1870 | ;; Shell output catching stolen from gud-gdb | ||
| 1871 | (defvar python-shell-fetch-lines-in-progress nil) | ||
| 1872 | (defvar python-shell-fetch-lines-string nil) | ||
| 1873 | (defvar python-shell-fetched-lines nil) | ||
| 1874 | |||
| 1875 | (defun python-shell-fetch-lines-filter (string) | ||
| 1876 | "Filter used to read the list of lines output by a command. | ||
| 1877 | STRING is the output to filter." | ||
| 1878 | (setq string (concat python-shell-fetch-lines-string string)) | ||
| 1879 | (while (string-match "\n" string) | ||
| 1880 | (push (substring string 0 (match-beginning 0)) | ||
| 1881 | python-shell-fetched-lines) | ||
| 1882 | (setq string (substring string (match-end 0)))) | ||
| 1883 | (if (equal (string-match comint-prompt-regexp string) 0) | ||
| 1884 | (progn | ||
| 1885 | (setq python-shell-fetch-lines-in-progress nil) | ||
| 1886 | string) | ||
| 1887 | (progn | ||
| 1888 | (setq python-shell-fetch-lines-string string) | ||
| 1889 | ""))) | ||
| 1890 | |||
| 1870 | (defun python-shell-send-string-no-output (string &optional process msg) | 1891 | (defun python-shell-send-string-no-output (string &optional process msg) |
| 1871 | "Send STRING to PROCESS and inhibit output. | 1892 | "Send STRING to PROCESS and inhibit output. |
| 1872 | When MSG is non-nil messages the first line of STRING. Return | 1893 | When MSG is non-nil messages the first line of STRING. Return |
| 1873 | the output." | 1894 | the output." |
| 1874 | (let* ((output-buffer "") | 1895 | (let ((process (or process (python-shell-get-or-create-process))) |
| 1875 | (process (or process (python-shell-get-or-create-process))) | 1896 | (comint-preoutput-filter-functions |
| 1876 | (comint-preoutput-filter-functions | 1897 | '(python-shell-fetch-lines-filter)) |
| 1877 | (append comint-preoutput-filter-functions | 1898 | (python-shell-fetch-lines-in-progress t) |
| 1878 | '(ansi-color-filter-apply | 1899 | (inhibit-quit t)) |
| 1879 | (lambda (string) | ||
| 1880 | (setq output-buffer (concat output-buffer string)) | ||
| 1881 | "")))) | ||
| 1882 | (inhibit-quit t)) | ||
| 1883 | (or | 1900 | (or |
| 1884 | (with-local-quit | 1901 | (with-local-quit |
| 1885 | (python-shell-send-string string process msg) | 1902 | (python-shell-send-string string process msg) |
| 1886 | (accept-process-output process) | 1903 | (while python-shell-fetch-lines-in-progress |
| 1887 | (replace-regexp-in-string | 1904 | (accept-process-output process)) |
| 1888 | (if (> (length python-shell-prompt-output-regexp) 0) | 1905 | (prog1 |
| 1889 | (format "\n*%s$\\|^%s\\|\n$" | 1906 | (mapconcat #'identity |
| 1890 | python-shell-prompt-regexp | 1907 | (reverse python-shell-fetched-lines) "\n") |
| 1891 | (or python-shell-prompt-output-regexp "")) | 1908 | (setq python-shell-fetched-lines nil))) |
| 1892 | (format "\n*$\\|^%s\\|\n$" | ||
| 1893 | python-shell-prompt-regexp)) | ||
| 1894 | "" output-buffer)) | ||
| 1895 | (with-current-buffer (process-buffer process) | 1909 | (with-current-buffer (process-buffer process) |
| 1896 | (comint-interrupt-subjob))))) | 1910 | (comint-interrupt-subjob))))) |
| 1897 | 1911 | ||