This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+lang/go/packages.el

164 lines
5.7 KiB
EmacsLisp
Raw Normal View History

2017-02-01 14:06:00 +00:00
;;; packages.el --- Go Layer packages File for Spacemacs
;;
;; Copyright (c) 2012-2017 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(setq go-packages
'(
(company-go :toggle (configuration-layer/package-usedp 'company))
flycheck
(flycheck-gometalinter :toggle (and go-use-gometalinter
(configuration-layer/package-usedp
'flycheck)))
ggtags
helm-gtags
exec-path-from-shell
go-eldoc
go-mode
2016-10-26 07:48:24 +00:00
go-guru
2017-02-01 14:11:52 +00:00
go-rename
popwin
))
2015-01-09 06:08:07 +00:00
(defun go/post-init-popwin ()
(push (cons go-test-buffer-name '(:dedicated t :position bottom :stick t :noselect t :height 0.4))
popwin:special-display-config))
(defun go/init-company-go ()
(use-package company-go
:defer t
:init
Refactor and simplify company backends declaration Enabling a company backend for a specific mode was a tedious tasks with code scattered at different locations, one for local variable definitions, one for company hook function definitions and another where the backends were pushed to the local variables (which was problematic, since we ended up pushing the same backends over and over again with `SPC f e R`, pushes have been replaced by add-to-list calls in the new macro). All these steps are now put together at one place with the new macro spacemacs|add-company-backends, check its docstring for more info on its arguments. This macro also allows to define arbitrary buffer local variables to tune company for specific modes (similar to layer variables via a keyword :variables) The code related to company backends management has been moved to the auto-completion layer in the funcs.el file. A nice side effect of this move is that it enforces correct encapsulation of company backends related code. We can now easily detect if there is some configuration leakage when the auto-completion layer is not used. But we loose macro expansion at file loading time (not sue it is a big concern though). The function spacemacs|enable-auto-complete was never used so it has been deleted which led to the deletion of the now empty file core-auto-completion.el. The example in LAYERS.org regarding auto-completion is now out of date and has been deleted. An example to setup auto-completion is provided in the README.org file of the auto-completion layer.
2017-01-02 05:39:04 +00:00
(spacemacs|add-company-backends
:backends company-go
:modes go-mode
:variables company-go-show-annotation t)))
(defun go/post-init-flycheck ()
(spacemacs/enable-flycheck 'go-mode))
(defun go/pre-init-exec-path-from-shell ()
(spacemacs|use-package-add-hook exec-path-from-shell
:pre-config
(dolist (var '("GOPATH" "GO15VENDOREXPERIMENT") exec-path-from-shell-variables)
(unless (or (member var exec-path-from-shell-variables) (getenv var))
(push var exec-path-from-shell-variables)))))
(defun go/init-go-mode()
2015-01-09 06:08:07 +00:00
(use-package go-mode
:defer t
:init
(progn
(defun spacemacs//go-set-tab-width ()
"Set the tab width."
(setq-local tab-width go-tab-width))
(add-hook 'go-mode-hook 'spacemacs//go-set-tab-width))
:config
(progn
(add-hook 'before-save-hook 'gofmt-before-save)
(defun spacemacs/go-run-tests (args)
(interactive)
(compilation-start (concat "go test " args " " go-use-test-args)
nil (lambda (n) go-test-buffer-name) nil))
(defun spacemacs/go-run-package-tests ()
(interactive)
(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 2) "'")))
(message "Gocheck is needed to test the current suite"))
(message "Must be in a _test.go file to run go-test-current-suite")))
(defun spacemacs/go-run-main ()
(interactive)
(shell-command
(format "go run %s"
(shell-quote-argument (buffer-file-name (buffer-base-buffer))))))
2015-11-27 20:35:24 +00:00
(spacemacs/declare-prefix-for-mode 'go-mode "me" "playground")
(spacemacs/declare-prefix-for-mode 'go-mode "mg" "goto")
(spacemacs/declare-prefix-for-mode 'go-mode "mh" "help")
(spacemacs/declare-prefix-for-mode 'go-mode "mi" "imports")
(spacemacs/declare-prefix-for-mode 'go-mode "mt" "test")
(spacemacs/declare-prefix-for-mode 'go-mode "mx" "execute")
(spacemacs/set-leader-keys-for-major-mode 'go-mode
"hh" 'godoc-at-point
"ig" 'go-goto-imports
"ia" 'go-import-add
"ir" 'go-remove-unused-imports
"eb" 'go-play-buffer
"er" 'go-play-region
"ed" 'go-download-play
"xx" 'spacemacs/go-run-main
"ga" 'ff-find-other-file
"gc" 'go-coverage
"tt" 'spacemacs/go-run-test-current-function
"ts" 'spacemacs/go-run-test-current-suite
"tp" 'spacemacs/go-run-package-tests
"tP" 'spacemacs/go-run-package-tests-nested))))
(defun go/init-go-eldoc()
(add-hook 'go-mode-hook 'go-eldoc-setup))
(defun go/init-go-guru()
(spacemacs/declare-prefix-for-mode 'go-mode "mf" "guru")
(spacemacs/set-leader-keys-for-major-mode 'go-mode
"fd" 'go-guru-describe
"ff" 'go-guru-freevars
"fi" 'go-guru-implements
"fc" 'go-guru-peers
"fr" 'go-guru-referrers
"fj" 'go-guru-definition
"fp" 'go-guru-pointsto
"fs" 'go-guru-callstack
"fe" 'go-guru-whicherrs
"f<" 'go-guru-callers
"f>" 'go-guru-callees
"fo" 'go-guru-set-scope))
(defun go/init-go-rename()
(use-package go-rename
:init
(spacemacs/declare-prefix-for-mode 'go-mode "mr" "rename")
(spacemacs/set-leader-keys-for-major-mode 'go-mode "rn" 'go-rename)))
2016-04-11 14:08:56 +00:00
(defun go/init-flycheck-gometalinter()
(use-package flycheck-gometalinter
:defer t
:init
(add-hook 'go-mode-hook 'spacemacs//go-enable-gometalinter t)))
(defun go/post-init-ggtags ()
(add-hook 'go-mode-local-vars-hook #'spacemacs/ggtags-mode-enable))
(defun go/post-init-helm-gtags ()
(spacemacs/helm-gtags-define-keys-for-mode 'go-mode))