* bug#70362: [PATCH] Add font-locking for Go built-in functions in go-ts-mode
@ 2024-04-13 5:47 Noah Peart
2024-04-13 7:23 ` Eli Zaretskii
2024-04-14 23:32 ` Yuan Fu
0 siblings, 2 replies; 10+ messages in thread
From: Noah Peart @ 2024-04-13 5:47 UTC (permalink / raw)
To: 70362
[-- Attachment #1.1: Type: text/plain, Size: 204 bytes --]
Tags: patch
This patch adds a new `builtin` feature to
`treesit-font-lock-feature-list` in `go-ts-mode` and a corresponding
rule to `go-ts-mode--font-lock-settings` to highlight Go's built-in
functions.
[-- Attachment #1.2: Type: text/html, Size: 245 bytes --]
[-- Attachment #2: 0001-Add-font-locking-for-Go-built-in-functions-in-go-ts-.patch --]
[-- Type: text/x-patch, Size: 2216 bytes --]
From feaf5598a5a63867f7dc5bf8f2c11c047b11483f Mon Sep 17 00:00:00 2001
From: Noah Peart <noah.v.peart@gmail.com>
Date: Fri, 12 Apr 2024 22:38:28 -0700
Subject: [PATCH] Add font-locking for Go built-in functions in go-ts-mode
* lisp/progmodes/go-ts-mode.el (go-ts-mode--font-lock-settings):
Add font-locking for Go built-in functions to go-ts-mode.
---
lisp/progmodes/go-ts-mode.el | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
index cc330688dc3..a1736703b62 100644
--- a/lisp/progmodes/go-ts-mode.el
+++ b/lisp/progmodes/go-ts-mode.el
@@ -108,6 +108,11 @@ go-ts-mode--operators
">>" "%=" ">>=" "--" "!" "..." "&^" "&^=" "~")
"Go operators for tree-sitter font-locking.")
+(defvar go-ts-mode--builtin-functions
+ '("append" "cap" "clear" "close" "complex" "copy" "delete" "imag" "len" "make"
+ "max" "min" "new" "panic" "print" "println" "real" "recover")
+ "Go built-in functions for tree-sitter font-locking.")
+
(defun go-ts-mode--iota-query-supported-p ()
"Return t if the iota query is supported by the tree-sitter-go grammar."
(ignore-errors
@@ -154,6 +159,16 @@ go-ts-mode--font-lock-settings
(var_spec name: (identifier) @font-lock-variable-name-face
("," name: (identifier) @font-lock-variable-name-face)*))
+ :language 'go
+ :feature 'builtin
+ `((call_expression
+ function: ((identifier) @font-lock-builtin-face
+ (:match ,(rx-to-string
+ `(seq bol
+ (or ,@go-ts-mode--builtin-functions)
+ eol))
+ @font-lock-builtin-face))))
+
:language 'go
:feature 'function
'((call_expression
@@ -256,7 +271,7 @@ go-ts-mode
(setq-local treesit-font-lock-feature-list
'(( comment definition)
( keyword string type)
- ( constant escape-sequence label number)
+ ( constant escape-sequence label number builtin)
( bracket delimiter error function operator property variable)))
(treesit-major-mode-setup)))
--
2.34.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* bug#70362: [PATCH] Add font-locking for Go built-in functions in go-ts-mode
2024-04-13 5:47 bug#70362: [PATCH] Add font-locking for Go built-in functions in go-ts-mode Noah Peart
@ 2024-04-13 7:23 ` Eli Zaretskii
2024-04-13 7:40 ` Noah Peart
2024-04-14 23:32 ` Yuan Fu
1 sibling, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2024-04-13 7:23 UTC (permalink / raw)
To: Noah Peart; +Cc: 70362
> From: Noah Peart <noah.v.peart@gmail.com>
> Date: Fri, 12 Apr 2024 22:47:37 -0700
>
> This patch adds a new `builtin` feature to
> `treesit-font-lock-feature-list` in `go-ts-mode` and a corresponding
> rule to `go-ts-mode--font-lock-settings` to highlight Go's built-in functions.
Thanks.
I will ask here as well: at what level of font-lock will this be
fontified? I think it should be fontified only on level 4.
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#70362: [PATCH] Add font-locking for Go built-in functions in go-ts-mode
2024-04-13 7:23 ` Eli Zaretskii
@ 2024-04-13 7:40 ` Noah Peart
2024-04-13 12:16 ` Dmitry Gutov
0 siblings, 1 reply; 10+ messages in thread
From: Noah Peart @ 2024-04-13 7:40 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 70362
[-- Attachment #1: Type: text/plain, Size: 769 bytes --]
I put it at level 3 following the conventions in other treesit modes
I checked: python-ts-mode, ruby-ts-mode, rust-ts-mode all put builtins at
level 3.
But, I haven't done a full census of the ts modes so there might be
variability.
On Sat, Apr 13, 2024 at 12:23 AM Eli Zaretskii <eliz@gnu.org> wrote:
> > From: Noah Peart <noah.v.peart@gmail.com>
> > Date: Fri, 12 Apr 2024 22:47:37 -0700
> >
> > This patch adds a new `builtin` feature to
> > `treesit-font-lock-feature-list` in `go-ts-mode` and a corresponding
> > rule to `go-ts-mode--font-lock-settings` to highlight Go's built-in
> functions.
>
> Thanks.
>
> I will ask here as well: at what level of font-lock will this be
> fontified? I think it should be fontified only on level 4.
>
[-- Attachment #2: Type: text/html, Size: 1165 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#70362: [PATCH] Add font-locking for Go built-in functions in go-ts-mode
2024-04-13 7:40 ` Noah Peart
@ 2024-04-13 12:16 ` Dmitry Gutov
0 siblings, 0 replies; 10+ messages in thread
From: Dmitry Gutov @ 2024-04-13 12:16 UTC (permalink / raw)
To: Noah Peart, Eli Zaretskii; +Cc: 70362
On 13/04/2024 10:40, Noah Peart wrote:
> I put it at level 3 following the conventions in other treesit modes
> I checked: python-ts-mode, ruby-ts-mode, rust-ts-mode all put builtins
> at level 3.
> But, I haven't done a full census of the ts modes so there might be
> variability.
SGTM. If classic major modes highlight a thing (and they do that for
built-ins), we usually put it in the default highlighting for ts modes
as well (meaning level 3 or lower).
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#70362: [PATCH] Add font-locking for Go built-in functions in go-ts-mode
2024-04-13 5:47 bug#70362: [PATCH] Add font-locking for Go built-in functions in go-ts-mode Noah Peart
2024-04-13 7:23 ` Eli Zaretskii
@ 2024-04-14 23:32 ` Yuan Fu
2024-04-16 0:44 ` Randy Taylor
2024-04-18 10:31 ` Eli Zaretskii
1 sibling, 2 replies; 10+ messages in thread
From: Yuan Fu @ 2024-04-14 23:32 UTC (permalink / raw)
To: Dmitry Gutov; +Cc: Noah Peart, Eli Zaretskii, 70362
Dmitry Gutov <dmitry@gutov.dev> writes:
> On 13/04/2024 10:40, Noah Peart wrote:
>> I put it at level 3 following the conventions in other treesit modes
>> I checked: python-ts-mode, ruby-ts-mode, rust-ts-mode all put
>> builtins at level 3.
>> But, I haven't done a full census of the ts modes so there might be
>> variability.
>
> SGTM. If classic major modes highlight a thing (and they do that for
> built-ins), we usually put it in the default highlighting for ts modes
> as well (meaning level 3 or lower).
Right. And the patch looks good to me.
Yuan
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#70362: [PATCH] Add font-locking for Go built-in functions in go-ts-mode
2024-04-14 23:32 ` Yuan Fu
@ 2024-04-16 0:44 ` Randy Taylor
2024-04-18 10:32 ` Eli Zaretskii
2024-04-18 10:31 ` Eli Zaretskii
1 sibling, 1 reply; 10+ messages in thread
From: Randy Taylor @ 2024-04-16 0:44 UTC (permalink / raw)
To: Noah Peart; +Cc: Dmitry Gutov, Yuan Fu, 70362, Eli Zaretskii
On Sunday, April 14th, 2024 at 19:32, Yuan Fu <casouri@gmail.com> wrote:
>
> Dmitry Gutov dmitry@gutov.dev writes:
>
> > On 13/04/2024 10:40, Noah Peart wrote:
> >
> > > I put it at level 3 following the conventions in other treesit modes
> > > I checked: python-ts-mode, ruby-ts-mode, rust-ts-mode all put
> > > builtins at level 3.
> > > But, I haven't done a full census of the ts modes so there might be
> > > variability.
> >
> > SGTM. If classic major modes highlight a thing (and they do that for
> > built-ins), we usually put it in the default highlighting for ts modes
> > as well (meaning level 3 or lower).
>
>
> Right. And the patch looks good to me.
>
> Yuan
>
Thanks for working on this Noah, it looks good to me as well.
Perhaps builtin could come before constant in treesit-font-lock-feature-list to keep things alphabetical?
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#70362: [PATCH] Add font-locking for Go built-in functions in go-ts-mode
2024-04-16 0:44 ` Randy Taylor
@ 2024-04-18 10:32 ` Eli Zaretskii
2024-04-18 13:44 ` Randy Taylor
0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2024-04-18 10:32 UTC (permalink / raw)
To: Randy Taylor; +Cc: noah.v.peart, casouri, 70362, dmitry
> Date: Tue, 16 Apr 2024 00:44:16 +0000
> From: Randy Taylor <dev@rjt.dev>
> Cc: Yuan Fu <casouri@gmail.com>, Dmitry Gutov <dmitry@gutov.dev>, Eli Zaretskii <eliz@gnu.org>, 70362@debbugs.gnu.org
>
> Thanks for working on this Noah, it looks good to me as well.
>
> Perhaps builtin could come before constant in treesit-font-lock-feature-list to keep things alphabetical?
I've rearranged them, thanks for noticing this.
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#70362: [PATCH] Add font-locking for Go built-in functions in go-ts-mode
2024-04-18 10:32 ` Eli Zaretskii
@ 2024-04-18 13:44 ` Randy Taylor
2024-04-18 14:15 ` Eli Zaretskii
0 siblings, 1 reply; 10+ messages in thread
From: Randy Taylor @ 2024-04-18 13:44 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: noah.v.peart, casouri, 70362, dmitry
[-- Attachment #1: Type: text/plain, Size: 690 bytes --]
On Thursday, April 18th, 2024 at 06:32, Eli Zaretskii <eliz@gnu.org> wrote:
>
> > Date: Tue, 16 Apr 2024 00:44:16 +0000
>
> > From: Randy Taylor dev@rjt.dev
> > Cc: Yuan Fu casouri@gmail.com, Dmitry Gutov dmitry@gutov.dev, Eli Zaretskii eliz@gnu.org, 70362@debbugs.gnu.org
> >
> > Thanks for working on this Noah, it looks good to me as well.
> >
> > Perhaps builtin could come before constant in treesit-font-lock-feature-list to keep things alphabetical?
>
>
> I've rearranged them, thanks for noticing this.
Thanks, but I was referring to the treesit-font-lock-feature-list variable (see attached patch), not go-ts-mode--font-lock-settings which is not alphabetized.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Alphabetize-go-ts-mode-s-treesit-font-lock-feature-l.patch --]
[-- Type: text/x-patch; name=0001-Alphabetize-go-ts-mode-s-treesit-font-lock-feature-l.patch, Size: 1023 bytes --]
From e77c132d934ad61117d55a5562c9cf0dc1fae47c Mon Sep 17 00:00:00 2001
From: Randy Taylor <dev@rjt.dev>
Date: Thu, 18 Apr 2024 09:38:28 -0400
Subject: [PATCH] ; Alphabetize go-ts-mode's treesit-font-lock-feature-list
* lisp/progmodes/go-ts-mode.el (go-ts-mode):
Rearrange features to keep alphabetical order. (Bug#70362)
---
lisp/progmodes/go-ts-mode.el | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
index f2b586dfb43..aef224ab3fa 100644
--- a/lisp/progmodes/go-ts-mode.el
+++ b/lisp/progmodes/go-ts-mode.el
@@ -284,7 +284,7 @@ go-ts-mode
(setq-local treesit-font-lock-feature-list
'(( comment definition)
( keyword string type)
- ( constant escape-sequence label number builtin)
+ ( builtin constant escape-sequence label number)
( bracket delimiter error function operator property variable)))
(treesit-major-mode-setup)))
--
2.44.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* bug#70362: [PATCH] Add font-locking for Go built-in functions in go-ts-mode
2024-04-18 13:44 ` Randy Taylor
@ 2024-04-18 14:15 ` Eli Zaretskii
0 siblings, 0 replies; 10+ messages in thread
From: Eli Zaretskii @ 2024-04-18 14:15 UTC (permalink / raw)
To: Randy Taylor; +Cc: noah.v.peart, casouri, 70362, dmitry
> Date: Thu, 18 Apr 2024 13:44:56 +0000
> From: Randy Taylor <dev@rjt.dev>
> Cc: noah.v.peart@gmail.com, casouri@gmail.com, dmitry@gutov.dev, 70362@debbugs.gnu.org
>
> On Thursday, April 18th, 2024 at 06:32, Eli Zaretskii <eliz@gnu.org> wrote:
> >
> > > Date: Tue, 16 Apr 2024 00:44:16 +0000
> >
> > > From: Randy Taylor dev@rjt.dev
> > > Cc: Yuan Fu casouri@gmail.com, Dmitry Gutov dmitry@gutov.dev, Eli Zaretskii eliz@gnu.org, 70362@debbugs.gnu.org
> > >
> > > Thanks for working on this Noah, it looks good to me as well.
> > >
> > > Perhaps builtin could come before constant in treesit-font-lock-feature-list to keep things alphabetical?
> >
> >
> > I've rearranged them, thanks for noticing this.
>
> Thanks, but I was referring to the treesit-font-lock-feature-list variable (see attached patch), not go-ts-mode--font-lock-settings which is not alphabetized.
Thanks, installed.
^ permalink raw reply [flat|nested] 10+ messages in thread
* bug#70362: [PATCH] Add font-locking for Go built-in functions in go-ts-mode
2024-04-14 23:32 ` Yuan Fu
2024-04-16 0:44 ` Randy Taylor
@ 2024-04-18 10:31 ` Eli Zaretskii
1 sibling, 0 replies; 10+ messages in thread
From: Eli Zaretskii @ 2024-04-18 10:31 UTC (permalink / raw)
To: Yuan Fu; +Cc: dmitry, 70362-done, noah.v.peart
> From: Yuan Fu <casouri@gmail.com>
> Date: Sun, 14 Apr 2024 16:32:43 -0700
> Cc: Noah Peart <noah.v.peart@gmail.com>,
> Eli Zaretskii <eliz@gnu.org>,
> 70362@debbugs.gnu.org
>
>
> Dmitry Gutov <dmitry@gutov.dev> writes:
>
> > On 13/04/2024 10:40, Noah Peart wrote:
> >> I put it at level 3 following the conventions in other treesit modes
> >> I checked: python-ts-mode, ruby-ts-mode, rust-ts-mode all put
> >> builtins at level 3.
> >> But, I haven't done a full census of the ts modes so there might be
> >> variability.
> >
> > SGTM. If classic major modes highlight a thing (and they do that for
> > built-ins), we usually put it in the default highlighting for ts modes
> > as well (meaning level 3 or lower).
>
> Right. And the patch looks good to me.
Thanks, installed on master, and closing the bug.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-04-18 14:15 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-13 5:47 bug#70362: [PATCH] Add font-locking for Go built-in functions in go-ts-mode Noah Peart
2024-04-13 7:23 ` Eli Zaretskii
2024-04-13 7:40 ` Noah Peart
2024-04-13 12:16 ` Dmitry Gutov
2024-04-14 23:32 ` Yuan Fu
2024-04-16 0:44 ` Randy Taylor
2024-04-18 10:32 ` Eli Zaretskii
2024-04-18 13:44 ` Randy Taylor
2024-04-18 14:15 ` Eli Zaretskii
2024-04-18 10:31 ` Eli Zaretskii
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.