From 9cbb7d0efd8f64e49a22a06184c758a87f7626d4 Mon Sep 17 00:00:00 2001 From: Marcus Kammer Date: Tue, 19 Apr 2022 22:42:34 +0200 Subject: [PATCH] Build go source on save --- bundle/bundle--package.el | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/bundle/bundle--package.el b/bundle/bundle--package.el index 5dbe50e6..c56c937d 100644 --- a/bundle/bundle--package.el +++ b/bundle/bundle--package.el @@ -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))