From: Fabián Ezequiel Gallina Date: Sun, 30 Sep 2012 20:14:02 +0000 (-0300) Subject: Enhancements for triple-quote string syntax. X-Git-Tag: emacs-24.2.90~241^2~89 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5727eadff9e9bfd5d0af90e4fbe21697cba444b1;p=emacs.git 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. --- 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'." (defconst python-syntax-propertize-function (syntax-propertize-rules ((rx - ;; Match even number of backslashes. - (or (not (any ?\\ ?\' ?\")) point) (* ?\\ ?\\) - ;; Match single or triple quotes of any kind. - (group (or "\"" "\"\"\"" "'" "'''"))) - (1 (ignore (python-syntax-stringify)))) - ((rx - ;; Match odd number of backslashes. - (or (not (any ?\\)) point) ?\\ (* ?\\ ?\\) - ;; Followed by even number of equal quotes. - (group (or "\"\"" "\"\"\"\"" "''" "''''"))) - (1 (ignore (python-syntax-stringify)))))) + (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 "\"\"" "\"\"\"\"" "''" "''''"))))) + (0 (ignore (python-syntax-stringify)))))) (defsubst python-syntax-count-quotes (quote-char &optional point limit) "Count number of quotes around point (max is 3). @@ -526,7 +526,8 @@ 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 (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))))