From: Noah Peart <noah.v.peart@gmail.com>
To: 70362@debbugs.gnu.org
Subject: bug#70362: [PATCH] Add font-locking for Go built-in functions in go-ts-mode
Date: Fri, 12 Apr 2024 22:47:37 -0700 [thread overview]
Message-ID: <CAPVBTSdAEhJoNVzb-Wof++SnwQAhXEFbMc3+D5wD69gKeapjVQ@mail.gmail.com> (raw)
[-- 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
next reply other threads:[~2024-04-13 5:47 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-13 5:47 Noah Peart [this message]
2024-04-13 7:23 ` bug#70362: [PATCH] Add font-locking for Go built-in functions in go-ts-mode 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
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=CAPVBTSdAEhJoNVzb-Wof++SnwQAhXEFbMc3+D5wD69gKeapjVQ@mail.gmail.com \
--to=noah.v.peart@gmail.com \
--cc=70362@debbugs.gnu.org \
/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).