Commit 5727eadf authored by Fabián Ezequiel Gallina's avatar Fabián Ezequiel Gallina
Browse files

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.
parent b43d62ae
...@@ -499,17 +499,17 @@ The type returned can be `comment', `string' or `paren'." ...@@ -499,17 +499,17 @@ 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
;; 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. ;; Match single or triple quotes of any kind.
(group (or "\"" "\"\"\"" "'" "'''"))) (group (or "\"" "\"\"\"" "'" "'''")))
(1 (ignore (python-syntax-stringify)))) (and
((rx
;; Match odd number of backslashes. ;; Match odd number of backslashes.
(or (not (any ?\\)) point) ?\\ (* ?\\ ?\\) (or (not (any ?\\)) point) ?\\ (* ?\\ ?\\)
;; Followed by even number of equal quotes. ;; Followed by even number of equal quotes.
(group (or "\"\"" "\"\"\"\"" "''" "''''"))) (group (or "\"\"" "\"\"\"\"" "''" "''''")))))
(1 (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)
"Count number of quotes around point (max is 3). "Count number of quotes around point (max is 3).
...@@ -526,7 +526,8 @@ is used to limit the scan." ...@@ -526,7 +526,8 @@ 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
(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 ;; This corrects the quote count when matching odd number
;; of backslashes followed by even number of quotes. ;; of backslashes followed by even number of quotes.
(or (and (= 1 (logand n 1)) n) (1- n)))) (or (and (= 1 (logand n 1)) n) (1- n))))
......
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