diff options
| author | Fabián Ezequiel Gallina | 2012-10-08 18:30:36 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2012-10-08 18:30:36 -0300 |
| commit | a5b773c40ce950ac004be26b9f1bc4fcf985276b (patch) | |
| tree | 6f49df0073c003ec04969191c72460609823477f /lisp/progmodes/python.el | |
| parent | 2b1f11ed71db0344deb3c469bba09bd2cda3f0bd (diff) | |
| download | emacs-a5b773c40ce950ac004be26b9f1bc4fcf985276b.tar.gz emacs-a5b773c40ce950ac004be26b9f1bc4fcf985276b.zip | |
Fix shell handling of unbalanced quotes and parens in output.
* progmodes/python.el (python-rx-constituents): Added
string-delimiter.
(python-syntax-propertize-function): Use it.
(python-shell-output-syntax-table): New var.
(inferior-python-mode): Prevent unbalanced parens/quotes from
previous output mess with current input context.
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 72 |
1 files changed, 48 insertions, 24 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 6b0dc954ca7..d35dbc69a48 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -337,19 +337,28 @@ | |||
| 337 | "==" ">=" "is" "not"))) | 337 | "==" ">=" "is" "not"))) |
| 338 | ;; FIXME: Use regexp-opt. | 338 | ;; FIXME: Use regexp-opt. |
| 339 | (assignment-operator . ,(rx (or "=" "+=" "-=" "*=" "/=" "//=" "%=" "**=" | 339 | (assignment-operator . ,(rx (or "=" "+=" "-=" "*=" "/=" "//=" "%=" "**=" |
| 340 | ">>=" "<<=" "&=" "^=" "|=")))) | 340 | ">>=" "<<=" "&=" "^=" "|="))) |
| 341 | "Additional Python specific sexps for `python-rx'")) | 341 | (string-delimiter . ,(rx (and |
| 342 | 342 | ;; Match even number of backslashes. | |
| 343 | (defmacro python-rx (&rest regexps) | 343 | (or (not (any ?\\ ?\' ?\")) point |
| 344 | "Python mode specialized rx macro. | 344 | ;; Quotes might be preceded by a escaped quote. |
| 345 | (and (or (not (any ?\\)) point) ?\\ | ||
| 346 | (* ?\\ ?\\) (any ?\' ?\"))) | ||
| 347 | (* ?\\ ?\\) | ||
| 348 | ;; Match single or triple quotes of any kind. | ||
| 349 | (group (or "\"" "\"\"\"" "'" "'''")))))) | ||
| 350 | "Additional Python specific sexps for `python-rx'") | ||
| 351 | |||
| 352 | (defmacro python-rx (&rest regexps) | ||
| 353 | "Python mode specialized rx macro. | ||
| 345 | This variant of `rx' supports common python named REGEXPS." | 354 | This variant of `rx' supports common python named REGEXPS." |
| 346 | (let ((rx-constituents (append python-rx-constituents rx-constituents))) | 355 | (let ((rx-constituents (append python-rx-constituents rx-constituents))) |
| 347 | (cond ((null regexps) | 356 | (cond ((null regexps) |
| 348 | (error "No regexp")) | 357 | (error "No regexp")) |
| 349 | ((cdr regexps) | 358 | ((cdr regexps) |
| 350 | (rx-to-string `(and ,@regexps) t)) | 359 | (rx-to-string `(and ,@regexps) t)) |
| 351 | (t | 360 | (t |
| 352 | (rx-to-string (car regexps) t))))) | 361 | (rx-to-string (car regexps) t)))))) |
| 353 | 362 | ||
| 354 | 363 | ||
| 355 | ;;; Font-lock and syntax | 364 | ;;; Font-lock and syntax |
| @@ -498,16 +507,7 @@ The type returned can be `comment', `string' or `paren'." | |||
| 498 | 507 | ||
| 499 | (defconst python-syntax-propertize-function | 508 | (defconst python-syntax-propertize-function |
| 500 | (syntax-propertize-rules | 509 | (syntax-propertize-rules |
| 501 | ((rx | 510 | ((python-rx string-delimiter) |
| 502 | (and | ||
| 503 | ;; Match even number of backslashes. | ||
| 504 | (or (not (any ?\\ ?\' ?\")) point | ||
| 505 | ;; Quotes might be preceded by a escaped quote. | ||
| 506 | (and (or (not (any ?\\)) point) ?\\ | ||
| 507 | (* ?\\ ?\\) (any ?\' ?\"))) | ||
| 508 | (* ?\\ ?\\) | ||
| 509 | ;; Match single or triple quotes of any kind. | ||
| 510 | (group (or "\"" "\"\"\"" "'" "'''")))) | ||
| 511 | (0 (ignore (python-syntax-stringify)))))) | 511 | (0 (ignore (python-syntax-stringify)))))) |
| 512 | 512 | ||
| 513 | (defsubst python-syntax-count-quotes (quote-char &optional point limit) | 513 | (defsubst python-syntax-count-quotes (quote-char &optional point limit) |
| @@ -1609,6 +1609,20 @@ OUTPUT is a string with the contents of the buffer." | |||
| 1609 | 1609 | ||
| 1610 | (defvar python-shell--parent-buffer nil) | 1610 | (defvar python-shell--parent-buffer nil) |
| 1611 | 1611 | ||
| 1612 | (defvar python-shell-output-syntax-table | ||
| 1613 | (let ((table (make-syntax-table python-dotty-syntax-table))) | ||
| 1614 | (modify-syntax-entry ?\' "." table) | ||
| 1615 | (modify-syntax-entry ?\" "." table) | ||
| 1616 | (modify-syntax-entry ?\( "." table) | ||
| 1617 | (modify-syntax-entry ?\[ "." table) | ||
| 1618 | (modify-syntax-entry ?\{ "." table) | ||
| 1619 | (modify-syntax-entry ?\) "." table) | ||
| 1620 | (modify-syntax-entry ?\] "." table) | ||
| 1621 | (modify-syntax-entry ?\} "." table) | ||
| 1622 | table) | ||
| 1623 | "Syntax table for shell output. | ||
| 1624 | It makes parens and quotes be treated as punctuation chars.") | ||
| 1625 | |||
| 1612 | (define-derived-mode inferior-python-mode comint-mode "Inferior Python" | 1626 | (define-derived-mode inferior-python-mode comint-mode "Inferior Python" |
| 1613 | "Major mode for Python inferior process. | 1627 | "Major mode for Python inferior process. |
| 1614 | Runs a Python interpreter as a subprocess of Emacs, with Python | 1628 | Runs a Python interpreter as a subprocess of Emacs, with Python |
| @@ -1637,7 +1651,6 @@ variable. | |||
| 1637 | python-shell-prompt-regexp | 1651 | python-shell-prompt-regexp |
| 1638 | python-shell-prompt-block-regexp | 1652 | python-shell-prompt-block-regexp |
| 1639 | python-shell-prompt-pdb-regexp)) | 1653 | python-shell-prompt-pdb-regexp)) |
| 1640 | (set-syntax-table python-mode-syntax-table) | ||
| 1641 | (setq mode-line-process '(":%s")) | 1654 | (setq mode-line-process '(":%s")) |
| 1642 | (make-local-variable 'comint-output-filter-functions) | 1655 | (make-local-variable 'comint-output-filter-functions) |
| 1643 | (add-hook 'comint-output-filter-functions | 1656 | (add-hook 'comint-output-filter-functions |
| @@ -1658,10 +1671,21 @@ variable. | |||
| 1658 | (make-local-variable 'python-pdbtrack-tracked-buffer) | 1671 | (make-local-variable 'python-pdbtrack-tracked-buffer) |
| 1659 | (make-local-variable 'python-shell-internal-last-output) | 1672 | (make-local-variable 'python-shell-internal-last-output) |
| 1660 | (when python-shell-enable-font-lock | 1673 | (when python-shell-enable-font-lock |
| 1674 | (set-syntax-table python-mode-syntax-table) | ||
| 1661 | (set (make-local-variable 'font-lock-defaults) | 1675 | (set (make-local-variable 'font-lock-defaults) |
| 1662 | '(python-font-lock-keywords nil nil nil nil)) | 1676 | '(python-font-lock-keywords nil nil nil nil)) |
| 1663 | (set (make-local-variable 'syntax-propertize-function) | 1677 | (set (make-local-variable 'syntax-propertize-function) |
| 1664 | python-syntax-propertize-function)) | 1678 | (syntax-propertize-rules |
| 1679 | (comint-prompt-regexp | ||
| 1680 | (0 (ignore | ||
| 1681 | (put-text-property | ||
| 1682 | comint-last-input-start end 'syntax-table | ||
| 1683 | python-shell-output-syntax-table) | ||
| 1684 | (font-lock-unfontify-region comint-last-input-start end)))) | ||
| 1685 | ((python-rx string-delimiter) | ||
| 1686 | (0 (ignore | ||
| 1687 | (and (not (eq (get-text-property start 'field) 'output)) | ||
| 1688 | (python-syntax-stringify)))))))) | ||
| 1665 | (compilation-shell-minor-mode 1)) | 1689 | (compilation-shell-minor-mode 1)) |
| 1666 | 1690 | ||
| 1667 | (defun python-shell-make-comint (cmd proc-name &optional pop internal) | 1691 | (defun python-shell-make-comint (cmd proc-name &optional pop internal) |