From feaf5598a5a63867f7dc5bf8f2c11c047b11483f 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. --- 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