aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorKenichi Handa2012-10-07 21:58:14 +0900
committerKenichi Handa2012-10-07 21:58:14 +0900
commitdade5fca51ce2ed10fdace1cfcf78287599154a1 (patch)
tree299c84e1ce2c5a95237b41781113790626d259c5 /lisp/progmodes/python.el
parent6aa75fb62f6cdc4164d935ef14d57feec5ed6e0a (diff)
parent78d876b90e52400b7bbb086ca1a471d3d20d0e98 (diff)
downloademacs-dade5fca51ce2ed10fdace1cfcf78287599154a1.tar.gz
emacs-dade5fca51ce2ed10fdace1cfcf78287599154a1.zip
merge trunk
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el77
1 files changed, 46 insertions, 31 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index b3b3b0181d7..726c0b2d542 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1667,10 +1667,6 @@ variable.
1667\(Type \\[describe-mode] in the process buffer for a list of commands.)" 1667\(Type \\[describe-mode] in the process buffer for a list of commands.)"
1668 (set-syntax-table python-mode-syntax-table) 1668 (set-syntax-table python-mode-syntax-table)
1669 (setq mode-line-process '(":%s")) 1669 (setq mode-line-process '(":%s"))
1670 (setq comint-prompt-regexp (format "^\\(?:%s\\|%s\\|%s\\)"
1671 python-shell-prompt-regexp
1672 python-shell-prompt-block-regexp
1673 python-shell-prompt-pdb-regexp))
1674 (make-local-variable 'comint-output-filter-functions) 1670 (make-local-variable 'comint-output-filter-functions)
1675 (add-hook 'comint-output-filter-functions 1671 (add-hook 'comint-output-filter-functions
1676 'python-comint-output-filter-function) 1672 'python-comint-output-filter-function)
@@ -1720,7 +1716,11 @@ killed."
1720 (process (get-buffer-process buffer))) 1716 (process (get-buffer-process buffer)))
1721 (with-current-buffer buffer 1717 (with-current-buffer buffer
1722 (inferior-python-mode) 1718 (inferior-python-mode)
1723 (python-util-clone-local-variables current-buffer)) 1719 (python-util-clone-local-variables current-buffer)
1720 (setq comint-prompt-regexp (format "^\\(?:%s\\|%s\\|%s\\)"
1721 python-shell-prompt-regexp
1722 python-shell-prompt-block-regexp
1723 python-shell-prompt-pdb-regexp)))
1724 (accept-process-output process) 1724 (accept-process-output process)
1725 (and pop (pop-to-buffer buffer t)) 1725 (and pop (pop-to-buffer buffer t))
1726 (and internal (set-process-query-on-exit-flag process nil)))) 1726 (and internal (set-process-query-on-exit-flag process nil))))
@@ -1861,26 +1861,39 @@ When MSG is non-nil messages the first line of STRING."
1861 (string-match "\n[ \t].*\n?$" string)) 1861 (string-match "\n[ \t].*\n?$" string))
1862 (comint-send-string process "\n"))))) 1862 (comint-send-string process "\n")))))
1863 1863
1864;; Shell output catching stolen from gud-gdb 1864(defvar python-shell-output-filter-in-progress nil)
1865(defvar python-shell-fetch-lines-in-progress nil) 1865(defvar python-shell-output-filter-buffer nil)
1866(defvar python-shell-fetch-lines-string nil) 1866
1867(defvar python-shell-fetched-lines nil) 1867(defun python-shell-output-filter (string)
1868 1868 "Filter used in `python-shell-send-string-no-output' to grab output.
1869(defun python-shell-fetch-lines-filter (string) 1869STRING is the output received to this point from the process.
1870 "Filter used to read the list of lines output by a command. 1870This filter saves received output from the process in
1871STRING is the output to filter." 1871`python-shell-output-filter-buffer' and stops receiving it after
1872 (setq string (concat python-shell-fetch-lines-string string)) 1872detecting a prompt at the end of the buffer."
1873 (while (string-match "\n" string) 1873 (setq
1874 (push (substring string 0 (match-beginning 0)) 1874 string (ansi-color-filter-apply string)
1875 python-shell-fetched-lines) 1875 python-shell-output-filter-buffer
1876 (setq string (substring string (match-end 0)))) 1876 (concat python-shell-output-filter-buffer string))
1877 (if (equal (string-match comint-prompt-regexp string) 0) 1877 (when (string-match
1878 (progn 1878 (format "\n\\(?:%s\\|%s\\|%s\\)$"
1879 (setq python-shell-fetch-lines-in-progress nil) 1879 python-shell-prompt-regexp
1880 string) 1880 python-shell-prompt-block-regexp
1881 (progn 1881 python-shell-prompt-pdb-regexp)
1882 (setq python-shell-fetch-lines-string string) 1882 python-shell-output-filter-buffer)
1883 ""))) 1883 ;; Output ends when `python-shell-output-filter-buffer' contains
1884 ;; the prompt attached at the end of it.
1885 (setq python-shell-output-filter-in-progress nil
1886 python-shell-output-filter-buffer
1887 (substring python-shell-output-filter-buffer
1888 0 (match-beginning 0)))
1889 (when (and (> (length python-shell-prompt-output-regexp) 0)
1890 (string-match (concat "^" python-shell-prompt-output-regexp)
1891 python-shell-output-filter-buffer))
1892 ;; Some shells, like iPython might append a prompt before the
1893 ;; output, clean that.
1894 (setq python-shell-output-filter-buffer
1895 (substring python-shell-output-filter-buffer (match-end 0)))))
1896 "")
1884 1897
1885(defun python-shell-send-string-no-output (string &optional process msg) 1898(defun python-shell-send-string-no-output (string &optional process msg)
1886 "Send STRING to PROCESS and inhibit output. 1899 "Send STRING to PROCESS and inhibit output.
@@ -1888,18 +1901,20 @@ When MSG is non-nil messages the first line of STRING. Return
1888the output." 1901the output."
1889 (let ((process (or process (python-shell-get-or-create-process))) 1902 (let ((process (or process (python-shell-get-or-create-process)))
1890 (comint-preoutput-filter-functions 1903 (comint-preoutput-filter-functions
1891 '(python-shell-fetch-lines-filter)) 1904 '(python-shell-output-filter))
1892 (python-shell-fetch-lines-in-progress t) 1905 (python-shell-output-filter-in-progress t)
1893 (inhibit-quit t)) 1906 (inhibit-quit t))
1894 (or 1907 (or
1895 (with-local-quit 1908 (with-local-quit
1896 (python-shell-send-string string process msg) 1909 (python-shell-send-string string process msg)
1897 (while python-shell-fetch-lines-in-progress 1910 (while python-shell-output-filter-in-progress
1911 ;; `python-shell-output-filter' takes care of setting
1912 ;; `python-shell-output-filter-in-progress' to NIL after it
1913 ;; detects end of output.
1898 (accept-process-output process)) 1914 (accept-process-output process))
1899 (prog1 1915 (prog1
1900 (mapconcat #'identity 1916 python-shell-output-filter-buffer
1901 (reverse python-shell-fetched-lines) "\n") 1917 (setq python-shell-output-filter-buffer nil)))
1902 (setq python-shell-fetched-lines nil)))
1903 (with-current-buffer (process-buffer process) 1918 (with-current-buffer (process-buffer process)
1904 (comint-interrupt-subjob))))) 1919 (comint-interrupt-subjob)))))
1905 1920