aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorJoakim Verona2012-10-16 17:14:35 +0200
committerJoakim Verona2012-10-16 17:14:35 +0200
commit017a270078be5ae39301e3205afad80d23facbbc (patch)
tree5c85d8c3890f3a0cead231e87823b621a8f28e16 /lisp/progmodes/python.el
parent5fcc7035c884b4419a1619551222b5f28ad9906f (diff)
parent2b794d6940aa7dc58e297b3649b7799190d71f64 (diff)
downloademacs-017a270078be5ae39301e3205afad80d23facbbc.tar.gz
emacs-017a270078be5ae39301e3205afad80d23facbbc.zip
upstream
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el77
1 files changed, 43 insertions, 34 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index e99e6bda4b8..f5e4bffd598 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -499,17 +499,16 @@ The type returned can be `comment', `string' or `paren'."
499(defconst python-syntax-propertize-function 499(defconst python-syntax-propertize-function
500 (syntax-propertize-rules 500 (syntax-propertize-rules
501 ((rx 501 ((rx
502 ;; Match even number of backslashes. 502 (and
503 (or (not (any ?\\ ?\' ?\")) point) (* ?\\ ?\\) 503 ;; Match even number of backslashes.
504 ;; Match single or triple quotes of any kind. 504 (or (not (any ?\\ ?\' ?\")) point
505 (group (or "\"" "\"\"\"" "'" "'''"))) 505 ;; Quotes might be preceeded by a escaped quote.
506 (1 (ignore (python-syntax-stringify)))) 506 (and (or (not (any ?\\)) point) ?\\
507 ((rx 507 (* ?\\ ?\\) (any ?\' ?\")))
508 ;; Match odd number of backslashes. 508 (* ?\\ ?\\)
509 (or (not (any ?\\)) point) ?\\ (* ?\\ ?\\) 509 ;; Match single or triple quotes of any kind.
510 ;; Followed by even number of equal quotes. 510 (group (or "\"" "\"\"\"" "'" "'''"))))
511 (group (or "\"\"" "\"\"\"\"" "''" "''''"))) 511 (0 (ignore (python-syntax-stringify))))))
512 (1 (ignore (python-syntax-stringify))))))
513 512
514(defsubst python-syntax-count-quotes (quote-char &optional point limit) 513(defsubst python-syntax-count-quotes (quote-char &optional point limit)
515 "Count number of quotes around point (max is 3). 514 "Count number of quotes around point (max is 3).
@@ -525,11 +524,7 @@ is used to limit the scan."
525 524
526(defun python-syntax-stringify () 525(defun python-syntax-stringify ()
527 "Put `syntax-table' property correctly on single/triple quotes." 526 "Put `syntax-table' property correctly on single/triple quotes."
528 (let* ((num-quotes 527 (let* ((num-quotes (length (match-string-no-properties 1)))
529 (let ((n (length (match-string-no-properties 1))))
530 ;; This corrects the quote count when matching odd number
531 ;; of backslashes followed by even number of quotes.
532 (or (and (= 1 (logand n 1)) n) (1- n))))
533 (ppss (prog2 528 (ppss (prog2
534 (backward-char num-quotes) 529 (backward-char num-quotes)
535 (syntax-ppss) 530 (syntax-ppss)
@@ -1866,31 +1861,45 @@ When MSG is non-nil messages the first line of STRING."
1866 (string-match "\n[ \t].*\n?$" string)) 1861 (string-match "\n[ \t].*\n?$" string))
1867 (comint-send-string process "\n"))))) 1862 (comint-send-string process "\n")))))
1868 1863
1864;; Shell output catching stolen from gud-gdb
1865(defvar python-shell-fetch-lines-in-progress nil)
1866(defvar python-shell-fetch-lines-string nil)
1867(defvar python-shell-fetched-lines nil)
1868
1869(defun python-shell-fetch-lines-filter (string)
1870 "Filter used to read the list of lines output by a command.
1871STRING is the output to filter."
1872 (setq string (concat python-shell-fetch-lines-string string))
1873 (while (string-match "\n" string)
1874 (push (substring string 0 (match-beginning 0))
1875 python-shell-fetched-lines)
1876 (setq string (substring string (match-end 0))))
1877 (if (equal (string-match comint-prompt-regexp string) 0)
1878 (progn
1879 (setq python-shell-fetch-lines-in-progress nil)
1880 string)
1881 (progn
1882 (setq python-shell-fetch-lines-string string)
1883 "")))
1884
1869(defun python-shell-send-string-no-output (string &optional process msg) 1885(defun python-shell-send-string-no-output (string &optional process msg)
1870 "Send STRING to PROCESS and inhibit output. 1886 "Send STRING to PROCESS and inhibit output.
1871When MSG is non-nil messages the first line of STRING. Return 1887When MSG is non-nil messages the first line of STRING. Return
1872the output." 1888the output."
1873 (let* ((output-buffer "") 1889 (let ((process (or process (python-shell-get-or-create-process)))
1874 (process (or process (python-shell-get-or-create-process))) 1890 (comint-preoutput-filter-functions
1875 (comint-preoutput-filter-functions 1891 '(python-shell-fetch-lines-filter))
1876 (append comint-preoutput-filter-functions 1892 (python-shell-fetch-lines-in-progress t)
1877 '(ansi-color-filter-apply 1893 (inhibit-quit t))
1878 (lambda (string)
1879 (setq output-buffer (concat output-buffer string))
1880 ""))))
1881 (inhibit-quit t))
1882 (or 1894 (or
1883 (with-local-quit 1895 (with-local-quit
1884 (python-shell-send-string string process msg) 1896 (python-shell-send-string string process msg)
1885 (accept-process-output process) 1897 (while python-shell-fetch-lines-in-progress
1886 (replace-regexp-in-string 1898 (accept-process-output process))
1887 (if (> (length python-shell-prompt-output-regexp) 0) 1899 (prog1
1888 (format "\n*%s$\\|^%s\\|\n$" 1900 (mapconcat #'identity
1889 python-shell-prompt-regexp 1901 (reverse python-shell-fetched-lines) "\n")
1890 (or python-shell-prompt-output-regexp "")) 1902 (setq python-shell-fetched-lines nil)))
1891 (format "\n*$\\|^%s\\|\n$"
1892 python-shell-prompt-regexp))
1893 "" output-buffer))
1894 (with-current-buffer (process-buffer process) 1903 (with-current-buffer (process-buffer process)
1895 (comint-interrupt-subjob))))) 1904 (comint-interrupt-subjob)))))
1896 1905