all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* 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

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.