Build go source on save

This commit is contained in:
Marcus Kammer 2022-04-19 22:42:34 +02:00
parent e79ef3428a
commit 9cbb7d0efd
Signed by: marcuskammer
GPG key ID: C374817BE285268F

View file

@ -116,7 +116,23 @@
(use-package go-mode
:config
(add-hook 'before-save-hook #'gofmt-before-save)
(add-hook 'go-mode-hook 'eglot-ensure))
(add-hook 'go-mode-hook 'eglot-ensure)
(defun me/go-mode-compile-command-hook ()
;; if no makefile use go build for compile command
(unless (or (file-exists-p "makefile")
(file-exists-p "Makefile"))
(set (make-local-variable 'compile-command)
(concat "go " "build " buffer-file-name))))
(add-hook 'go-mode-hook 'me/go-mode-compile-command-hook)
(defun me/go-mode-compile-on-save ()
;; compile on save hook
(make-local-variable 'after-save-hook)
(add-hook 'after-save-hook (lambda () (compile compile-command))))
(add-hook 'go-mode-hook 'me/go-mode-compile-on-save))
(use-package rust-mode
:hook (rust . eglot-ensure))