A lightweight Emacs major mode for editing Go text/template (Go templates).
It focuses on fast, incremental font-lock (regex-based) and avoids parsers, caches, or heavy hooks.
- Highlights template delimiters: {{ and }}
- Highlights $variables
- Highlights control keywords (if, range, with, …)
- Highlights common builtins (printf, len, …)
- Highlights multiline template comments: {{* … *}}
- Optional cheap highlighting of simple HTML tag names
- Emacs 28.1+
After installing from MELPA, enable it in your init:
(use-package go-template-mode
:ensure t
:mode (("\\.gotmpl\\'" . go-template-mode)
("\\.tpl\\'" . go-template-mode)
("\\.tmpl\\'" . go-template-mode)))- Put
go-template-mode.elon yourload-path. - Add to your init file:
(require 'go-template-mode)File associations for .gotmpl, .tpl, and .tmpl are provided by the mode.
(use-package go-template-mode
:load-path "/path/to/repo/"
:mode ("\\.\\(gotmpl\\|tpl\\|tmpl\\)\\'" . go-template-mode))- Open a
.gotmpl,.tpl, or.tmplfile to activate the mode. M-;uses Go template comment delimiters for convenience:{{/* ... */}}
Helm chart templates often embed Go templates inside YAML (usually under
a templates/ directory). For templated YAML (host mode yaml-mode),
consider using the companion minor mode:
go-template-helper-mode: overlays Go template highlighting on top of another major mode (commonly YAML).
In short:
- Use
go-template-modewhen the buffer is primarily a Go template. - Use
go-template-helper-modewhen templates are embedded inside another format (YAML, config files, etc.).
- No indentation engine (intentionally)
- Regex-based highlighting may miss edge cases or produce false positives
- Comment matching is lexical; nested comments are not supported
GPL-3.0-or-later. See COPYING.