From 44870df239ba681e826795fc54d69e8d9a517826 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Sun, 19 Sep 2021 11:42:20 +0100 Subject: [PATCH] Make syntax-ppss more accurate for Python triple quotes (bug#49518) By putting delimiter syntax on the "inside" of Python triple-quoted strings, this makes syntax-ppss be more accurate and thus 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. --- lisp/progmodes/python.el | 10 ++++++---- test/lisp/progmodes/python-tests.el | 1 - 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 19b79b69197..da7b92ae42c 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -775,12 +775,14 @@ is used to limit the scan." ;; 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) + ;; This set of quotes delimit the start of a string. Put + ;; the delimiter syntax in the last of the three quotes. + (put-text-property (1- quote-ending-pos) quote-ending-pos 'syntax-table (string-to-syntax "|"))) (t - ;; This set of quotes delimit the end of a string. - (put-text-property (1- quote-ending-pos) quote-ending-pos + ;; This set of quotes delimit the end of a string. Put the + ;; delimiter syntax in the first of the three quotess. + (put-text-property quote-starting-pos (1+ quote-starting-pos) 'syntax-table (string-to-syntax "|")))))) (defvar python-mode-syntax-table diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 1af579bb7a4..a172f0f8e9c 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -193,7 +193,6 @@ aliqua." (ert-deftest python-syntax-after-python-backspace () ;; `python-indent-dedent-line-backspace' garbles syntax - :expected-result :failed (python-tests-with-temp-buffer "\"\"\"" (goto-char (point-max)) -- 2.39.5