emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 09cdf8a406c: Fix syntax highlighting after string literal concat


From: Eli Zaretskii
Subject: master 09cdf8a406c: Fix syntax highlighting after string literal concat in python-mode
Date: Sat, 27 Jan 2024 05:06:28 -0500 (EST)

branch: master
commit 09cdf8a406c5b73e8924a7396c2aaabe74a1a638
Author: Jakub Ječmínek <jecminek.k@gmail.com>
Commit: Eli Zaretskii <eliz@gnu.org>

    Fix syntax highlighting after string literal concat in python-mode
    
    * lisp/progmodes/python.el (python-syntax-stringify): Fix
    incorrect font-lock after string literal concatenation.
    (Bug#45897)
    
    * test/lisp/progmodes/python-tests.el
    (python-font-lock-string-literal-concatenation): New test.
    
    Co-authored-by: kobarity <kobarity@gmail.com>
    Copyright-paperwork-exempt: yes
---
 lisp/progmodes/python.el            |  3 +++
 test/lisp/progmodes/python-tests.el | 12 ++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 41f612c8b1c..9d840efb9da 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -909,6 +909,7 @@ is used to limit the scan."
   "Put `syntax-table' property correctly on single/triple quotes."
   (let* ((ppss (save-excursion (backward-char 3) (syntax-ppss)))
          (string-start (and (eq t (nth 3 ppss)) (nth 8 ppss)))
+         (string-literal-concat (numberp (nth 3 ppss)))
          (quote-starting-pos (- (point) 3))
          (quote-ending-pos (point)))
     (cond ((or (nth 4 ppss)             ;Inside a comment
@@ -921,6 +922,8 @@ is used to limit the scan."
           ((nth 5 ppss)
            ;; The first quote is escaped, so it's not part of a triple quote!
            (goto-char (1+ quote-starting-pos)))
+          ;; Handle string literal concatenation (bug#45897)
+          (string-literal-concat nil)
           ((null string-start)
            ;; This set of quotes delimit the start of a string.  Put
            ;; string fence syntax on last quote. (bug#49518)
diff --git a/test/lisp/progmodes/python-tests.el 
b/test/lisp/progmodes/python-tests.el
index 97ffd5fe20f..59957ff0712 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -660,6 +660,18 @@ r'\\x12 \123 \\n \\u1234 \\U00010348 \\N{Plus-Minus Sign}'"
      (3 . font-lock-string-face) (14)
      (16 . font-lock-string-face))))
 
+(ert-deftest python-font-lock-string-literal-concatenation ()
+  "Test for bug#45897."
+  (python-tests-assert-faces
+   "x = \"hello\"\"\"
+y = \"confused\""
+   '((1 . font-lock-variable-name-face) (2)
+     (3 . font-lock-operator-face) (4)
+     (5 . font-lock-string-face) (14)
+     (15 . font-lock-variable-name-face) (16)
+     (17 . font-lock-operator-face) (18)
+     (19 . font-lock-string-face))))
+
 
 ;;; Indentation
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]