emacs-diffs
[Top][All Lists]
Advanced

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

master 71cd290c20d: Fix font-lock of Python f-strings


From: Stefan Monnier
Subject: master 71cd290c20d: Fix font-lock of Python f-strings
Date: Fri, 13 Dec 2024 18:34:01 -0500 (EST)

branch: master
commit 71cd290c20dbbd8b14f09818b3c1b58623aea350
Author: kobarity <kobarity@gmail.com>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    Fix font-lock of Python f-strings
    
    * lisp/progmodes/python.el (python--font-lock-f-strings): Bind
    'parse-sexp-ignore-comments' to nil so that we can look for
    closing braces even if a hash is used in the format specifier.
    * test/lisp/progmodes/python-tests.el
    (python-font-lock-f-string-1): New test.  (Bug#74738)
---
 lisp/progmodes/python.el            | 4 +++-
 test/lisp/progmodes/python-tests.el | 8 ++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 4a1cfc6c072..5729b12573f 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -623,7 +623,9 @@ the {...} holes that appear within f-strings."
               (forward-char 1)          ;Just skip over {{
             (let ((beg (match-beginning 0))
                   (end (condition-case nil
-                           (progn (up-list 1) (min send (point)))
+                           (let ((parse-sexp-ignore-comments))
+                             (up-list 1)
+                             (min send (point)))
                          (scan-error send))))
               (goto-char end)
               (put-text-property beg end 'face nil))))
diff --git a/test/lisp/progmodes/python-tests.el 
b/test/lisp/progmodes/python-tests.el
index 4cc4040d0ff..ac17c5b1263 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -709,6 +709,14 @@ y = \"confused\""
      (17 . font-lock-operator-face) (18)
      (19 . font-lock-string-face))))
 
+(ert-deftest python-font-lock-f-string-1 ()
+  "Test for bug#74738."
+  (python-tests-assert-faces
+   "print(f\"{value:#x} is a value\")"
+   '((1 . font-lock-builtin-face) (6)
+     (8 . font-lock-string-face) (9)
+     (19 . font-lock-string-face) (31))))
+
 
 ;;; Indentation
 



reply via email to

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