summary refs log tree commit diff
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-06-26 14:13:33 -0700
committerFranck Cuny <franck@fcuny.net>2022-06-26 14:17:42 -0700
commitacdcf472ee36900559514591343fd4be06fdd26a (patch)
tree847f2d2587049e4cc9bd4a4d2afa3f6a376e3c93
parentfeat(prog): require go-mode (diff)
downloademacs.d-acdcf472ee36900559514591343fd4be06fdd26a.tar.gz
fix(prog): configure eglot for buffer formatting
Load eglot when Emacs starts, and delegate buffer formatting for
supported language to LSP.

The LSP for nix is using `nixpkgs-fmt' already, so there's no need to
configure this ourselves.

Change-Id: I6ee4adcc34b30c75031974c10a47fd3f7d240bed
Diffstat (limited to '')
-rw-r--r--emacs/custom/my-prog.el26
1 files changed, 14 insertions, 12 deletions
diff --git a/emacs/custom/my-prog.el b/emacs/custom/my-prog.el
index a198ce2..dad14f2 100644
--- a/emacs/custom/my-prog.el
+++ b/emacs/custom/my-prog.el
@@ -101,23 +101,25 @@
 (dolist (hook '(prog-mode-hook conf-mode-hook))
   (add-hook hook 'turn-on-eldoc-mode))
 
-;; format nix buffers on save
-(customize-set-variable 'nix-nixfmt-bin "nixpkgs-fmt")
-(add-hook 'before-save-hook 'nix-format-before-save)
-
+(require 'eglot)
 ;; List of settings for gopls:
 ;; https://github.com/golang/tools/blob/master/gopls/doc/settings.md
-;; https://github.com/golang/tools/blob/master/gopls/doc/settings.md#experimentalworkspacemodule-bool
-(customize-set-variable 'eglot-workspace-configuration
-                        '((:gopls .
-                                  ((staticcheck                 . t)
-                                   (experimentalWorkspaceModule . t)
-                                   (matcher                     . "CaseSensitive")
-                                   (usePlaceholders             . t)))))
+(setq eglot-workspace-configuration
+      '((:gopls .
+                ((staticcheck                 . t)
+                 (experimentalWorkspaceModule . t)
+                 (matcher                     . "CaseSensitive")
+                 (usePlaceholders             . t)))))
+
+(defun my/eglot-install-save-hook ()
+  "Install the local hooks that are executed before saving a buffer."
+  ;; the last thing we do is to format the buffer
+  (add-hook 'before-save-hook #'eglot-format-buffer 100 t))
 
 ;; ensure we load eglot for some specific modes
 (dolist (hook '(go-mode-hook nix-mode-hook))
-  (add-hook hook 'eglot-ensure))
+  (add-hook hook 'eglot-ensure)
+  (add-hook hook #'my/eglot-install-save-hook))
 
 (provide 'my-prog)