Skip to content

Mirror of the: https://codeberg.org/rch/go-template-mode. Lightweight major mode for Go text/template files with fast, regex-based highlighting.

License

Notifications You must be signed in to change notification settings

rchar01/go-template-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-template-mode

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.

Features

  • 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

Requirements

  • Emacs 28.1+

Installation

From MELPA

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)))

Manual

  1. Put go-template-mode.el on your load-path.
  2. Add to your init file:
(require 'go-template-mode)

File associations for .gotmpl, .tpl, and .tmpl are provided by the mode.

With use-package (local checkout)

(use-package go-template-mode
  :load-path "/path/to/repo/"
  :mode ("\\.\\(gotmpl\\|tpl\\|tmpl\\)\\'" . go-template-mode))

Usage

  • Open a .gotmpl, .tpl, or .tmpl file to activate the mode.
  • M-; uses Go template comment delimiters for convenience: {{/* ... */}}

Helm charts and embedded templates

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-mode when the buffer is primarily a Go template.
  • Use go-template-helper-mode when templates are embedded inside another format (YAML, config files, etc.).

Limitations

  • No indentation engine (intentionally)
  • Regex-based highlighting may miss edge cases or produce false positives
  • Comment matching is lexical; nested comments are not supported

License

GPL-3.0-or-later. See COPYING.

About

Mirror of the: https://codeberg.org/rch/go-template-mode. Lightweight major mode for Go text/template files with fast, regex-based highlighting.

Resources

License

Stars

Watchers

Forks

Packages