aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorJoão Távora2021-09-19 11:42:20 +0100
committerJoão Távora2021-09-21 10:56:27 +0100
commit0646c6817139aa905a2f6079fdc82eb4be944de0 (patch)
tree99744a6d07ea4486b2abd0911c9aa3c22de96747 /lisp/progmodes/python.el
parent9ad962e118a17daf073ef5308233f9301755035d (diff)
downloademacs-0646c6817139aa905a2f6079fdc82eb4be944de0.tar.gz
emacs-0646c6817139aa905a2f6079fdc82eb4be944de0.zip
Make syntax-ppss more accurate for Python triple quotes (bug#49518)
By putting delimiter syntax on the last character of Python triple-quoted strings, this makes syntax-ppss be more accurate. Previously: emacs -Q something.py type two single quotes M-: (nth 3 (syntax-ppss)) notice how the return value says you're outside a string, correctly type another quote M-: (nth 3 (syntax-ppss)) notice how the return value says you're inside a string, correctly backspace the quote just entered M-: (nth 3 (syntax-ppss)) notice how the return value says you're inside a string, incorrectly With this patch the last step is corrected. This helps things like electric-pair-mode. Also, the test python-syntax-after-python-backspace now passes, again. * lisp/progmodes/python.el (python-syntax-stringify): Put delimiter syntax in "inner" of the surrouding triple quotes. * test/lisp/progmodes/python-tests.el (python-syntax-after-python-backspace): Passes again.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el11
1 files changed, 7 insertions, 4 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index f848f4c1030..7818ab1ab05 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -775,12 +775,14 @@ is used to limit the scan."
775 ;; The first quote is escaped, so it's not part of a triple quote! 775 ;; The first quote is escaped, so it's not part of a triple quote!
776 (goto-char (1+ quote-starting-pos))) 776 (goto-char (1+ quote-starting-pos)))
777 ((null string-start) 777 ((null string-start)
778 ;; This set of quotes delimit the start of a string. 778 ;; This set of quotes delimit the start of a string. Put
779 (put-text-property quote-starting-pos (1+ quote-starting-pos) 779 ;; string fence syntax on last quote. (bug#49518)
780 (put-text-property (1- quote-ending-pos) quote-ending-pos
780 'syntax-table (string-to-syntax "|"))) 781 'syntax-table (string-to-syntax "|")))
781 (t 782 (t
782 ;; This set of quotes delimit the end of a string. 783 ;; This set of quotes delimit the end of a string. Put
783 (put-text-property (1- quote-ending-pos) quote-ending-pos 784 ;; string fence syntax on first quote. (bug#49518)
785 (put-text-property quote-starting-pos (1+ quote-starting-pos)
784 'syntax-table (string-to-syntax "|")))))) 786 'syntax-table (string-to-syntax "|"))))))
785 787
786(defvar python-mode-syntax-table 788(defvar python-mode-syntax-table
@@ -4308,6 +4310,7 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'."
4308 (and (equal (string-to-syntax "|") 4310 (and (equal (string-to-syntax "|")
4309 (syntax-after (point))) 4311 (syntax-after (point)))
4310 (point))))) 4312 (point)))))
4313 ;; JT@2021-09-21: Since bug#49518's fix this will always be 1
4311 (num-quotes (python-syntax-count-quotes 4314 (num-quotes (python-syntax-count-quotes
4312 (char-after str-start-pos) str-start-pos)) 4315 (char-after str-start-pos) str-start-pos))
4313 (str-line-start-pos 4316 (str-line-start-pos