unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Randy Taylor <dev@rjt.dev>
To: Yuan Fu <casouri@gmail.com>
Cc: 59268@debbugs.gnu.org
Subject: bug#59268: [PATCH] Utilize new font-lock faces for C/C++ and Python tree-sitter use
Date: Thu, 17 Nov 2022 03:26:29 +0000	[thread overview]
Message-ID: <_eVZXSOw6ehYHpOX5-Uf76Mz8SW9Q1mqy0mEzCSlKU4p9obGA8eaEPhf5yrFKdG293X9pQw7qvz_JYQKQ9gd9Oxxzn4aazUq-5RSp-8-tok=@rjt.dev> (raw)
In-Reply-To: <qjKrRSZJLdUEqznC_YasNTX0mspKCgVAq29wviBaelmbuMe1_Z-L_AWMoRvupyXe1Fs3Fxfzoxt3sGa9mNNVXg17nVjVOP7R34AdMPmNWvQ=@rjt.dev>


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

Updated the patch again to apply cleanly, as there were some more changes to c-ts-mode.el.

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Utilize-new-font-lock-faces-for-C-C-and-Python-tree-.patch --]
[-- Type: text/x-patch; name=0001-Utilize-new-font-lock-faces-for-C-C-and-Python-tree-.patch, Size: 6940 bytes --]

From 7a59ea1a5655ce6c70b86839dad2d5091cafd260 Mon Sep 17 00:00:00 2001
From: Randy Taylor <dev@rjt.dev>
Date: Sun, 13 Nov 2022 22:06:33 -0500
Subject: [PATCH] Utilize new font-lock faces for C/C++ and Python tree-sitter
 use

* lisp/progmodes/c-ts-mode.el (c-ts-mode--font-lock-settings): Use new
escape, number, property, operator, bracket, and delimiter font-lock
faces.
(c-ts-mode--base-mode): Add them to the feature list.
(c-ts-mode): Fix typo.
* lisp/progmodes/python.el (python--treesit-settings): Use new number,
property, operator, bracket, and delimiter font-lock faces.
(python-mode): Add them to the feature list.
---
 lisp/progmodes/c-ts-mode.el | 45 +++++++++++++++++++++++--------------
 lisp/progmodes/python.el    | 41 ++++++++++++++++++++++++++++-----
 2 files changed, 63 insertions(+), 23 deletions(-)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index b951031d81..f45fe59240 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -230,19 +230,17 @@ c-ts-mode--font-lock-settings
 
    :language mode
    :feature 'operator
-   :override t
    `([,@c-ts-mode--operators] @font-lock-operator-face
      "!" @font-lock-negation-char-face)
 
    :language mode
    :feature 'string
    `((string_literal) @font-lock-string-face
-     (system_lib_string) @font-lock-string-face
-     (escape_sequence) @font-lock-escape-face)
+     (system_lib_string) @font-lock-string-face)
 
    :language mode
    :feature 'literal
-   `((number_literal) @font-lock-constant-face
+   `((number_literal) @font-lock-number-face
      (char_literal) @font-lock-constant-face)
 
    :language mode
@@ -268,14 +266,11 @@ c-ts-mode--font-lock-settings
       declarator: (_) @c-ts-mode--fontify-struct-declarator)
 
      (function_definition
-      declarator: (_) @c-ts-mode--fontify-struct-declarator)
+      declarator: (_) @c-ts-mode--fontify-struct-declarator))
 
      ;; Should we highlight identifiers in the parameter list?
      ;; (parameter_declaration
-     ;;  declarator: (_) @c-ts-mode--fontify-struct-declarator)
-
-     (enumerator
-      name: (identifier) @font-lock-variable-name-face))
+     ;;  declarator: (_) @c-ts-mode--fontify-struct-declarator))
 
    :language mode
    :feature 'assignment
@@ -284,8 +279,6 @@ c-ts-mode--font-lock-settings
    ;; inspiration.
    '((assignment_expression
       left: (identifier) @font-lock-variable-name-face)
-     (assignment_expression
-      left: (field_expression field: (_) @font-lock-property-face))
      (assignment_expression
       left: (pointer_expression
              (identifier) @font-lock-variable-name-face))
@@ -298,8 +291,7 @@ c-ts-mode--font-lock-settings
    '((call_expression
       function: (identifier) @font-lock-function-name-face)
      (field_expression
-      argument: (identifier) @font-lock-variable-name-face
-      field: (field_identifier) @font-lock-property-face)
+      argument: (identifier) @font-lock-variable-name-face)
      (pointer_expression
       (identifier) @font-lock-variable-name-face))
 
@@ -313,6 +305,24 @@ c-ts-mode--font-lock-settings
    :feature 'error
    '((ERROR) @font-lock-warning-face)
 
+   :feature 'escape-sequence
+   :language mode
+   '((escape_sequence) @font-lock-escape-face)
+
+   :language mode
+   :feature 'property
+   '((field_identifier) @font-lock-property-face
+     (enumerator
+      name: (identifier) @font-lock-property-face))
+
+   :language mode
+   :feature 'bracket
+   '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
+
+   :language mode
+   :feature 'delimiter
+   '((["," ":" ";"]) @font-lock-delimiter-face)
+
    :language mode
    :feature 'emacs-devel
    '(((call_expression function: (identifier) @fn)
@@ -471,9 +481,10 @@ c-ts-mode--base-mode
   (setq-local which-func-functions nil)
 
   (setq-local treesit-font-lock-feature-list
-              '((comment preprocessor constant string literal keyword)
-                (type definition label assignment)
-                (expression error operator))))
+              '(( comment constant keyword literal preprocessor string)
+                ( assignment definition label property type)
+                ( bracket delimiter error escape-sequence expression
+                  operator))))
 
 ;;;###autoload
 (define-derived-mode c-ts-mode c-ts-mode--base-mode "C"
@@ -500,7 +511,7 @@ c-ts-mode
 
 ;;;###autoload
 (define-derived-mode c++-ts-mode c-ts-mode--base-mode "C++"
-  "Major mode for editing C, powered by tree-sitter."
+  "Major mode for editing C++, powered by tree-sitter."
   :group 'c++
 
   (unless (treesit-ready-p nil 'cpp)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index ad4665eb19..22485a025e 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -975,11 +975,8 @@ python--treesit-constants
     "copyright" "credits" "exit" "license" "quit"))
 
 (defvar python--treesit-operators
-  ;; This is not used. And and, or, not, is, in are fontified as
-  ;; keywords.
   '("-" "-=" "!=" "*" "**" "**=" "*=" "/" "//" "//=" "/=" "&" "%" "%="
-    "^" "+" "+=" "<" "<<" "<=" "<>" "=" "==" ">" ">=" ">>" "|" "~"
-    "and" "in" "is" "not" "or"))
+    "^" "+" "+=" "<" "<<" "<=" "<>" "=" "==" ">" ">=" ">>" "|" "~"))
 
 (defvar python--treesit-special-attributes
   '("__annotations__" "__closure__" "__code__"
@@ -1117,7 +1114,38 @@ python--treesit-settings
    :feature 'escape-sequence
    :language 'python
    :override t
-   '((escape_sequence) @font-lock-escape-face))
+   '((escape_sequence) @font-lock-escape-face)
+
+   :feature 'number
+   :language 'python
+   :override t
+   '([(integer) (float)] @font-lock-number-face)
+
+   :feature 'property
+   :language 'python
+   :override t
+   '((attribute
+      attribute: (identifier) @font-lock-property-face)
+     (class_definition
+      body: (block
+             (expression_statement
+              (assignment left:
+                          (identifier) @font-lock-property-face)))))
+
+   :feature 'operator
+   :language 'python
+   :override t
+   `([,@python--treesit-operators] @font-lock-operator-face)
+
+   :feature 'bracket
+   :language 'python
+   :override t
+   '(["(" ")" "[" "]" "{" "}"] @font-lock-bracket-face)
+
+   :feature 'delimiter
+   :language 'python
+   :override t
+   '(["," "." ":" ";" (ellipsis)] @font-lock-delimiter-face))
   "Tree-sitter font-lock settings.")
 
 \f
@@ -6553,7 +6581,8 @@ python-mode
                 '(( comment string function-name class-name)
                   ( keyword builtin constant type)
                   ( assignment decorator escape-sequence
-                    string-interpolation)))
+                    string-interpolation number property
+                    operator bracket delimiter)))
     (setq-local treesit-font-lock-settings python--treesit-settings)
     (setq-local imenu-create-index-function
                 #'python-imenu-treesit-create-index)
-- 
2.38.1


  reply	other threads:[~2022-11-17  3:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-14  3:27 bug#59268: [PATCH] Utilize new font-lock faces for C/C++ and Python tree-sitter use Randy Taylor
2022-11-15  1:26 ` Randy Taylor
2022-11-16  2:04   ` Randy Taylor
2022-11-17  3:26     ` Randy Taylor [this message]
2022-11-17  3:39       ` Yuan Fu
2022-11-17 13:50         ` Randy Taylor
2022-11-17 18:39           ` Yuan Fu
2022-11-17 20:02             ` Randy Taylor
2022-11-17 20:07               ` Yuan Fu
2022-11-17 20:19                 ` Randy Taylor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='_eVZXSOw6ehYHpOX5-Uf76Mz8SW9Q1mqy0mEzCSlKU4p9obGA8eaEPhf5yrFKdG293X9pQw7qvz_JYQKQ9gd9Oxxzn4aazUq-5RSp-8-tok=@rjt.dev' \
    --to=dev@rjt.dev \
    --cc=59268@debbugs.gnu.org \
    --cc=casouri@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).