2015-04-19 03:40:24 +00:00
|
|
|
(setq go-packages
|
2015-10-26 13:57:33 +00:00
|
|
|
'(
|
|
|
|
company
|
|
|
|
company-go
|
|
|
|
flycheck
|
|
|
|
go-mode
|
|
|
|
go-eldoc
|
|
|
|
))
|
2015-01-09 06:08:07 +00:00
|
|
|
|
2015-04-11 02:23:16 +00:00
|
|
|
(defun go/post-init-flycheck ()
|
2015-08-28 11:02:20 +00:00
|
|
|
(spacemacs/add-flycheck-hook 'go-mode))
|
2015-01-10 04:09:16 +00:00
|
|
|
|
2015-01-09 06:08:07 +00:00
|
|
|
(defun go/init-go-mode()
|
2015-06-06 17:28:54 +00:00
|
|
|
(when (memq window-system '(mac ns x))
|
2015-10-22 22:15:46 +00:00
|
|
|
(exec-path-from-shell-copy-env "GOPATH")
|
|
|
|
(exec-path-from-shell-copy-env "GO15VENDOREXPERIMENT"))
|
2015-06-06 17:28:54 +00:00
|
|
|
|
2015-01-09 06:08:07 +00:00
|
|
|
(use-package go-mode
|
|
|
|
:defer t
|
2015-01-19 08:01:00 +00:00
|
|
|
:config
|
2015-04-04 04:34:03 +00:00
|
|
|
(progn
|
2015-01-19 08:01:00 +00:00
|
|
|
(add-hook 'before-save-hook 'gofmt-before-save)
|
2015-04-04 04:34:03 +00:00
|
|
|
|
2015-10-26 13:57:33 +00:00
|
|
|
(defun spacemacs/go-run-tests (args)
|
|
|
|
(interactive)
|
|
|
|
(save-selected-window
|
|
|
|
(async-shell-command (concat "go test " args))))
|
|
|
|
|
2015-04-04 04:34:03 +00:00
|
|
|
(defun spacemacs/go-run-package-tests ()
|
|
|
|
(interactive)
|
2015-10-26 13:57:33 +00:00
|
|
|
(spacemacs/go-run-tests ""))
|
|
|
|
|
|
|
|
(defun spacemacs/go-run-package-tests-nested ()
|
|
|
|
(interactive)
|
|
|
|
(spacemacs/go-run-tests "./..."))
|
|
|
|
|
|
|
|
(defun spacemacs/go-run-test-current-function ()
|
|
|
|
(interactive)
|
|
|
|
(if (string-match "_test\\.go" buffer-file-name)
|
|
|
|
(let ((test-method (if go-use-gocheck-for-testing
|
|
|
|
"-check.f"
|
|
|
|
"-run")))
|
|
|
|
(save-excursion
|
|
|
|
(re-search-backward "^func[ ]+([[:alnum:]]*?[ ]?[*]?\\([[:alnum:]]+\\))[ ]+\\(Test[[:alnum:]]+\\)(.*)")
|
|
|
|
(spacemacs/go-run-tests (concat test-method "='" (match-string-no-properties 2) "'"))))
|
|
|
|
(message "Must be in a _test.go file to run go-run-test-current-function")))
|
|
|
|
|
|
|
|
(defun spacemacs/go-run-test-current-suite ()
|
|
|
|
(interactive)
|
|
|
|
(if (string-match "_test\.go" buffer-file-name)
|
|
|
|
(if go-use-gocheck-for-testing
|
|
|
|
(save-excursion
|
|
|
|
(re-search-backward "^func[ ]+([[:alnum:]]*?[ ]?[*]?\\([[:alnum:]]+\\))[ ]+\\(Test[[:alnum:]]+\\)(.*)")
|
|
|
|
(spacemacs/go-run-tests (concat "-check.f='" (match-string-no-properties 1) "'")))
|
|
|
|
(message "Gocheck is needed to test the current suite"))
|
|
|
|
(message "Must be in a _test.go file to run go-test-current-suite")))
|
2015-04-04 04:34:03 +00:00
|
|
|
|
2015-10-22 19:22:26 +00:00
|
|
|
(defun spacemacs/go-run-main ()
|
|
|
|
(interactive)
|
|
|
|
(shell-command
|
|
|
|
(format "go run %s"
|
|
|
|
(shell-quote-argument (buffer-file-name)))))
|
|
|
|
|
2015-01-19 08:01:00 +00:00
|
|
|
(evil-leader/set-key-for-mode 'go-mode
|
2015-09-17 17:44:59 +00:00
|
|
|
"mhh" 'godoc-at-point
|
2015-04-01 19:39:01 +00:00
|
|
|
"mig" 'go-goto-imports
|
|
|
|
"mia" 'go-import-add
|
|
|
|
"mir" 'go-remove-unused-imports
|
2015-09-15 21:41:13 +00:00
|
|
|
"meb" 'go-play-buffer
|
|
|
|
"mer" 'go-play-region
|
|
|
|
"med" 'go-download-play
|
2015-10-22 19:22:26 +00:00
|
|
|
"mxx" 'spacemacs/go-run-main
|
2015-06-06 17:33:41 +00:00
|
|
|
"mga" 'ff-find-other-file
|
2015-04-01 19:39:01 +00:00
|
|
|
"mgg" 'godef-jump
|
2015-10-26 13:57:33 +00:00
|
|
|
"mtt" 'spacemacs/go-run-test-current-function
|
|
|
|
"mts" 'spacemacs/go-run-test-current-suite
|
|
|
|
"mtp" 'spacemacs/go-run-package-tests
|
|
|
|
"mtP" 'spacemacs/go-run-package-tests-nested))))
|
2015-01-12 04:22:23 +00:00
|
|
|
|
|
|
|
(defun go/init-go-eldoc()
|
2015-10-26 13:57:33 +00:00
|
|
|
(add-hook 'go-mode-hook 'go-eldoc-setup))
|
2015-01-19 08:01:00 +00:00
|
|
|
|
2015-04-03 23:13:52 +00:00
|
|
|
(when (configuration-layer/layer-usedp 'auto-completion)
|
2015-04-09 03:57:22 +00:00
|
|
|
(defun go/post-init-company ()
|
|
|
|
(spacemacs|add-company-hook go-mode))
|
|
|
|
|
2015-04-03 21:12:56 +00:00
|
|
|
(defun go/init-company-go ()
|
|
|
|
(use-package company-go
|
2015-04-09 03:57:22 +00:00
|
|
|
:if (configuration-layer/package-usedp 'company)
|
2015-04-03 21:12:56 +00:00
|
|
|
:defer t
|
2015-04-09 03:57:22 +00:00
|
|
|
:init
|
2015-04-30 03:54:30 +00:00
|
|
|
(push 'company-go company-backends-go-mode))))
|