From cec7c55d56cad41f09225554451765e12b309ffc Mon Sep 17 00:00:00 2001 From: Franck Cuny Date: Mon, 20 Jun 2022 14:07:33 -0700 Subject: fix(prog): use gofmt to format go code When using LSP to format the code, I keep running into weird behavior with eglot. I think it's because the code is being formatted while flymake is running but I need more evidence. --- emacs/custom/my-prog.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'emacs') diff --git a/emacs/custom/my-prog.el b/emacs/custom/my-prog.el index 97eec00..379262f 100644 --- a/emacs/custom/my-prog.el +++ b/emacs/custom/my-prog.el @@ -69,6 +69,10 @@ "Hooks for `go-mode'." (setq tab-width 4) + ;; format the buffer using gofmt, for reasons unclear, doing this + ;; with LSP is not working great. + (add-hook 'before-save-hook 'gofmt-before-save) + (set (make-local-variable 'compile-command) "go build -v && go test -v -cover") (define-key go-mode-map (kbd "C-c C-r") 'compile) @@ -112,9 +116,6 @@ (dolist (hook '(go-mode-hook nix-mode-hook)) (add-hook hook 'eglot-ensure)) -;; rely on eglot to do the formatting for go buffers -(add-hook 'go-mode-hook #'(lambda() (add-hook 'before-save-hook 'eglot-format-buffer nil t))) - (provide 'my-prog) ;;; my-prog.el ends here -- cgit 1.4.1