From 93340d508c22e8936b764bb0e67c6c43108cf046 Mon Sep 17 00:00:00 2001 From: Noah Peart 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'. (Bug#70362) (cherry picked from commit 9055dad65d722850eaec049acbce15829638fd61) --- 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 b82bc2364dc..83e15301854 100644 --- a/lisp/progmodes/go-ts-mode.el +++ b/lisp/progmodes/go-ts-mode.el @@ -108,6 +108,11 @@ ">>" "%=" ">>=" "--" "!" "..." "&^" "&^=" "~") "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 @@ -167,6 +172,16 @@ (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 @@ -269,7 +284,7 @@ (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.39.5