diff options
| author | Fabián Ezequiel Gallina | 2012-10-03 18:53:09 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2012-10-03 18:53:09 -0300 |
| commit | a1a9f411ab644cb191442ea1de4bc1370341cc88 (patch) | |
| tree | c225b549638004b6d951f4eec538b6048219af7d /lisp/progmodes/python.el | |
| parent | 05e153a645e17fd83f673ed6b243dae00feff647 (diff) | |
| download | emacs-a1a9f411ab644cb191442ea1de4bc1370341cc88.tar.gz emacs-a1a9f411ab644cb191442ea1de4bc1370341cc88.zip | |
Fix cornercase for string syntax.
* progmodes/python.el (python-syntax-propertize-function):
Simplify and enhance the regexp for unescaped quotes. Now it also
matches quotes in weird situations like the single quote in
"something\"'".
(python-syntax-stringify): Simplify num-quotes detecting code.
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 26758105218..f5e4bffd598 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -499,16 +499,15 @@ 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 | (or (and | 502 | (and |
| 503 | ;; Match even number of backslashes. | 503 | ;; Match even number of backslashes. |
| 504 | (or (not (any ?\\ ?\' ?\")) point) (* ?\\ ?\\) | 504 | (or (not (any ?\\ ?\' ?\")) point |
| 505 | ;; Match single or triple quotes of any kind. | 505 | ;; Quotes might be preceeded by a escaped quote. |
| 506 | (group (or "\"" "\"\"\"" "'" "'''"))) | 506 | (and (or (not (any ?\\)) point) ?\\ |
| 507 | (and | 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 "\"\"" "\"\"\"\"" "''" "''''"))))) | ||
| 512 | (0 (ignore (python-syntax-stringify)))))) | 511 | (0 (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) |
| @@ -525,12 +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 (or (match-string-no-properties 1) | ||
| 530 | (match-string-no-properties 2))))) | ||
| 531 | ;; This corrects the quote count when matching odd number | ||
| 532 | ;; of backslashes followed by even number of quotes. | ||
| 533 | (or (and (= 1 (logand n 1)) n) (1- n)))) | ||
| 534 | (ppss (prog2 | 528 | (ppss (prog2 |
| 535 | (backward-char num-quotes) | 529 | (backward-char num-quotes) |
| 536 | (syntax-ppss) | 530 | (syntax-ppss) |