]> git.eshelyaron.com Git - emacs.git/commitdiff
Utilize new font-lock faces for more tree-sitter modes (Bug#59397)
authorRandy Taylor <dev@rjt.dev>
Sun, 20 Nov 2022 03:30:13 +0000 (22:30 -0500)
committerYuan Fu <casouri@gmail.com>
Wed, 23 Nov 2022 03:07:26 +0000 (19:07 -0800)
* lisp/progmodes/java-ts-mode.el (java-ts-mode--font-lock-settings):
Use font-lock-number-face.
(java-ts-mode): Alphabetize features.
* lisp/progmodes/js.el (js--treesit-operators): Define operators.
(js--treesit-font-lock-settings): Use bracket, delimiter,
escape-sequence, property, number, and operator font-lock faces.
(js-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/json-ts-mode.el (json-ts-mode--font-lock-settings):
Use bracket, delimiter, escape-sequence, and number faces.  Remove
unused features.
(json-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/sh-script.el (sh-mode--treesit-settings): Use
bracket, delimiter, number, misc-punctuation, and operator font-lock
faces.
(sh-mode--treesit-operators): Remove ; and ;; from list.
(bash-ts-mode): Add them to the feature list and alphabetize.
* lisp/progmodes/ts-mode.el (ts-mode--operators): Define operators.
(ts-mode--font-lock-settings): Use escape-sequence, number, and
operator font-lock faces.
(ts-mode): Add them to the feature list and alphabetize.

lisp/progmodes/java-ts-mode.el
lisp/progmodes/js.el
lisp/progmodes/json-ts-mode.el
lisp/progmodes/sh-script.el
lisp/progmodes/ts-mode.el

index e78f1b4c6e8db5fc1e3fa6dcc1319dc9b7586b95..ee2934f53c6e98f5b0a816c67dc8edce8c53760d 100644 (file)
    :feature 'constant
    `(((identifier) @font-lock-constant-face
       (:match "^[A-Z_][A-Z_\\d]*$" @font-lock-constant-face))
-     (true) @font-lock-constant-face
-     (false) @font-lock-constant-face)
+     [(true) (false)] @font-lock-constant-face)
    :language 'java
    :override t
    :feature 'keyword
    :override t
    :feature 'literal
    `((null_literal) @font-lock-constant-face
-     (decimal_floating_point_literal)  @font-lock-constant-face
-     (hex_floating_point_literal) @font-lock-constant-face)
+     (binary_integer_literal)  @font-lock-number-face
+     (decimal_integer_literal) @font-lock-number-face
+     (hex_integer_literal) @font-lock-number-face
+     (octal_integer_literal) @font-lock-number-face
+     (decimal_floating_point_literal) @font-lock-number-face
+     (hex_floating_point_literal) @font-lock-number-face)
    :language 'java
    :override t
    :feature 'type
@@ -314,8 +317,8 @@ the subtrees."
   ;; Font-lock.
   (setq-local treesit-font-lock-settings java-ts-mode--font-lock-settings)
   (setq-local treesit-font-lock-feature-list
-              '((comment keyword constant string)
-                (type definition expression literal annotation)
+              '((comment constant keyword string)
+                (annotation definition expression literal type)
                 (bracket delimiter operator)))
 
   ;; Imenu.
index 51d105b9d7d9365cad1d580d99db25c5554bc789..da05b7b364a09fae7a7b7db56506744f2081a772 100644 (file)
@@ -3465,6 +3465,13 @@ This function is intended for use in `after-change-functions'."
     "typeof" "var" "void" "while" "with" "yield")
   "JavaScript keywords for tree-sitter font-locking.")
 
+(defvar js--treesit-operators
+  '("=" "+=" "-=" "*=" "/=" "%=" "**=" "<<=" ">>=" ">>>=" "&=" "^="
+    "|=" "&&=" "||=" "??=" "==" "!=" "===" "!==" ">" ">=" "<" "<=" "+"
+    "-" "*" "/" "%" "++" "--" "**" "&" "|" "^" "~" "<<" ">>" ">>>"
+    "&&" "||" "!")
+  "JavaScript operators for tree-sitter font-locking.")
+
 (defvar js--treesit-font-lock-settings
   (treesit-font-lock-rules
 
@@ -3479,8 +3486,7 @@ This function is intended for use in `after-change-functions'."
    `(((identifier) @font-lock-constant-face
       (:match "^[A-Z_][A-Z_\\d]*$" @font-lock-constant-face))
 
-     [(true) (false) (null)] @font-lock-constant-face
-     (number) @font-lock-constant-face)
+     [(true) (false) (null)] @font-lock-constant-face)
 
    :language 'javascript
    :override t
@@ -3557,21 +3563,6 @@ This function is intended for use in `after-change-functions'."
              (member_expression
               property: (property_identifier) @font-lock-variable-name-face)]))
 
-   :language 'javascript
-   :override t
-   :feature 'property
-   `((pair key: (property_identifier) @font-lock-variable-name-face)
-
-     (pair value: (identifier) @font-lock-variable-name-face)
-
-     (pair
-      key: (property_identifier) @font-lock-function-name-face
-      value: [(function) (arrow_function)])
-
-     ((shorthand_property_identifier) @font-lock-variable-name-face)
-
-     ((shorthand_property_identifier_pattern) @font-lock-variable-name-face))
-
    :language 'javascript
    :override t
    :feature 'pattern
@@ -3596,7 +3587,42 @@ This function is intended for use in `after-change-functions'."
 
      (jsx_attribute
       (property_identifier)
-      @font-lock-constant-face)))
+      @font-lock-constant-face))
+
+   :language 'javascript
+   :feature 'number
+   `((number) @font-lock-number-face
+     ((identifier) @font-lock-number-face
+      (:match "^\\(:?NaN\\|Infinity\\)$" @font-lock-number-face)))
+
+   :language 'javascript
+   :feature 'operator
+   `([,@js--treesit-operators] @font-lock-operator-face
+     (ternary_expression ["?" ":"] @font-lock-operator-face))
+
+   :language 'javascript
+   :feature 'bracket
+   '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
+
+   :language 'javascript
+   :feature 'delimiter
+   '((["," "." ";" ":"]) @font-lock-delimiter-face)
+
+   :language 'javascript
+   :feature 'escape-sequence
+   :override t
+   '((escape_sequence) @font-lock-escape-face)
+
+   :language 'javascript
+   :override t
+   :feature 'property
+   `((property_identifier) @font-lock-property-face
+
+     (pair value: (identifier) @font-lock-variable-name-face)
+
+     ((shorthand_property_identifier) @font-lock-property-face)
+
+     ((shorthand_property_identifier_pattern) @font-lock-property-face)))
   "Tree-sitter font-lock settings.")
 
 (defun js--fontify-template-string (node override start end &rest _)
@@ -3846,9 +3872,10 @@ Currently there are `js-mode' and `js-ts-mode'."
     ;; Fontification.
     (setq-local treesit-font-lock-settings js--treesit-font-lock-settings)
     (setq-local treesit-font-lock-feature-list
-                '((comment declaration)
-                  (string keyword identifier expression constant)
-                  (property pattern jsx )))
+                '(( comment declaration)
+                  ( constant expression identifier keyword number string)
+                  ( bracket delimiter escape-sequence jsx operator
+                    pattern property)))
     ;; Imenu
     (setq-local imenu-create-index-function
                 #'js--treesit-imenu)
index 4ea285bd439ad71c5b80ae3f2adc5df890d63752..101e873cf6ed64216eef64bf8f7603d571199e64 100644 (file)
 (defvar json-ts-mode--font-lock-settings
   (treesit-font-lock-rules
    :language 'json
-   :feature 'comment
-   :override t
-   '((comment) @font-lock-comment-face)
+   :feature 'bracket
+   '((["[" "]" "{" "}"]) @font-lock-bracket-face)
    :language 'json
-   :feature 'string
-   :override t
-   '((escape_sequence) @font-lock-constant-face
-     (string) @font-lock-string-face)
+   :feature 'constant
+   '([(null) (true) (false)] @font-lock-constant-face)
+   :language 'json
+   :feature 'delimiter
+   '((["," ":"]) @font-lock-delimiter-face)
    :language 'json
    :feature 'number
-   :override t
-   '((number) @font-lock-constant-face)
+   '((number) @font-lock-number-face)
    :language 'json
-   :feature 'constant
+   :feature 'string
+   '((string) @font-lock-string-face)
+   :language 'json
+   :feature 'escape-sequence
    :override t
-   '([(null) (true) (false)] @font-lock-constant-face)
+   '((escape_sequence) @font-lock-escape-face)
    :language 'json
-   :feature 'pair
+   :feature 'error
    :override t
-   `((pair key: (_) @font-lock-variable-name-face)))
+   '((ERROR) @font-lock-warning-face))
   "Font-lock settings for JSON.")
 
 (defun json-ts-mode--imenu-1 (node)
@@ -154,7 +156,9 @@ the subtrees."
   ;; Font-lock.
   (setq-local treesit-font-lock-settings json-ts-mode--font-lock-settings)
   (setq-local treesit-font-lock-feature-list
-              '((comment string number) (constant pair) ()))
+              '((constant number string)
+                (escape-sequence)
+                (bracket delimiter error)))
 
   ;; Imenu.
   (setq-local imenu-create-index-function #'json-ts-mode--imenu)
index 7fe31802c4198e2f852c38ecccf9da119980b63d..067aef86692f22ce2eccb51f2d9f564954104019 100644 (file)
@@ -1608,9 +1608,10 @@ with your script for an edit-interpret-debug cycle."
   "Major mode for editing Bash shell scripts."
   (when (treesit-ready-p 'bash)
     (setq-local treesit-font-lock-feature-list
-                '((comment function string heredoc)
-                  (variable keyword command declaration-command)
-                  (constant operator builtin-variable)))
+                '(( comment function heredoc string)
+                  ( command declaration-command keyword number variable)
+                  ( bracket builtin-variable constant delimiter
+                    misc-punctuation operator)))
     (setq-local treesit-font-lock-settings
                 sh-mode--treesit-settings)
     (treesit-major-mode-setup)))
@@ -3216,8 +3217,7 @@ member of `flymake-diagnostic-functions'."
 ;;; Tree-sitter font-lock
 
 (defvar sh-mode--treesit-operators
-  '("|" "|&" "||" "&&" ">" ">>" "<" "<<" "<<-" "<<<" "==" "!=" ";"
-    ";;" ";&" ";;&")
+  '("|" "|&" "||" "&&" ">" ">>" "<" "<<" "<<-" "<<<" "==" "!=" ";&" ";;&")
   "A list of `sh-mode' operators to fontify.")
 
 (defvar sh-mode--treesit-keywords
@@ -3312,7 +3312,7 @@ See `sh-mode--treesit-other-keywords' and
 
    :feature 'operator
    :language 'bash
-   `([ ,@sh-mode--treesit-operators ] @font-lock-builtin-face)
+   `([,@sh-mode--treesit-operators] @font-lock-operator-face)
 
    :feature 'builtin-variable
    :language 'bash
@@ -3322,7 +3322,24 @@ See `sh-mode--treesit-other-keywords' and
                   `(seq bol
                         (or ,@builtin-vars)
                         eol)))
-              @font-lock-builtin-face))))
+              @font-lock-builtin-face)))
+
+   :feature 'number
+   :language 'bash
+   `(((word) @font-lock-number-face
+      (:match "^[0-9]+$" @font-lock-number-face)))
+
+   :feature 'bracket
+   :language 'bash
+   '((["(" ")" "((" "))" "[" "]" "[[" "]]" "{" "}"]) @font-lock-bracket-face)
+
+   :feature 'delimiter
+   :language 'bash
+   '(([";" ";;"]) @font-lock-delimiter-face)
+
+   :feature 'misc-punctuation
+   :language 'bash
+   '((["$"]) @font-lock-misc-punctuation-face))
   "Tree-sitter font-lock settings for `sh-mode'.")
 
 (provide 'sh-script)
index a91eba6501ab268e147f44e9b497f3119e5f2f95..436b198f594bb1efe3108db6cb1ca549e633a0ce 100644 (file)
     "while" "with" "yield")
   "TypeScript keywords for tree-sitter font-locking.")
 
+(defvar ts-mode--operators
+  '("=" "+=" "-=" "*=" "/=" "%=" "**=" "<<=" ">>=" ">>>=" "&=" "^="
+    "|=" "&&=" "||=" "??=" "==" "!=" "===" "!==" ">" ">=" "<" "<=" "+"
+    "-" "*" "/" "%" "++" "--" "**" "&" "|" "^" "~" "<<" ">>" ">>>"
+    "&&" "||" "!" "?.")
+  "TypeScript operators for tree-sitter font-locking.")
+
 (defvar ts-mode--font-lock-settings
   (treesit-font-lock-rules
    :language 'tsx
    `(((identifier) @font-lock-constant-face
       (:match "^[A-Z_][A-Z_\\d]*$" @font-lock-constant-face))
 
-     [(true) (false) (null)] @font-lock-constant-face
-     (number) @font-lock-constant-face)
+     [(true) (false) (null)] @font-lock-constant-face)
 
    :language 'tsx
    :override t
        (member_expression
         property: (property_identifier) @font-lock-function-name-face)]))
 
-   :language 'tsx
-   :override t
-   :feature 'property
-   `((pair key: (property_identifier) @font-lock-property-face)
-
-     (pair value: (identifier) @font-lock-variable-name-face)
-
-     (pair
-      key: (property_identifier) @font-lock-property-face
-      value: [(function) (arrow_function)])
-
-     (property_signature
-      name: (property_identifier) @font-lock-property-face)
-
-     ((shorthand_property_identifier) @font-lock-property-face)
-
-     ((shorthand_property_identifier_pattern)
-      @font-lock-variable-name-face))
-
    :language 'tsx
    :override t
    :feature 'pattern
       @font-lock-function-name-face)
 
      (jsx_attribute (property_identifier) @font-lock-constant-face))
+
+   :language 'tsx
+   :feature 'number
+   `((number) @font-lock-number-face
+     ((identifier) @font-lock-number-face
+      (:match "^\\(:?NaN\\|Infinity\\)$" @font-lock-number-face)))
+
+   :language 'tsx
+   :feature 'operator
+   `([,@ts-mode--operators] @font-lock-operator-face
+     (ternary_expression ["?" ":"] @font-lock-operator-face))
+
    :language 'tsx
    :feature 'bracket
    '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face)
 
    :language 'tsx
    :feature 'delimiter
-   '((["," ":" ";"]) @font-lock-delimiter-face))
+   '((["," "." ";" ":"]) @font-lock-delimiter-face)
+
+   :language 'tsx
+   :feature 'escape-sequence
+   :override t
+   '((escape_sequence) @font-lock-escape-face)
+
+   :language 'tsx
+   :override t
+   :feature 'property
+   `(((property_identifier) @font-lock-property-face)
+
+     (pair value: (identifier) @font-lock-variable-name-face)
+
+     ((shorthand_property_identifier) @font-lock-property-face)
+
+     ((shorthand_property_identifier_pattern)
+      @font-lock-property-face)))
   "Tree-sitter font-lock settings.")
 
 ;;;###autoload
     (setq-local treesit-font-lock-settings ts-mode--font-lock-settings)
     (setq-local treesit-font-lock-feature-list
                 '((comment declaration)
-                  (string keyword identifier expression constant)
-                  (property pattern jsx bracket delimiter)))
+                  (constant expression identifier keyword number string)
+                  (bracket delimiter jsx pattern property)))
     ;; Imenu.
     (setq-local imenu-create-index-function #'js--treesit-imenu)