go.el 922 B

12345678910111213141516171819202122232425262728293031323334
  1. ;; --- Go configuration file.---
  2. ;; Setup/configure Go specific programs
  3. ;; Requires:
  4. ;; gocode (for auto-complete; must be in path)
  5. (defun go-sanitize-env ()
  6. "Check that then environment is configured properly for Go"
  7. (unless (getenv "GOPATH")
  8. (error "GOPATH is not set."))
  9. (unless (getenv "GOROOT")
  10. (error "GOROOT is not set.")))
  11. (defun my-go-mode-hook ()
  12. (add-hook 'before-save-hook 'gofmt-before-save)
  13. (setq gofmt-command "goimports")
  14. (if (not (string-match "go" compile-command))
  15. (set (make-local-variable 'compile-command)
  16. "go build -v && go test -v && go vet")))
  17. (require 'package-loader)
  18. (use-package go-mode
  19. :config
  20. (add-hook 'go-mode-hook 'my-go-mode-hook)
  21. (add-hook 'go-mode-hook 'flycheck-mode))
  22. (use-package company-go
  23. :if (executable-find "gocode")
  24. :config
  25. (add-hook 'go-mode-hook 'go-sanitize-env)
  26. (push 'company-go company-backends))
  27. (provide 'go)