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.
parent 05e153a6
2012-10-03 Fabián Ezequiel Gallina <fgallina@cuca>
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.
2012-10-03 Glenn Morris <rgm@gnu.org> 2012-10-03 Glenn Morris <rgm@gnu.org>
* help-macro.el (three-step-help): * help-macro.el (three-step-help):
......
...@@ -499,16 +499,15 @@ The type returned can be `comment', `string' or `paren'." ...@@ -499,16 +499,15 @@ The type returned can be `comment', `string' or `paren'."
(defconst python-syntax-propertize-function (defconst python-syntax-propertize-function
(syntax-propertize-rules (syntax-propertize-rules
((rx ((rx
(or (and (and
;; Match even number of backslashes. ;; Match even number of backslashes.
(or (not (any ?\\ ?\' ?\")) point) (* ?\\ ?\\) (or (not (any ?\\ ?\' ?\")) point
;; Match single or triple quotes of any kind. ;; Quotes might be preceeded by a escaped quote.
(group (or "\"" "\"\"\"" "'" "'''"))) (and (or (not (any ?\\)) point) ?\\
(and (* ?\\ ?\\) (any ?\' ?\")))
;; Match odd number of backslashes. (* ?\\ ?\\)
(or (not (any ?\\)) point) ?\\ (* ?\\ ?\\) ;; Match single or triple quotes of any kind.
;; Followed by even number of equal quotes. (group (or "\"" "\"\"\"" "'" "'''"))))
(group (or "\"\"" "\"\"\"\"" "''" "''''")))))
(0 (ignore (python-syntax-stringify)))))) (0 (ignore (python-syntax-stringify))))))
(defsubst python-syntax-count-quotes (quote-char &optional point limit) (defsubst python-syntax-count-quotes (quote-char &optional point limit)
...@@ -525,12 +524,7 @@ is used to limit the scan." ...@@ -525,12 +524,7 @@ is used to limit the scan."
(defun python-syntax-stringify () (defun python-syntax-stringify ()
"Put `syntax-table' property correctly on single/triple quotes." "Put `syntax-table' property correctly on single/triple quotes."
(let* ((num-quotes (let* ((num-quotes (length (match-string-no-properties 1)))
(let ((n (length (or (match-string-no-properties 1)
(match-string-no-properties 2)))))
;; This corrects the quote count when matching odd number
;; of backslashes followed by even number of quotes.
(or (and (= 1 (logand n 1)) n) (1- n))))
(ppss (prog2 (ppss (prog2
(backward-char num-quotes) (backward-char num-quotes)
(syntax-ppss) (syntax-ppss)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment