all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#70478: 30.0.50; [PATCH] Fix treesitter-font-lock-settings for built-in functions and attributes.
@ 2024-04-19 21:00 Prateek Sharma
  2024-04-20  6:13 ` Eli Zaretskii
  0 siblings, 1 reply; 22+ messages in thread
From: Prateek Sharma @ 2024-04-19 21:00 UTC (permalink / raw)
  To: 70478


[-- Attachment #1.1: Type: text/plain, Size: 580 bytes --]

Dear maintainers,

I do a lot of programming in python and have noticed that if there is a
method of a class defined with the same name as a builtin function. It
gets highlighted with the face for builtin functions and it looks
different for all the other functions and confuses me sometimes and just
looks inconsistent.

I have made a simple fix to the treesitter query and it seems to have
fixed the problem.

Please share you thoughts on this fix. This is my first time
contributing to an open-source project and to emacs. Very excited to
hear from you guys!!!

Prateek Sharma

[-- Attachment #1.2: Type: text/html, Size: 651 bytes --]

[-- Attachment #2: 0001-Fix-treesitter-font-lock-settings-for-built-in-funct.patch --]
[-- Type: application/octet-stream, Size: 2678 bytes --]

From 3ba23aea28796b801832baf1aa5e1092cff88e6e Mon Sep 17 00:00:00 2001
From: Prateek Sharma <ps.prateek.sharma143@gmail.com>
Date: Sat, 20 Apr 2024 02:06:17 +0530
Subject: [PATCH] Fix treesitter-font-lock-settings for built-in functions and
 attributes.

* etc/NEWS: Announce the effect of the changes for the treesitter-font-lock-settings for built-in functions and attributes
* lisp/progmodes/python.el (python--treesit-settings): Change the treesitter query to fetch the correct type of node for built-in functions and attributes and highlight them with corresponding font-lock face.
---
 etc/NEWS                 |  9 +++++++++
 lisp/progmodes/python.el | 13 ++++++-------
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 8ad1e78ca60..e5cd70b6106 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1319,6 +1319,15 @@ instead of:
 This allows the user to specify command line arguments to the non
 interactive Python interpreter specified by 'python-interpreter'.
 
+*** Treesitter syntax highlighting for built-in functions fixed
+The fix highlights only the correct built-in function calls and
+attributes with font-lock-builtin-face. When some class defines
+a function with the same name as a built-in function, earlier it was
+being highlighted with the same font-lock-builtin-face, which was
+incorrect. Now, normal user defined functions will be highlighted
+with font-lock-function-call-face face and built-in functions and
+attributes will be highlighted with font-lock-builtin-face.
+
 ** Scheme mode
 Scheme mode now handles regular expression literal '#/regexp/' that is
 available in some Scheme implementations.
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 85279d3e84b..5c67d0765eb 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1206,13 +1206,12 @@ fontified."
 
    :feature 'builtin
    :language 'python
-   `(((identifier) @font-lock-builtin-face
-      (:match ,(rx-to-string
-                `(seq bol
-                      (or ,@python--treesit-builtins
-                          ,@python--treesit-special-attributes)
-                      eol))
-              @font-lock-builtin-face)))
+   `((call function: (identifier) @font-lock-builtin-face
+           (:match ,(rx-to-string `(seq bol (or ,@python--treesit-builtins) eol))
+                   @font-lock-builtin-face))
+     (attribute attribute: (identifier) @font-lock-builtin-face
+                (:match ,(rx-to-string `(seq bol (or ,@python--treesit-special-attributes) eol))
+                        @font-lock-builtin-face)))
 
    :feature 'decorator
    :language 'python
-- 
2.39.3 (Apple Git-146)


^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2024-04-24 15:33 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-19 21:00 bug#70478: 30.0.50; [PATCH] Fix treesitter-font-lock-settings for built-in functions and attributes Prateek Sharma
2024-04-20  6:13 ` Eli Zaretskii
2024-04-20  6:54   ` Prateek Sharma
2024-04-20  6:55     ` Prateek Sharma
2024-04-20  7:41       ` Eli Zaretskii
2024-04-20  7:53         ` Prateek Sharma
2024-04-21  3:47           ` Yuan Fu
2024-04-21  5:16             ` Prateek Sharma
2024-04-21  5:27             ` Eli Zaretskii
2024-04-21 23:39               ` Yuan Fu
2024-04-22  2:29                 ` Prateek Sharma
2024-04-22  6:36                   ` Yuan Fu
     [not found]                     ` <CALFrjHxRZyriFw4cS-hQWZbbVbf5otnP6qGqZAY42z=Tf648Nw@mail.gmail.com>
2024-04-22 15:50                       ` Yuan Fu
2024-04-22 16:18                         ` Prateek Sharma
2024-04-22 16:21                         ` Eli Zaretskii
2024-04-23  4:26                           ` Yuan Fu
2024-04-23  6:14                             ` Eli Zaretskii
2024-04-24 13:46                               ` Prateek Sharma
2024-04-24 15:31                                 ` Eli Zaretskii
2024-04-24 15:33                                   ` Prateek Sharma
2024-04-22  6:28                 ` Eli Zaretskii
2024-04-22  6:34                   ` Yuan Fu

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.