aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2012-09-30 21:53:44 -0300
committerFabián Ezequiel Gallina2012-09-30 21:53:44 -0300
commit0478776bb7f04bfb60ff7a2397546c955a1f3ce2 (patch)
treef862ae9faf3c60ccd1acdb4854ab0cc8e875192e
parent07f133bf5d9e1c3da32eca2e2024b47cbfaef26d (diff)
downloademacs-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.
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/progmodes/python.el50
2 files changed, 41 insertions, 18 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index b5b8c8bef9f..15c8d43b869 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
12012-10-01 Fabián Ezequiel Gallina <fgallina@cuca>
2
3 Shell output catching a la gud-gdb.
4 * progmodes/python.el (python-shell-fetch-lines-in-progress)
5 (python-shell-fetch-lines-string, python-shell-fetched-lines): New
6 Vars.
7 (python-shell-fetch-lines-filter): New function.
8 (python-shell-send-string-no-output): Use them.
9
12012-09-30 Tomohiro Matsuyama <tomo@cx4a.org> 102012-09-30 Tomohiro Matsuyama <tomo@cx4a.org>
2 11
3 * profiler.el (profiler-sampling-interval): Rename from 12 * profiler.el (profiler-sampling-interval): Rename from
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.
1877STRING 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.
1872When MSG is non-nil messages the first line of STRING. Return 1893When MSG is non-nil messages the first line of STRING. Return
1873the output." 1894the 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