From acdcf472ee36900559514591343fd4be06fdd26a Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Sun, 26 Jun 2022 14:13:33 -0700 Subject: 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 --- emacs/custom/my-prog.el | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'emacs/custom') 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) -- cgit 1.4.1