]> git.eshelyaron.com Git - emacs.git/commitdiff
Add font-locking for Go built-in functions in go-ts-mode
authorNoah Peart <noah.v.peart@gmail.com>
Sat, 13 Apr 2024 05:38:28 +0000 (22:38 -0700)
committerEshel Yaron <me@eshelyaron.com>
Sat, 20 Apr 2024 11:06:03 +0000 (14:06 +0300)
* lisp/progmodes/go-ts-mode.el (go-ts-mode--font-lock-settings):
Add font-locking for Go built-in functions to 'go-ts-mode'.
(Bug#70362)

(cherry picked from commit 9055dad65d722850eaec049acbce15829638fd61)

lisp/progmodes/go-ts-mode.el

index b82bc2364dc964857caf924ddacfe012997ff0ae..83e15301854db65bf2984e2ccfaf6e1a4a4935d6 100644 (file)
     ">>" "%=" ">>=" "--" "!"  "..."  "&^" "&^=" "~")
   "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
      (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
     (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)))