all repos — nixfiles @ 116b5525d76168073e657cf3fcf9ec3885dde229

System and user configuration, managed by nix and home-manager

emacs: start eglot in templ files
Alan Pearce alan@alanpearce.eu
Tue, 18 Jun 2024 20:29:16 +0200
commit

116b5525d76168073e657cf3fcf9ec3885dde229

parent

e9d62e56f73a1ecc772073ab3ce2705abf153028

1 files changed, 9 insertions(+), 0 deletions(-)

jump to
M user/emacs/init.eluser/emacs/init.el
@@ -791,6 +791,7 @@ (add-to-list 'project-vc-extra-root-markers "go.mod")) 
 (setq-default go-ts-mode-indent-offset 2)
 (use-package templ-ts-mode
+  :gfhook #'eglot-format-before-save-mode
   :defer t
   :config (progn
             (setq-default go-ts-mode-indent-offset 2)))
@@ -1093,6 +1094,13 @@ (use-package consult-lsp   :commands (consult-lsp-symbols
              consult-lsp-diagnostics))
 
+(define-minor-mode eglot-format-before-save-mode
+  "Whether to ask the LSP to format the buffer before saving"
+  :init-val nil
+  (if eglot-format-before-save-mode
+      (add-hook 'before-save-hook #'eglot-format-buffer nil 'local)
+    (remove-hook 'before-save-hook #'eglot-format-buffer 'local)))
+
 (use-package eglot
   :defer 3
   :general (:states 'normal :keymaps 'eglot-mode-map
@@ -1107,6 +1115,7 @@ lua-mode-hook             nim-mode-hook
             html-mode-hook
             nix-mode-hook
+            templ-ts-mode-hook
             toml-ts-mode-hook
             haskell-mode-hook)
           #'eglot-ensure)