From a1a9f411ab644cb191442ea1de4bc1370341cc88 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabi=C3=A1n=20Ezequiel=20Gallina?= Date: Wed, 3 Oct 2012 18:53:09 -0300 Subject: [PATCH] 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. --- lisp/ChangeLog | 9 +++++++++ lisp/progmodes/python.el | 26 ++++++++++---------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 32540b213dc..689659fd797 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2012-10-03 Fabián Ezequiel Gallina + + 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 * help-macro.el (three-step-help): 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'." (defconst python-syntax-propertize-function (syntax-propertize-rules ((rx - (or (and - ;; Match even number of backslashes. - (or (not (any ?\\ ?\' ?\")) point) (* ?\\ ?\\) - ;; Match single or triple quotes of any kind. - (group (or "\"" "\"\"\"" "'" "'''"))) - (and - ;; Match odd number of backslashes. - (or (not (any ?\\)) point) ?\\ (* ?\\ ?\\) - ;; Followed by even number of equal quotes. - (group (or "\"\"" "\"\"\"\"" "''" "''''"))))) + (and + ;; Match even number of backslashes. + (or (not (any ?\\ ?\' ?\")) point + ;; Quotes might be preceeded by a escaped quote. + (and (or (not (any ?\\)) point) ?\\ + (* ?\\ ?\\) (any ?\' ?\"))) + (* ?\\ ?\\) + ;; Match single or triple quotes of any kind. + (group (or "\"" "\"\"\"" "'" "'''")))) (0 (ignore (python-syntax-stringify)))))) (defsubst python-syntax-count-quotes (quote-char &optional point limit) @@ -525,12 +524,7 @@ is used to limit the scan." (defun python-syntax-stringify () "Put `syntax-table' property correctly on single/triple quotes." - (let* ((num-quotes - (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)))) + (let* ((num-quotes (length (match-string-no-properties 1))) (ppss (prog2 (backward-char num-quotes) (syntax-ppss) -- 2.39.2