]> git.eshelyaron.com Git - emacs.git/commitdiff
Tweak python-ts-mode fontification
authorYuan Fu <casouri@gmail.com>
Mon, 21 Nov 2022 04:31:42 +0000 (20:31 -0800)
committerYuan Fu <casouri@gmail.com>
Mon, 21 Nov 2022 09:29:31 +0000 (01:29 -0800)
* lisp/progmodes/python.el (python--treesit-fontify-string): Make the
matching condition for docstrings more specific.

lisp/progmodes/python.el

index c49af223c660711bd479b9031db552c150375d11..d38d0292775ae947f16fec03342f132d5366726e 100644 (file)
@@ -1020,12 +1020,18 @@ f-strings.  OVERRIDE is the override flag described in
 fontified."
   (let* ((string-beg (treesit-node-start node))
          (string-end (treesit-node-end node))
+         (maybe-expression (treesit-node-parent node))
          (maybe-defun (treesit-node-parent
                        (treesit-node-parent
-                        (treesit-node-parent node))))
-         (face (if (member (treesit-node-type maybe-defun)
-                           '("function_definition"
-                             "class_definition"))
+                        maybe-expression)))
+         (face (if (and (member (treesit-node-type maybe-defun)
+                                '("function_definition"
+                                  "class_definition"))
+                        ;; This check filters out this case:
+                        ;; def function():
+                        ;;     return "some string"
+                        (equal (treesit-node-type maybe-expression)
+                               "expression_statement"))
                    'font-lock-doc-face
                  'font-lock-string-face)))
     (when (eq (char-after string-beg) ?f)