diff options
| author | Fabián Ezequiel Gallina | 2012-09-30 17:14:02 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2012-09-30 17:14:02 -0300 |
| commit | 5727eadff9e9bfd5d0af90e4fbe21697cba444b1 (patch) | |
| tree | 31dc8aef28471cc449ac2ed6c921b7e0ba35780e /lisp/progmodes/python.el | |
| parent | b43d62ae72b1b597b145077537444c422279994e (diff) | |
| download | emacs-5727eadff9e9bfd5d0af90e4fbe21697cba444b1.tar.gz emacs-5727eadff9e9bfd5d0af90e4fbe21697cba444b1.zip | |
Enhancements for triple-quote string syntax.
* progmodes/python.el (python-syntax-propertize-function): Match
both quote cases in one regexp.
(python-syntax-stringify): Handle matches properly.
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index e99e6bda4b8..c5ba9a6aecb 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -499,17 +499,17 @@ 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 | (or (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 | ;; Match single or triple quotes of any kind. |
| 506 | (1 (ignore (python-syntax-stringify)))) | 506 | (group (or "\"" "\"\"\"" "'" "'''"))) |
| 507 | ((rx | 507 | (and |
| 508 | ;; Match odd number of backslashes. | 508 | ;; Match odd number of backslashes. |
| 509 | (or (not (any ?\\)) point) ?\\ (* ?\\ ?\\) | 509 | (or (not (any ?\\)) point) ?\\ (* ?\\ ?\\) |
| 510 | ;; Followed by even number of equal quotes. | 510 | ;; Followed by even number of equal quotes. |
| 511 | (group (or "\"\"" "\"\"\"\"" "''" "''''"))) | 511 | (group (or "\"\"" "\"\"\"\"" "''" "''''"))))) |
| 512 | (1 (ignore (python-syntax-stringify)))))) | 512 | (0 (ignore (python-syntax-stringify)))))) |
| 513 | 513 | ||
| 514 | (defsubst python-syntax-count-quotes (quote-char &optional point limit) | 514 | (defsubst python-syntax-count-quotes (quote-char &optional point limit) |
| 515 | "Count number of quotes around point (max is 3). | 515 | "Count number of quotes around point (max is 3). |
| @@ -526,7 +526,8 @@ is used to limit the scan." | |||
| 526 | (defun python-syntax-stringify () | 526 | (defun python-syntax-stringify () |
| 527 | "Put `syntax-table' property correctly on single/triple quotes." | 527 | "Put `syntax-table' property correctly on single/triple quotes." |
| 528 | (let* ((num-quotes | 528 | (let* ((num-quotes |
| 529 | (let ((n (length (match-string-no-properties 1)))) | 529 | (let ((n (length (or (match-string-no-properties 1) |
| 530 | (match-string-no-properties 2))))) | ||
| 530 | ;; This corrects the quote count when matching odd number | 531 | ;; This corrects the quote count when matching odd number |
| 531 | ;; of backslashes followed by even number of quotes. | 532 | ;; of backslashes followed by even number of quotes. |
| 532 | (or (and (= 1 (logand n 1)) n) (1- n)))) | 533 | (or (and (= 1 (logand n 1)) n) (1- n)))) |