]> git.vanrenterghem.biz Git - Dotty.git/commitdiff
Use Tempel for templates in Emacs.
authorFrederik Vanrenterghem <frederik@vanrenterghem.biz>
Wed, 9 Apr 2025 14:04:29 +0000 (22:04 +0800)
committerFrederik Vanrenterghem <frederik@vanrenterghem.biz>
Wed, 9 Apr 2025 14:04:29 +0000 (22:04 +0800)
emacs/.emacs.d/init.el

index ee17ca85697495164e490d76796002077c1779c0..7df9f5a0e62123c5f925b92bf5f4c5a77614a896 100644 (file)
@@ -60,6 +60,47 @@ vc-follow-symlinks t
 (use-package ess-view-data
   :ensure t)
 
+;; Configure Tempel
+(use-package tempel
+  :ensure t
+  ;; Require trigger prefix before template name when completing.
+  ;; :custom
+  ;; (tempel-trigger-prefix "<")
+
+  :bind (("M-+" . tempel-complete) ;; Alternative tempel-expand
+         ("M-*" . tempel-insert))
+
+  :init
+
+  ;; Setup completion at point
+  (defun tempel-setup-capf ()
+    ;; Add the Tempel Capf to `completion-at-point-functions'.
+    ;; `tempel-expand' only triggers on exact matches. Alternatively use
+    ;; `tempel-complete' if you want to see all matches, but then you
+    ;; should also configure `tempel-trigger-prefix', such that Tempel
+    ;; does not trigger too often when you don't expect it. NOTE: We add
+    ;; `tempel-expand' *before* the main programming mode Capf, such
+    ;; that it will be tried first.
+    (setq-local completion-at-point-functions
+                (cons #'tempel-expand
+                      completion-at-point-functions)))
+
+  (add-hook 'conf-mode-hook 'tempel-setup-capf)
+  (add-hook 'prog-mode-hook 'tempel-setup-capf)
+  (add-hook 'text-mode-hook 'tempel-setup-capf)
+
+  ;; Optionally make the Tempel templates available to Abbrev,
+  ;; either locally or globally. `expand-abbrev' is bound to C-x '.
+  ;; (add-hook 'prog-mode-hook #'tempel-abbrev-mode)
+  ;; (global-tempel-abbrev-mode)
+)
+
+;; Optional: Add tempel-collection.
+;; The package is young and doesn't have comprehensive coverage.
+(use-package tempel-collection
+  :ensure t
+  :after tempel)
+
 ;; enable autocomplete
 (use-package corfu
   :ensure t