emacs-diffs
[Top][All Lists]
Advanced

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

feature/tree-sitter c6384e9bfb 1/2: Fix python-mode tree-sitter fontific


From: Yuan Fu
Subject: feature/tree-sitter c6384e9bfb 1/2: Fix python-mode tree-sitter fontification
Date: Sat, 19 Nov 2022 04:32:18 -0500 (EST)

branch: feature/tree-sitter
commit c6384e9bfbc765229ea9676ba1044b9db28fec2d
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Fix python-mode tree-sitter fontification
    
    Forgot to update python-mode's code when I added the tree-sitter
    notifier facility.  Now it doesn't need any special treatment anymore.
    Leaving it as is causes some incorrect fontification.
    
    * lisp/progmodes/python.el (python--treesit-fontify-string): Accept
    the string node rather than the quote node.
    (python--treesit-settings): Capture string node.
---
 lisp/progmodes/python.el | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 22485a025e..b9b71a57d7 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1014,16 +1014,15 @@ It makes underscores and dots word constituent chars.")
 
 (defun python--treesit-fontify-string (node override start end &rest _)
   "Fontify string.
-NODE is the leading quote in the string.  Do not fontify the
-initial f for f-strings.  OVERRIDE is the override flag described
-in `treesit-font-lock-rules'.  START and END marks the region to
-be fontified."
-  (let* ((string (treesit-node-parent node))
-         (string-beg (treesit-node-start string))
-         (string-end (treesit-node-end string))
+NODE is the string node.  Do not fontify the initial f for
+f-strings.  OVERRIDE is the override flag described in
+`treesit-font-lock-rules'.  START and END marks the region to be
+fontified."
+  (let* ((string-beg (treesit-node-start node))
+         (string-end (treesit-node-end node))
          (maybe-defun (treesit-node-parent
                        (treesit-node-parent
-                        (treesit-node-parent string))))
+                        (treesit-node-parent node))))
          (face (if (member (treesit-node-type maybe-defun)
                            '("function_definition"
                              "class_definition"))
@@ -1043,8 +1042,7 @@ be fontified."
    :feature 'string
    :language 'python
    :override t
-   ;; TODO Document on why we do this.
-   '((string :anchor "\"" @python--treesit-fontify-string))
+   '((string) @python--treesit-fontify-string)
 
    :feature 'string-interpolation
    :language 'python



reply via email to

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