;; --- Go configuration file.--- ;; Setup/configure Go specific programs ;; Requires: ;; gocode (for auto-complete; must be in path) (defun go-sanitize-env () "Check that then environment is configured properly for Go" (unless (getenv "GOPATH") (error "GOPATH is not set.")) (unless (getenv "GOROOT") (error "GOROOT is not set."))) (defun my-go-mode-hook () (add-hook 'before-save-hook 'gofmt-before-save) (setq gofmt-command "goimports") (if (not (string-match "go" compile-command)) (set (make-local-variable 'compile-command) "go build -v && go test -v && go vet"))) (require 'package-loader) (use-package go-mode :config (add-hook 'go-mode-hook 'my-go-mode-hook) (add-hook 'go-mode-hook 'flycheck-mode)) (use-package company-go :if (executable-find "gocode") :config (add-hook 'go-mode-hook 'go-sanitize-env) (push 'company-go company-backends)) (provide 'go)