diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2019-04-09 15:08:21 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2019-04-09 15:08:21 -0400 |
commit | 4b39b741f1949ebad1dfccc5032dfce521bedc2a (patch) | |
tree | ad093eab789e968f364529104c1b602c2a0b9531 | |
parent | c44313327588b5d2aafe9234e71f081f39a16082 (diff) | |
download | emacs-4b39b741f1949ebad1dfccc5032dfce521bedc2a.tar.gz |
python.el: don't syntax-propertize single/double quoted strings
* lisp/progmodes/python.el (python-syntax-propertize-function):
Only mark triple-quoted strings, let the normal syntax-table handle
the rest.
(python-syntax-stringify): Adjust accordingly.
-rw-r--r-- | lisp/progmodes/python.el | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 5d0d03d5029..b05f9a33e90 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -675,7 +675,7 @@ Which one will be chosen depends on the value of (defconst python-syntax-propertize-function (syntax-propertize-rules - ((python-rx string-delimiter) + ((rx (or "\"\"\"" "'''")) (0 (ignore (python-syntax-stringify)))))) (define-obsolete-variable-alias 'python--prettify-symbols-alist @@ -701,35 +701,27 @@ is used to limit the scan." (defun python-syntax-stringify () "Put `syntax-table' property correctly on single/triple quotes." - (let* ((num-quotes (length (match-string-no-properties 1))) - (ppss (prog2 - (backward-char num-quotes) - (syntax-ppss) - (forward-char num-quotes))) - (string-start (and (not (nth 4 ppss)) (nth 8 ppss))) - (quote-starting-pos (- (point) num-quotes)) - (quote-ending-pos (point)) - (num-closing-quotes - (and string-start - (python-syntax-count-quotes - (char-before) string-start quote-starting-pos)))) - (cond ((and string-start (= num-closing-quotes 0)) - ;; This set of quotes doesn't match the string starting - ;; kind. Do nothing. + (let* ((ppss (save-excursion (backward-char 3) (syntax-ppss))) + (string-start (and (eq t (nth 3 ppss)) (nth 8 ppss))) + (quote-starting-pos (- (point) 3)) + (quote-ending-pos (point))) + (cond ((or (nth 4 ppss) ;Inside a comment + (and string-start + ;; Inside of a string quoted with different triple quotes. + (not (eql (char-after string-start) + (char-after quote-starting-pos))))) + ;; Do nothing. nil) - ((not string-start) + ((nth 5 ppss) + ;; The first quote is escaped, so it's not part of a triple quote! + (goto-char (1+ quote-starting-pos))) + ((null string-start) ;; This set of quotes delimit the start of a string. (put-text-property quote-starting-pos (1+ quote-starting-pos) 'syntax-table (string-to-syntax "|"))) - ((= num-quotes num-closing-quotes) + (t ;; This set of quotes delimit the end of a string. (put-text-property (1- quote-ending-pos) quote-ending-pos - 'syntax-table (string-to-syntax "|"))) - ((> num-quotes num-closing-quotes) - ;; This may only happen whenever a triple quote is closing - ;; a single quoted string. Add string delimiter syntax to - ;; all three quotes. - (put-text-property quote-starting-pos quote-ending-pos 'syntax-table (string-to-syntax "|")))))) (defvar python-mode-syntax-table |