From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#59445: 29.0.50; Tweak tree sitter faces in Java and TypeScript Date: Mon, 21 Nov 2022 13:13:25 +0100 Message-ID: <87a64k8pzu.fsf@thornhill.no> Reply-To: Theodor Thornhill Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1647"; mail-complaints-to="usenet@ciao.gmane.io" To: 59445@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 21 13:14:17 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ox5gn-0000DS-0y for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 21 Nov 2022 13:14:17 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ox5ga-00033X-TD; Mon, 21 Nov 2022 07:14:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox5gY-00033F-P1 for bug-gnu-emacs@gnu.org; Mon, 21 Nov 2022 07:14:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ox5gY-0005X6-GM for bug-gnu-emacs@gnu.org; Mon, 21 Nov 2022 07:14:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ox5gY-0002e0-Bi for bug-gnu-emacs@gnu.org; Mon, 21 Nov 2022 07:14:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 21 Nov 2022 12:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 59445 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.166903282110126 (code B ref -1); Mon, 21 Nov 2022 12:14:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 21 Nov 2022 12:13:41 +0000 Original-Received: from localhost ([127.0.0.1]:45638 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ox5gD-0002dF-3O for submit@debbugs.gnu.org; Mon, 21 Nov 2022 07:13:41 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:37060) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ox5gA-0002d7-HM for submit@debbugs.gnu.org; Mon, 21 Nov 2022 07:13:39 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox5g9-0002yb-QV for bug-gnu-emacs@gnu.org; Mon, 21 Nov 2022 07:13:38 -0500 Original-Received: from out0.migadu.com ([2001:41d0:2:267::]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ox5g7-0005QY-1g for bug-gnu-emacs@gnu.org; Mon, 21 Nov 2022 07:13:37 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1669032812; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=RO08eZv1ZOUF7Zwy1de8ufihBgxo1MF03q6EQ9h0OD0=; b=aevmMsEyqAqi4UFZ1eBLKECtDR5GjNsIprvZx4wHRWywPgM0Q2gysFrItqkjuyB1Phnvih I8ZahVrYyxnYmZwpLCPVjlHTdOrgvwUSHevsnoXYNJIQA8hqNcflTS68bBzIOLnTC07feQ 5qJDKxnjgKkeyB7S3s1NOVl1+7JDidMXbGww70/6+1tZSBl/lj9BQyVKuCPhJqVyyhP9YG vmz8To+lJsw4HTGoRodVMzMUPUEl1XeQjC6XtutAAb5T1fK8aUYk9s9E2ejSTkp4PjECef /5rWM7HIK6u/bTvcWU/w32ihABPSvo7pk6MLZcmiVHzppGdaIpgPr8dIvPWzWg== X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:2:267::; envelope-from=theo@thornhill.no; helo=out0.migadu.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:248518 Archived-At: --=-=-= Content-Type: text/plain Hi Yuan! I tweaked Java and TypeScript a little. Feel free to apply when you have the time :) Theo --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-Tweak-faces-in-Java-and-TypeScript.patch >From 5fa011d763f6c799766361104e5372e10a31b54c Mon Sep 17 00:00:00 2001 From: Theodor Thornhill Date: Mon, 21 Nov 2022 13:12:03 +0100 Subject: [PATCH] Tweak faces in Java and TypeScript * lisp/progmodes/java-ts-mode.el (java-ts-mode--operators): Remove @ as an operator. (java-ts-mode--font-lock-settings): Use constant-face for @ to match rest of the annotation. Add bracket, delimiter and use some of the new faces. (java-ts-mode--imenu): Clean up the implementation a little. (java-ts-mode): Refer to the new features. * lisp/progmodes/ts-mode.el (ts-mode--font-lock-settings, ts-mode): Add in bracket and delimiter'. --- lisp/progmodes/java-ts-mode.el | 85 ++++++++++++++++++---------------- lisp/progmodes/ts-mode.el | 21 ++++++--- 2 files changed, 60 insertions(+), 46 deletions(-) diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el index 62962b7293..d6e8a9d638 100644 --- a/lisp/progmodes/java-ts-mode.el +++ b/lisp/progmodes/java-ts-mode.el @@ -111,18 +111,14 @@ java-ts-mode--keywords "C keywords for tree-sitter font-locking.") (defvar java-ts-mode--operators - '("@" "+" ":" "++" "-" "--" "&" "&&" "|" "||" - "!=" "==" "*" "/" "%" "<" "<=" ">" ">=" "=" - "-=" "+=" "*=" "/=" "%=" "->" "^" "^=" "&=" - "|=" "~" ">>" ">>>" "<<" "::" "?") + '("+" ":" "++" "-" "--" "&" "&&" "|" "||" "=" + "!=" "==" "*" "/" "%" "<" "<=" ">" ">=" + "-=" "+=" "*=" "/=" "%=" "->" "^" "^=" + "|=" "~" ">>" ">>>" "<<" "::" "?" "&=") "C operators for tree-sitter font-locking.") (defvar java-ts-mode--font-lock-settings (treesit-font-lock-rules - :language 'java - :override t - :feature 'basic - '((identifier) @font-lock-variable-name-face) :language 'java :override t :feature 'comment @@ -144,7 +140,8 @@ java-ts-mode--font-lock-settings :language 'java :override t :feature 'operator - `([,@java-ts-mode--operators] @font-lock-builtin-face) + `([,@java-ts-mode--operators] @font-lock-operator-face + "@" @font-lock-constant-face) :language 'java :override t :feature 'annotation @@ -186,6 +183,8 @@ java-ts-mode--font-lock-settings (method_reference (identifier) @font-lock-type-face) + (scoped_identifier (identifier) @font-lock-variable-name-face) + ((scoped_identifier name: (identifier) @font-lock-type-face) (:match "^[A-Z]" @font-lock-type-face)) @@ -201,6 +200,12 @@ java-ts-mode--font-lock-settings `((method_declaration name: (identifier) @font-lock-function-name-face) + (variable_declarator + name: (identifier) @font-lock-variable-name-face) + + (element_value_pair + key: (identifier) @font-lock-property-face) + (formal_parameter name: (identifier) @font-lock-variable-name-face) @@ -215,7 +220,15 @@ java-ts-mode--font-lock-settings (method_invocation name: (identifier) @font-lock-function-name-face) - (argument_list (identifier) @font-lock-variable-name-face))) + (argument_list (identifier) @font-lock-variable-name-face)) + + :language 'java + :feature 'bracket + '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face) + + :language 'java + :feature 'delimiter + '((["," ":" ";"]) @font-lock-delimiter-face)) "Tree-sitter font-lock settings.") (defun java-ts-mode--imenu-1 (node) @@ -243,33 +256,27 @@ java-ts-mode--imenu-1 (defun java-ts-mode--imenu () "Return Imenu alist for the current buffer." (let* ((node (treesit-buffer-root-node)) - (class-tree - `("Class" . ,(java-ts-mode--imenu-1 - (treesit-induce-sparse-tree - node "^class_declaration$" nil 1000)))) - (interface-tree - `("Interface" . ,(java-ts-mode--imenu-1 - (treesit-induce-sparse-tree - node "^interface_declaration$" nil 1000)))) - (enum-tree - `("Enum" . ,(java-ts-mode--imenu-1 - (treesit-induce-sparse-tree - node "^enum_declaration$" nil 1000)))) - (record-tree - `("Record" . ,(java-ts-mode--imenu-1 - (treesit-induce-sparse-tree - node "^record_declaration$" nil 1000)))) - (method-tree - `("Method" . ,(java-ts-mode--imenu-1 - (treesit-induce-sparse-tree - node "^method_declaration$" nil 1000))))) - (cl-remove-if - #'null - `(,(when (cdr class-tree) class-tree) - ,(when (cdr interface-tree) interface-tree) - ,(when (cdr enum-tree) enum-tree) - ,(when (cdr record-tree) record-tree) - ,(when (cdr method-tree) method-tree))))) + (class-tree (treesit-induce-sparse-tree + node "^class_declaration$" nil 1000)) + (interface-tree (treesit-induce-sparse-tree + node "^interface_declaration$" nil 1000)) + (enum-tree (treesit-induce-sparse-tree + node "^enum_declaration$" nil 1000)) + (record-tree (treesit-induce-sparse-tree + node "^record_declaration$" nil 1000)) + (method-tree (treesit-induce-sparse-tree + node "^method_declaration$" nil 1000)) + (class-index (java-ts-mode--imenu-1 class-tree)) + (interface-index (java-ts-mode--imenu-1 interface-tree)) + (enum-index (java-ts-mode--imenu-1 enum-tree)) + (record-index (java-ts-mode--imenu-1 record-tree)) + (method-index (java-ts-mode--imenu-1 method-tree))) + (append + (when class-index `(("Class" . ,class-index))) + (when interface-index `(("Interface" . ,interface-index))) + (when enum-index `(("Enum" . ,enum-index))) + (when record-index `(("Record" . ,record-index))) + (when method-index `(("Method" . ,method-index)))))) ;;;###autoload (define-derived-mode java-ts-mode prog-mode "Java" @@ -302,9 +309,9 @@ java-ts-mode ;; Font-lock. (setq-local treesit-font-lock-settings java-ts-mode--font-lock-settings) (setq-local treesit-font-lock-feature-list - '((basic comment keyword constant string operator) + '((comment keyword constant string) (type definition expression literal annotation) - ())) + (bracket delimiter operator))) ;; Imenu. (setq-local imenu-create-index-function #'java-ts-mode--imenu) diff --git a/lisp/progmodes/ts-mode.el b/lisp/progmodes/ts-mode.el index 01719a89ee..a91eba6501 100644 --- a/lisp/progmodes/ts-mode.el +++ b/lisp/progmodes/ts-mode.el @@ -210,18 +210,18 @@ ts-mode--font-lock-settings :language 'tsx :override t :feature 'property - `((pair key: (property_identifier) @font-lock-variable-name-face) + `((pair key: (property_identifier) @font-lock-property-face) (pair value: (identifier) @font-lock-variable-name-face) (pair - key: (property_identifier) @font-lock-function-name-face + key: (property_identifier) @font-lock-property-face value: [(function) (arrow_function)]) (property_signature - name: (property_identifier) @font-lock-variable-name-face) + name: (property_identifier) @font-lock-property-face) - ((shorthand_property_identifier) @font-lock-variable-name-face) + ((shorthand_property_identifier) @font-lock-property-face) ((shorthand_property_identifier_pattern) @font-lock-variable-name-face)) @@ -230,7 +230,7 @@ ts-mode--font-lock-settings :override t :feature 'pattern `((pair_pattern - key: (property_identifier) @font-lock-variable-name-face) + key: (property_identifier) @font-lock-property-face) (array_pattern (identifier) @font-lock-variable-name-face)) @@ -249,7 +249,14 @@ ts-mode--font-lock-settings [(nested_identifier (identifier)) (identifier)] @font-lock-function-name-face) - (jsx_attribute (property_identifier) @font-lock-constant-face))) + (jsx_attribute (property_identifier) @font-lock-constant-face)) + :language 'tsx + :feature 'bracket + '((["(" ")" "[" "]" "{" "}"]) @font-lock-bracket-face) + + :language 'tsx + :feature 'delimiter + '((["," ":" ";"]) @font-lock-delimiter-face)) "Tree-sitter font-lock settings.") ;;;###autoload @@ -297,7 +304,7 @@ ts-mode (setq-local treesit-font-lock-feature-list '((comment declaration) (string keyword identifier expression constant) - (property pattern jsx))) + (property pattern jsx bracket delimiter))) ;; Imenu. (setq-local imenu-create-index-function #'js--treesit-imenu) -- 2.34.1 --=-=-=--