]> git.eshelyaron.com Git - emacs.git/commitdiff
Make syntax-ppss more accurate for Python triple quotes (bug#49518)
authorJoão Távora <joaotavora@gmail.com>
Sun, 19 Sep 2021 10:42:20 +0000 (11:42 +0100)
committerJoão Távora <joaotavora@gmail.com>
Tue, 21 Sep 2021 09:56:27 +0000 (10:56 +0100)
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.

lisp/progmodes/python.el
test/lisp/progmodes/python-tests.el

index f848f4c1030009d7ce976ce761cd8b4b28fb25eb..7818ab1ab05a0ac2390986cc2f1c183a29664671 100644 (file)
@@ -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
+           ;; string fence syntax on last quote. (bug#49518)
+           (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
+           ;; string fence syntax on first quote. (bug#49518)
+           (put-text-property quote-starting-pos (1+ quote-starting-pos)
                               'syntax-table (string-to-syntax "|"))))))
 
 (defvar python-mode-syntax-table
@@ -4308,6 +4310,7 @@ JUSTIFY should be used (if applicable) as in `fill-paragraph'."
                (and (equal (string-to-syntax "|")
                            (syntax-after (point)))
                     (point)))))
+         ;; JT@2021-09-21: Since bug#49518's fix this will always be 1
          (num-quotes (python-syntax-count-quotes
                       (char-after str-start-pos) str-start-pos))
          (str-line-start-pos
index afdae4c75c6f4d10bd4e5f81fc91439a552e0e2a..6ab9c62746e840b5f517c53a4cd14117d22673e5 100644 (file)
@@ -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))