all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#59268: [PATCH] Utilize new font-lock faces for C/C++ and Python tree-sitter use
@ 2022-11-14  3:27 Randy Taylor
  2022-11-15  1:26 ` Randy Taylor
  0 siblings, 1 reply; 10+ messages in thread
From: Randy Taylor @ 2022-11-14  3:27 UTC (permalink / raw)
  To: 59268


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

I'm just submitting C/C++ and Python for now since some of the other files are
a little more volatile currently (there are some patches in progress).

Will probably need to update this patch after Theo's stuff is pushed.

I would also like to reorganize the features to be sorted
alphabetically, but I'll wait for things to calm down a little beforedoing that.

[-- Attachment #1.2: Type: text/html, Size: 959 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: 8131 bytes --]

From 4d01527a7af375b68579934d745edf0dc2a8f11e 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.  Simplify type matching.
(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 | 74 ++++++++++++++++---------------------
 lisp/progmodes/python.el    | 41 +++++++++++++++++---
 2 files changed, 66 insertions(+), 49 deletions(-)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 5617ea7d7c..065ee5c12c 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -229,18 +229,17 @@ c-ts-mode--font-lock-settings
    :language mode
    :override t
    :feature 'operator
-   `([,@c-ts-mode--operators] @font-lock-builtin-face)
+   `([,@c-ts-mode--operators] @font-lock-operator-face)
    :language mode
    :override t
    :feature 'string
    `((string_literal) @font-lock-string-face
      ((string_literal)) @contextual
-     (system_lib_string) @font-lock-string-face
-     (escape_sequence) @font-lock-string-face)
+     (system_lib_string) @font-lock-string-face)
    :language mode
    :override t
    :feature 'literal
-   `((number_literal) @font-lock-constant-face
+   `((number_literal) @font-lock-number-face
      (char_literal) @font-lock-constant-face)
    :language mode
    :override t
@@ -250,30 +249,13 @@ c-ts-mode--font-lock-settings
          '((type_qualifier) @font-lock-type-face
 
            (qualified_identifier
-            scope: (namespace_identifier) @font-lock-type-face)
-
-           (operator_cast) type: (type_identifier) @font-lock-type-face)))
+            scope: (namespace_identifier) @font-lock-type-face))))
    :language mode
    :override t
    :feature 'definition
    `((declaration
       declarator: (identifier) @font-lock-variable-name-face)
 
-     (declaration
-      type: (type_identifier) @font-lock-type-face)
-
-     (field_declaration
-      declarator: (field_identifier) @font-lock-variable-name-face)
-
-     (field_declaration
-      type: (type_identifier) @font-lock-type-face)
-
-     (parameter_declaration
-      type: (type_identifier) @font-lock-type-face)
-
-     (function_definition
-      type: (type_identifier) @font-lock-type-face)
-
      (function_declarator
       declarator: (identifier) @font-lock-function-name-face)
 
@@ -283,17 +265,8 @@ c-ts-mode--font-lock-settings
      (init_declarator
       declarator: (identifier) @font-lock-variable-name-face)
 
-     (struct_specifier
-      name: (type_identifier) @font-lock-type-face)
-
      (sized_type_specifier) @font-lock-type-face
 
-     (enum_specifier
-      name: (type_identifier) @font-lock-type-face)
-
-     (enumerator
-      name: (identifier) @font-lock-variable-name-face)
-
      (parameter_declaration
       type: (_) @font-lock-type-face
       declarator: (identifier) @font-lock-variable-name-face)
@@ -301,8 +274,7 @@ c-ts-mode--font-lock-settings
      (pointer_declarator
       declarator: (identifier) @font-lock-variable-name-face)
 
-     (pointer_declarator
-      declarator: (field_identifier) @font-lock-variable-name-face))
+     ((type_identifier) @font-lock-type-face))
    :language mode
    :override t
    :feature 'expression
@@ -313,11 +285,7 @@ c-ts-mode--font-lock-settings
       function: (identifier) @font-lock-function-name-face)
 
      (field_expression
-      field: (field_identifier) @font-lock-variable-name-face)
-
-     (field_expression
-      argument: (identifier) @font-lock-variable-name-face
-      field: (field_identifier) @font-lock-variable-name-face)
+      argument: (identifier) @font-lock-variable-name-face)
 
      (pointer_expression
       argument: (identifier) @font-lock-variable-name-face))
@@ -330,7 +298,26 @@ c-ts-mode--font-lock-settings
    :language mode
    :override t
    :feature 'error
-   '((ERROR) @font-lock-warning-face)))
+   '((ERROR) @font-lock-warning-face)
+   :feature 'escape-sequence
+   :language mode
+   :override t
+   '((escape_sequence) @font-lock-escape-face)
+   :language mode
+   :override t
+   :feature 'property
+   '((field_identifier) @font-lock-property-face
+     (enumerator
+      name: (identifier) @font-lock-property-face))
+   :language mode
+   :override t
+   :feature 'bracket
+   '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
+   :language mode
+   :override t
+   :feature 'delimiter
+   '((["," ":" ";"]) @font-lock-delimiter-face)
+   ))
 
 (defun c-ts-mode--imenu-1 (node)
   "Helper for `c-ts-mode--imenu'.
@@ -422,9 +409,10 @@ c-ts-mode--base-mode
   (setq-local which-func-functions nil)
 
   (setq-local treesit-font-lock-feature-list
-              '((comment preprocessor operator constant string literal keyword)
-                (type definition expression statement)
-                (error))))
+              '(( comment preprocessor operator constant string literal keyword)
+                ( type definition expression statement property bracket
+                  delimiter escape-sequence)
+                ( error))))
 
 ;;;###autoload
 (define-derived-mode c-ts-mode c-ts-mode--base-mode "C"
@@ -446,7 +434,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 a5d02d0fcb..88dc31b50e 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__"
@@ -1118,7 +1115,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


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

* bug#59268: [PATCH] Utilize new font-lock faces for C/C++ and Python tree-sitter use
  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
  0 siblings, 1 reply; 10+ messages in thread
From: Randy Taylor @ 2022-11-15  1:26 UTC (permalink / raw)
  Cc: 59268


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

I updated the patch to apply cleanly, since recent changes caused conflicts.

[-- Attachment #1.2: Type: text/html, Size: 170 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: 8040 bytes --]

From d474d7247ec7c51d761ea629ca107464a0fa7a2f 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.  Simplify type matching.
(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 | 72 ++++++++++++++++---------------------
 lisp/progmodes/python.el    | 41 +++++++++++++++++----
 2 files changed, 65 insertions(+), 48 deletions(-)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index bb0db0e1e7..1ee5f45d35 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -231,18 +231,17 @@ c-ts-mode--font-lock-settings
    :language mode
    :override t
    :feature 'operator
-   `([,@c-ts-mode--operators] @font-lock-builtin-face)
+   `([,@c-ts-mode--operators] @font-lock-operator-face)
    :language mode
    :override t
    :feature 'string
    `((string_literal) @font-lock-string-face
      ((string_literal)) @contextual
-     (system_lib_string) @font-lock-string-face
-     (escape_sequence) @font-lock-string-face)
+     (system_lib_string) @font-lock-string-face)
    :language mode
    :override t
    :feature 'literal
-   `((number_literal) @font-lock-constant-face
+   `((number_literal) @font-lock-number-face
      (char_literal) @font-lock-constant-face)
    :language mode
    :override t
@@ -252,30 +251,13 @@ c-ts-mode--font-lock-settings
          '((type_qualifier) @font-lock-type-face
 
            (qualified_identifier
-            scope: (namespace_identifier) @font-lock-type-face)
-
-           (operator_cast) type: (type_identifier) @font-lock-type-face)))
+            scope: (namespace_identifier) @font-lock-type-face))))
    :language mode
    :override t
    :feature 'definition
    `((declaration
       declarator: (identifier) @font-lock-variable-name-face)
 
-     (declaration
-      type: (type_identifier) @font-lock-type-face)
-
-     (field_declaration
-      declarator: (field_identifier) @font-lock-variable-name-face)
-
-     (field_declaration
-      type: (type_identifier) @font-lock-type-face)
-
-     (parameter_declaration
-      type: (type_identifier) @font-lock-type-face)
-
-     (function_definition
-      type: (type_identifier) @font-lock-type-face)
-
      (function_declarator
       declarator: (identifier) @font-lock-function-name-face)
 
@@ -285,17 +267,8 @@ c-ts-mode--font-lock-settings
      (init_declarator
       declarator: (identifier) @font-lock-variable-name-face)
 
-     (struct_specifier
-      name: (type_identifier) @font-lock-type-face)
-
      (sized_type_specifier) @font-lock-type-face
 
-     (enum_specifier
-      name: (type_identifier) @font-lock-type-face)
-
-     (enumerator
-      name: (identifier) @font-lock-variable-name-face)
-
      (parameter_declaration
       type: (_) @font-lock-type-face
       declarator: (identifier) @font-lock-variable-name-face)
@@ -303,8 +276,7 @@ c-ts-mode--font-lock-settings
      (pointer_declarator
       declarator: (identifier) @font-lock-variable-name-face)
 
-     (pointer_declarator
-      declarator: (field_identifier) @font-lock-variable-name-face))
+     ((type_identifier) @font-lock-type-face))
    :language mode
    :override t
    :feature 'expression
@@ -315,11 +287,7 @@ c-ts-mode--font-lock-settings
       function: (identifier) @font-lock-function-name-face)
 
      (field_expression
-      field: (field_identifier) @font-lock-variable-name-face)
-
-     (field_expression
-      argument: (identifier) @font-lock-variable-name-face
-      field: (field_identifier) @font-lock-variable-name-face)
+      argument: (identifier) @font-lock-variable-name-face)
 
      (pointer_expression
       argument: (identifier) @font-lock-variable-name-face))
@@ -332,7 +300,26 @@ c-ts-mode--font-lock-settings
    :language mode
    :override t
    :feature 'error
-   '((ERROR) @font-lock-warning-face)))
+   '((ERROR) @font-lock-warning-face)
+   :feature 'escape-sequence
+   :language mode
+   :override t
+   '((escape_sequence) @font-lock-escape-face)
+   :language mode
+   :override t
+   :feature 'property
+   '((field_identifier) @font-lock-property-face
+     (enumerator
+      name: (identifier) @font-lock-property-face))
+   :language mode
+   :override t
+   :feature 'bracket
+   '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
+   :language mode
+   :override t
+   :feature 'delimiter
+   '((["," ":" ";"]) @font-lock-delimiter-face)
+   ))
 
 (defun c-ts-mode--imenu-1 (node)
   "Helper for `c-ts-mode--imenu'.
@@ -418,8 +405,9 @@ c-ts-mode--base-mode
   (setq-local which-func-functions nil)
 
   (setq-local treesit-font-lock-feature-list
-              '((comment preprocessor operator constant string literal keyword)
-                (type definition expression statement)
+              '(( comment preprocessor operator constant string literal keyword)
+                ( type definition expression statement property bracket
+                  delimiter escape-sequence)
                 ())))
 
 ;;;###autoload
@@ -447,7 +435,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 a5d02d0fcb..88dc31b50e 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__"
@@ -1118,7 +1115,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


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

* bug#59268: [PATCH] Utilize new font-lock faces for C/C++ and Python tree-sitter use
  2022-11-15  1:26 ` Randy Taylor
@ 2022-11-16  2:04   ` Randy Taylor
  2022-11-17  3:26     ` Randy Taylor
  0 siblings, 1 reply; 10+ messages in thread
From: Randy Taylor @ 2022-11-16  2:04 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 59268


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

Updated the patch again to apply cleanly.

Also added Yuan. (Side note: perhaps emacs-devel feature should be renamed to emacs-defun?)

[-- Attachment #1.2: Type: text/html, Size: 410 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: 8056 bytes --]

From afe8c88a1adddac7e080b6bd04c117112a54bb52 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.  Simplify type matching.
(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 | 71 +++++++++++++++----------------------
 lisp/progmodes/python.el    | 41 +++++++++++++++++----
 2 files changed, 64 insertions(+), 48 deletions(-)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 950ef1f65e..dbf37109c4 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -231,18 +231,17 @@ c-ts-mode--font-lock-settings
    :language mode
    :override t
    :feature 'operator
-   `([,@c-ts-mode--operators] @font-lock-builtin-face)
+   `([,@c-ts-mode--operators] @font-lock-operator-face)
    :language mode
    :override t
    :feature 'string
    `((string_literal) @font-lock-string-face
      ((string_literal)) @contextual
-     (system_lib_string) @font-lock-string-face
-     (escape_sequence) @font-lock-string-face)
+     (system_lib_string) @font-lock-string-face)
    :language mode
    :override t
    :feature 'literal
-   `((number_literal) @font-lock-constant-face
+   `((number_literal) @font-lock-number-face
      (char_literal) @font-lock-constant-face)
    :language mode
    :override t
@@ -252,30 +251,13 @@ c-ts-mode--font-lock-settings
          '((type_qualifier) @font-lock-type-face
 
            (qualified_identifier
-            scope: (namespace_identifier) @font-lock-type-face)
-
-           (operator_cast) type: (type_identifier) @font-lock-type-face)))
+            scope: (namespace_identifier) @font-lock-type-face))))
    :language mode
    :override t
    :feature 'definition
    `((declaration
       declarator: (identifier) @font-lock-variable-name-face)
 
-     (declaration
-      type: (type_identifier) @font-lock-type-face)
-
-     (field_declaration
-      declarator: (field_identifier) @font-lock-variable-name-face)
-
-     (field_declaration
-      type: (type_identifier) @font-lock-type-face)
-
-     (parameter_declaration
-      type: (type_identifier) @font-lock-type-face)
-
-     (function_definition
-      type: (type_identifier) @font-lock-type-face)
-
      (function_declarator
       declarator: (identifier) @font-lock-function-name-face)
 
@@ -285,17 +267,8 @@ c-ts-mode--font-lock-settings
      (init_declarator
       declarator: (identifier) @font-lock-variable-name-face)
 
-     (struct_specifier
-      name: (type_identifier) @font-lock-type-face)
-
      (sized_type_specifier) @font-lock-type-face
 
-     (enum_specifier
-      name: (type_identifier) @font-lock-type-face)
-
-     (enumerator
-      name: (identifier) @font-lock-variable-name-face)
-
      (parameter_declaration
       type: (_) @font-lock-type-face
       declarator: (identifier) @font-lock-variable-name-face)
@@ -303,8 +276,7 @@ c-ts-mode--font-lock-settings
      (pointer_declarator
       declarator: (identifier) @font-lock-variable-name-face)
 
-     (pointer_declarator
-      declarator: (field_identifier) @font-lock-variable-name-face))
+     ((type_identifier) @font-lock-type-face))
    :language mode
    :override t
    :feature 'expression
@@ -315,11 +287,7 @@ c-ts-mode--font-lock-settings
       function: (identifier) @font-lock-function-name-face)
 
      (field_expression
-      field: (field_identifier) @font-lock-variable-name-face)
-
-     (field_expression
-      argument: (identifier) @font-lock-variable-name-face
-      field: (field_identifier) @font-lock-variable-name-face)
+      argument: (identifier) @font-lock-variable-name-face)
 
      (pointer_expression
       argument: (identifier) @font-lock-variable-name-face))
@@ -333,6 +301,24 @@ c-ts-mode--font-lock-settings
    :override t
    :feature 'error
    '((ERROR) @font-lock-warning-face)
+   :feature 'escape-sequence
+   :language mode
+   :override t
+   '((escape_sequence) @font-lock-escape-face)
+   :language mode
+   :override t
+   :feature 'property
+   '((field_identifier) @font-lock-property-face
+     (enumerator
+      name: (identifier) @font-lock-property-face))
+   :language mode
+   :override t
+   :feature 'bracket
+   '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
+   :language mode
+   :override t
+   :feature 'delimiter
+   '((["," ":" ";"]) @font-lock-delimiter-face)
    :language mode
    :feature 'emacs-devel
    :override 't
@@ -465,9 +451,10 @@ c-ts-mode--base-mode
   (setq-local which-func-functions nil)
 
   (setq-local treesit-font-lock-feature-list
-              '((comment preprocessor operator constant string literal keyword)
-                (type definition expression statement)
-                (error))))
+              '(( comment preprocessor operator constant string literal keyword)
+                ( type definition expression statement property bracket
+                  delimiter escape-sequence)
+                ( error))))
 
 ;;;###autoload
 (define-derived-mode c-ts-mode c-ts-mode--base-mode "C"
@@ -494,7 +481,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


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

* bug#59268: [PATCH] Utilize new font-lock faces for C/C++ and Python tree-sitter use
  2022-11-16  2:04   ` Randy Taylor
@ 2022-11-17  3:26     ` Randy Taylor
  2022-11-17  3:39       ` Yuan Fu
  0 siblings, 1 reply; 10+ messages in thread
From: Randy Taylor @ 2022-11-17  3:26 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 59268


[-- 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


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

* bug#59268: [PATCH] Utilize new font-lock faces for C/C++ and Python tree-sitter use
  2022-11-17  3:26     ` Randy Taylor
@ 2022-11-17  3:39       ` Yuan Fu
  2022-11-17 13:50         ` Randy Taylor
  0 siblings, 1 reply; 10+ messages in thread
From: Yuan Fu @ 2022-11-17  3:39 UTC (permalink / raw)
  To: Randy Taylor; +Cc: 59268



> On Nov 16, 2022, at 7:26 PM, Randy Taylor <dev@rjt.dev> wrote:
> 
> Updated the patch again to apply cleanly, as there were some more changes to c-ts-mode.el.
> 
> 
> <0001-Utilize-new-font-lock-faces-for-C-C-and-Python-tree-.patch>

Ah, for making you updating the patch for so many times! I just see this report. The only comment I have is that I see you removed the field rule from assignment feature:

-     (assignment_expression
-      left: (field_expression field: (_) @font-lock-property-face))

I envisioned the assignment feature to highlight “the thing being assigned to”, in which case it would highlight the field when it’s in LHS. It’s perfectly fine to have both the field rule and the assignment rule to highlight fields, I think. So if you don’t mind, I’d add it back to assignment group.

Yuan




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

* bug#59268: [PATCH] Utilize new font-lock faces for C/C++ and Python tree-sitter use
  2022-11-17  3:39       ` Yuan Fu
@ 2022-11-17 13:50         ` Randy Taylor
  2022-11-17 18:39           ` Yuan Fu
  0 siblings, 1 reply; 10+ messages in thread
From: Randy Taylor @ 2022-11-17 13:50 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 59268

[-- Attachment #1: Type: text/plain, Size: 1204 bytes --]

On Wednesday, November 16th, 2022 at 22:39, Yuan Fu <casouri@gmail.com> wrote:

> 
> Ah, for making you updating the patch for so many times! I just see this report. The only comment I have is that I see you removed the field rule from assignment feature:
> 

No worries!

>
> - (assignment_expression
> - left: (field_expression field: (_) @font-lock-property-face))
> 
> I envisioned the assignment feature to highlight “the thing being assigned to”, in which case it would highlight the field when it’s in LHS. It’s perfectly fine to have both the field rule and the assignment rule to highlight fields, I think. So if you don’t mind, I’d add it back to assignment group.
> 

I removed it because (field_identifier) @font-lock-property-face (in the property feature) highlights all fields, from what I can tell and have tested.
Can you show me an example where it won't match?

Below, when T is a struct:

  T thing;
  thing.b = thing.b;
  thing.b = 5;

b is highlighted as a field in all cases.

Also, I've attached an updated patch: it seems that the escape-sequence feature needs an override to work (probably because it's inside a string that's highlighted?).

[-- 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: 6956 bytes --]

From bb93e32e7e921becc2b76184acfd3a4a99fde4ff 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 | 46 +++++++++++++++++++++++--------------
 lisp/progmodes/python.el    | 41 ++++++++++++++++++++++++++++-----
 2 files changed, 64 insertions(+), 23 deletions(-)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index b951031d81..8816660f89 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,25 @@ c-ts-mode--font-lock-settings
    :feature 'error
    '((ERROR) @font-lock-warning-face)
 
+   :feature 'escape-sequence
+   :language mode
+   :override t
+   '((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 +482,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 +512,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


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

* bug#59268: [PATCH] Utilize new font-lock faces for C/C++ and Python tree-sitter use
  2022-11-17 13:50         ` Randy Taylor
@ 2022-11-17 18:39           ` Yuan Fu
  2022-11-17 20:02             ` Randy Taylor
  0 siblings, 1 reply; 10+ messages in thread
From: Yuan Fu @ 2022-11-17 18:39 UTC (permalink / raw)
  To: Randy Taylor; +Cc: 59268



> On Nov 17, 2022, at 5:50 AM, Randy Taylor <dev@rjt.dev> wrote:
> 
> On Wednesday, November 16th, 2022 at 22:39, Yuan Fu <casouri@gmail.com> wrote:
> 
>> 
>> Ah, for making you updating the patch for so many times! I just see this report. The only comment I have is that I see you removed the field rule from assignment feature:
>> 
> 
> No worries!
> 
>> 
>> - (assignment_expression
>> - left: (field_expression field: (_) @font-lock-property-face))
>> 
>> I envisioned the assignment feature to highlight “the thing being assigned to”, in which case it would highlight the field when it’s in LHS. It’s perfectly fine to have both the field rule and the assignment rule to highlight fields, I think. So if you don’t mind, I’d add it back to assignment group.
>> 
> 
> I removed it because (field_identifier) @font-lock-property-face (in the property feature) highlights all fields, from what I can tell and have tested.
> Can you show me an example where it won't match?
> 
> Below, when T is a struct:
> 
>  T thing;
>  thing.b = thing.b;
>  thing.b = 5;
> 
> b is highlighted as a field in all cases.

Ah, the purpose of that rule is to highlight field names in the LHS of assignments _only_. So if I disable property and enable assignment, I should see normal field names not highlighted, but field names in LHS of assignments highlighted.

> 
> Also, I've attached an updated patch: it seems that the escape-sequence feature needs an override to work (probably because it's inside a string that's highlighted?).<0001-Utilize-new-font-lock-faces-for-C-C-and-Python-tree-.patch>

Thanks. I will add back the assignment field rule and apply, is that ok with you?

Yuan






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

* bug#59268: [PATCH] Utilize new font-lock faces for C/C++ and Python tree-sitter use
  2022-11-17 18:39           ` Yuan Fu
@ 2022-11-17 20:02             ` Randy Taylor
  2022-11-17 20:07               ` Yuan Fu
  0 siblings, 1 reply; 10+ messages in thread
From: Randy Taylor @ 2022-11-17 20:02 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 59268

[-- Attachment #1: Type: text/plain, Size: 783 bytes --]

On Thursday, November 17th, 2022 at 13:39, Yuan Fu <casouri@gmail.com> wrote:

> 
> Ah, the purpose of that rule is to highlight field names in the LHS of assignments only. So if I disable property and enable assignment, I should see normal field names not highlighted, but field names in LHS of assignments highlighted.
> 

I see - you're trying to truly cover everything in assignment on its own.

> > Also, I've attached an updated patch: it seems that the escape-sequence feature needs an override to work (probably because it's inside a string that's highlighted?).<0001-Utilize-new-font-lock-faces-for-C-C-and-Python-tree-.patch>
> 
> 
> Thanks. I will add back the assignment field rule and apply, is that ok with you?
>

Sure! I attached a patch which keeps it.

[-- 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: 6582 bytes --]

From 12964e14ffcbf1f1084d0c2bc2d666ea5fc91a1f 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 | 44 ++++++++++++++++++++++++-------------
 lisp/progmodes/python.el    | 41 +++++++++++++++++++++++++++++-----
 2 files changed, 64 insertions(+), 21 deletions(-)

diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index b951031d81..d1be13573d 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
@@ -298,8 +293,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 +307,25 @@ c-ts-mode--font-lock-settings
    :feature 'error
    '((ERROR) @font-lock-warning-face)
 
+   :feature 'escape-sequence
+   :language mode
+   :override t
+   '((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 +484,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 +514,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


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

* bug#59268: [PATCH] Utilize new font-lock faces for C/C++ and Python tree-sitter use
  2022-11-17 20:02             ` Randy Taylor
@ 2022-11-17 20:07               ` Yuan Fu
  2022-11-17 20:19                 ` Randy Taylor
  0 siblings, 1 reply; 10+ messages in thread
From: Yuan Fu @ 2022-11-17 20:07 UTC (permalink / raw)
  To: Randy Taylor; +Cc: 59268



> On Nov 17, 2022, at 12:02 PM, Randy Taylor <dev@rjt.dev> wrote:
> 
> On Thursday, November 17th, 2022 at 13:39, Yuan Fu <casouri@gmail.com> wrote:
> 
>> 
>> Ah, the purpose of that rule is to highlight field names in the LHS of assignments only. So if I disable property and enable assignment, I should see normal field names not highlighted, but field names in LHS of assignments highlighted.
>> 
> 
> I see - you're trying to truly cover everything in assignment on its own.
> 
>>> Also, I've attached an updated patch: it seems that the escape-sequence feature needs an override to work (probably because it's inside a string that's highlighted?).<0001-Utilize-new-font-lock-faces-for-C-C-and-Python-tree-.patch>
>> 
>> 
>> Thanks. I will add back the assignment field rule and apply, is that ok with you?
>> 
> 
> Sure! I attached a patch which keeps it.<0001-Utilize-new-font-lock-faces-for-C-C-and-Python-tree-.patch>

Thanks, applied :-)

Yuan




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

* bug#59268: [PATCH] Utilize new font-lock faces for C/C++ and Python tree-sitter use
  2022-11-17 20:07               ` Yuan Fu
@ 2022-11-17 20:19                 ` Randy Taylor
  0 siblings, 0 replies; 10+ messages in thread
From: Randy Taylor @ 2022-11-17 20:19 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 59268-done@debbugs.gnu.org

On Thursday, November 17th, 2022 at 15:07, Yuan Fu <casouri@gmail.com> wrote:

> 
> Thanks, applied :-)
> 
> Yuan

Thanks, closing the bug (hopefully).





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

end of thread, other threads:[~2022-11-17 20:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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.