From: Dmitry Gutov <dgutov@yandex.ru>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 61205@debbugs.gnu.org, casouri@gmail.com, theo@thornhill.no, dev@rjt.dev
Subject: bug#61205: 'function' in 3rd element of treesit-font-lock-feature-list
Date: Sun, 5 Feb 2023 01:44:40 +0200 [thread overview]
Message-ID: <a8272b2a-7d35-c338-e6eb-5f5e42cdb36b@yandex.ru> (raw)
In-Reply-To: <838rhdvs3c.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1429 bytes --]
On 04/02/2023 08:53, Eli Zaretskii wrote:
>> Date: Sat, 4 Feb 2023 05:36:15 +0200
>> From: Dmitry Gutov<dgutov@yandex.ru>
>> Cc:61205@debbugs.gnu.org,casouri@gmail.com,theo@thornhill.no,dev@rjt.dev
>>
>> Here's the updated patch in the meantime.
> Thanks, but please also update the doc string of
> treesit-font-lock-level.
Done.
>> Not sure what to do with 'type' highlighting in rust-ts-mode yet.
> What is the problem with that?
The nodes structure of a 'use' instruction has a lot of nesting, and at
least a couple of variations, which would lead to a combinatoric
increase in the number of queries.
Taking another look at the declarations, though, I wasn't sure I could
understand the specific logic for choosing between font-lock-type-face
and font-lock-constant-face.
It seemed heavily inspired by
https://github.com/tree-sitter/tree-sitter-rust/blob/master/queries/highlights.scm,
though. So what I did is reverted to those rules (in that area): the
path segments that start with an uppercase char get highlighted with
font-lock-type-face. The rest don't get highlighted at all. That's how
Rust code looks at Github, so a fair number of developers must be okay
with it.
(Github also highlights function calls, though.)
I'm also adding function parameter highlighting to rust and go modes.
See the attached patch. I suggest we install it in emacs-29, but then
people are free to tweak the rules further.
[-- Attachment #2: ts-modes-refine-features.diff --]
[-- Type: text/x-patch, Size: 7959 bytes --]
diff --git a/doc/emacs/display.texi b/doc/emacs/display.texi
index 97732b65e32..a86c12a0db7 100644
--- a/doc/emacs/display.texi
+++ b/doc/emacs/display.texi
@@ -1159,11 +1159,11 @@ Parser-based Font Lock
This level adds fontification of keywords, strings, and data types.
@item Level 3
This is the default level; it adds fontification of assignments,
-numbers, properties, etc.
+numbers, etc.
@item Level 4
This level adds everything else that can be fontified: operators,
delimiters, brackets, other punctuation, function names in function
-calls, variables, etc.
+calls, property look ups, variables, etc.
@end table
@vindex treesit-font-lock-feature-list
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 2a164af26ea..7300074e5c6 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -774,8 +774,8 @@ c-ts-base-mode
(setq-local treesit-font-lock-feature-list
'(( comment definition)
( keyword preprocessor string type)
- ( assignment constant escape-sequence label literal property )
- ( bracket delimiter error function operator variable))))
+ ( assignment constant escape-sequence label literal)
+ ( bracket delimiter error function operator property variable))))
;;;###autoload
(define-derived-mode c-ts-mode c-ts-base-mode "C"
diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
index 95dcf653fc6..4b14e55281e 100644
--- a/lisp/progmodes/go-ts-mode.el
+++ b/lisp/progmodes/go-ts-mode.el
@@ -123,17 +123,26 @@ go-ts-mode--font-lock-settings
:feature 'delimiter
'((["," "." ";" ":"]) @font-lock-delimiter-face)
+ :language 'go
+ :feature 'definition
+ '((function_declaration
+ name: (identifier) @font-lock-function-name-face)
+ (method_declaration
+ name: (field_identifier) @font-lock-function-name-face)
+ (method_spec
+ name: (field_identifier) @font-lock-function-name-face)
+ (field_declaration
+ name: (field_identifier) @font-lock-property-face)
+ (parameter_declaration
+ name: (identifier) @font-lock-variable-name-face))
+
:language 'go
:feature 'function
'((call_expression
function: (identifier) @font-lock-function-name-face)
(call_expression
function: (selector_expression
- field: (field_identifier) @font-lock-function-name-face))
- (function_declaration
- name: (identifier) @font-lock-function-name-face)
- (method_declaration
- name: (field_identifier) @font-lock-function-name-face))
+ field: (field_identifier) @font-lock-function-name-face)))
:language 'go
:feature 'keyword
@@ -221,11 +230,10 @@ go-ts-mode
;; Font-lock.
(setq-local treesit-font-lock-settings go-ts-mode--font-lock-settings)
(setq-local treesit-font-lock-feature-list
- '(( comment)
+ '(( comment definition)
( keyword string type)
- ( constant escape-sequence function label number
- property variable)
- ( bracket delimiter error operator)))
+ ( constant escape-sequence label number)
+ ( bracket delimiter error function operator property variable)))
(treesit-major-mode-setup)))
diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el
index e317793d211..5722d037bba 100644
--- a/lisp/progmodes/rust-ts-mode.el
+++ b/lisp/progmodes/rust-ts-mode.el
@@ -155,6 +155,16 @@ rust-ts-mode--font-lock-settings
:feature 'delimiter
'((["," "." ";" ":" "::"]) @font-lock-delimiter-face)
+ :language 'rust
+ :feature 'definition
+ '((function_item name: (identifier) @font-lock-function-name-face)
+ (macro_definition "macro_rules!" @font-lock-constant-face)
+ (macro_definition (identifier) @font-lock-preprocessor-face)
+ (field_declaration name: (field_identifier) @font-lock-property-face)
+ (parameter pattern: (identifier) @font-lock-variable-name-face)
+ (parameter
+ pattern: (reference_pattern (identifier) @font-lock-variable-name-face)))
+
:language 'rust
:feature 'function
'((call_expression
@@ -164,15 +174,12 @@ rust-ts-mode--font-lock-settings
field: (field_identifier) @font-lock-function-name-face)
(scoped_identifier
name: (identifier) @font-lock-function-name-face)])
- (function_item (identifier) @font-lock-function-name-face)
(generic_function
function: [(identifier) @font-lock-function-name-face
(field_expression
field: (field_identifier) @font-lock-function-name-face)
(scoped_identifier
name: (identifier) @font-lock-function-name-face)])
- (macro_definition "macro_rules!" @font-lock-constant-face)
- (macro_definition (identifier) @font-lock-preprocessor-face)
(macro_invocation macro: (identifier) @font-lock-preprocessor-face))
:language 'rust
@@ -208,20 +215,20 @@ rust-ts-mode--font-lock-settings
(mod_item name: (identifier) @font-lock-constant-face)
(primitive_type) @font-lock-type-face
(type_identifier) @font-lock-type-face
- (scoped_identifier name: (identifier) @font-lock-type-face)
- (scoped_identifier path: (identifier) @font-lock-constant-face)
- (scoped_identifier
- (scoped_identifier
- path: (identifier) @font-lock-constant-face))
+ ((scoped_identifier name: (identifier) @font-lock-type-face)
+ (:match "^[A-Z]" @font-lock-type-face))
+ ((scoped_identifier path: (identifier) @font-lock-type-face)
+ (:match "^[A-Z]" @font-lock-type-face))
+ ((scoped_identifier
+ (scoped_identifier
+ path: (identifier) @font-lock-type-face))
+ (:match "^[A-Z]" @font-lock-type-face))
((scoped_identifier
path: [(identifier) @font-lock-type-face
(scoped_identifier
name: (identifier) @font-lock-type-face)])
(:match "^[A-Z]" @font-lock-type-face))
(scoped_type_identifier path: (identifier) @font-lock-constant-face)
- (scoped_use_list
- path: [(identifier) @font-lock-constant-face
- (scoped_identifier (identifier) @font-lock-constant-face)])
(type_identifier) @font-lock-type-face
(use_as_clause alias: (identifier) @font-lock-type-face)
(use_list (identifier) @font-lock-type-face))
@@ -317,11 +324,11 @@ rust-ts-mode
;; Font-lock.
(setq-local treesit-font-lock-settings rust-ts-mode--font-lock-settings)
(setq-local treesit-font-lock-feature-list
- '(( comment)
+ '(( comment definition)
( keyword string)
( attribute builtin constant escape-sequence
- function number property type variable)
- ( bracket delimiter error operator)))
+ number type)
+ ( bracket delimiter error function operator property variable)))
;; Imenu.
(setq-local treesit-simple-imenu-settings
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 98f446a1456..2562e1286c7 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -585,9 +585,10 @@ treesit-font-lock-level
Level 1 usually contains only comments and definitions.
Level 2 usually adds keywords, strings, data types, etc.
Level 3 usually represents full-blown fontifications, including
-assignments, constants, numbers and literals, properties, etc.
+assignments, constants, numbers and literals, etc.
Level 4 adds everything else that can be fontified: delimiters,
-operators, brackets, punctuation, all functions and variables, etc.
+operators, brackets, punctuation, all functions, properties,
+variables, etc.
In addition to the decoration level, individual features can be
turned on/off by calling `treesit-font-lock-recompute-features'.
next prev parent reply other threads:[~2023-02-04 23:44 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-01 2:08 bug#61205: 'function' in 3rd element of treesit-font-lock-feature-list Dmitry Gutov
2023-02-01 5:18 ` Yuan Fu
2023-02-02 2:34 ` Dmitry Gutov
2023-02-02 3:18 ` Randy Taylor
2023-02-02 11:03 ` Dmitry Gutov
2023-02-02 20:25 ` Dmitry Gutov
2023-02-03 2:38 ` Yuan Fu
2023-02-03 2:51 ` Dmitry Gutov
2023-02-03 6:45 ` Eli Zaretskii
2023-02-03 6:46 ` Eli Zaretskii
2023-02-03 11:42 ` Dmitry Gutov
2023-02-03 12:19 ` Eli Zaretskii
2023-02-03 15:15 ` Dmitry Gutov
2023-02-03 15:54 ` Eli Zaretskii
2023-02-03 17:10 ` Dmitry Gutov
2023-02-04 3:36 ` Dmitry Gutov
2023-02-04 6:53 ` Eli Zaretskii
2023-02-04 23:44 ` Dmitry Gutov [this message]
2023-02-05 6:05 ` Eli Zaretskii
2023-02-05 13:52 ` Dmitry Gutov
2023-02-02 2:34 ` Randy Taylor
2023-02-02 2:44 ` Dmitry Gutov
2023-02-02 3:29 ` Randy Taylor
2023-02-02 11:11 ` Dmitry Gutov
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=a8272b2a-7d35-c338-e6eb-5f5e42cdb36b@yandex.ru \
--to=dgutov@yandex.ru \
--cc=61205@debbugs.gnu.org \
--cc=casouri@gmail.com \
--cc=dev@rjt.dev \
--cc=eliz@gnu.org \
--cc=theo@thornhill.no \
/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).