spacemacs/layers/+lang/go/packages.el

160 lines
4.8 KiB
EmacsLisp
Raw Normal View History

2017-02-01 14:06:00 +00:00
;;; packages.el --- Go Layer packages File for Spacemacs
;;
2018-01-04 07:00:25 +00:00
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
2017-02-01 14:06:00 +00:00
;;
;; 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
'(
2017-07-03 07:52:54 +00:00
(company-go :requires company)
flycheck
(flycheck-gometalinter :toggle (and go-use-gometalinter
(configuration-layer/package-used-p
'flycheck)))
ggtags
counsel-gtags
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
2017-05-25 11:19:32 +00:00
godoctor
2017-12-05 14:48:29 +00:00
go-tag
popwin
go-gen-test
))
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" "GOROOT" "GO15VENDOREXPERIMENT") exec-path-from-shell-variables)
(unless (or (member var exec-path-from-shell-variables) (getenv var))
(add-to-list 'exec-path-from-shell-variables var)))))
(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)
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))))
2017-05-25 11:20:36 +00:00
(defun go/init-go-eldoc ()
(add-hook 'go-mode-hook 'go-eldoc-setup))
2017-05-25 11:20:36 +00:00
(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))
2017-05-25 11:20:36 +00:00
(defun go/init-go-rename ()
(use-package go-rename
:init
2017-05-25 11:19:32 +00:00
(spacemacs/declare-prefix-for-mode 'go-mode "mr" "refactoring")
(spacemacs/set-leader-keys-for-major-mode 'go-mode "rN" 'go-rename)))
(defun go/init-godoctor ()
(use-package godoctor
:defer t
2017-05-25 11:19:32 +00:00
:init
(progn
(spacemacs/declare-prefix-for-mode 'go-mode "mr" "refactoring")
(spacemacs/set-leader-keys-for-major-mode 'go-mode
"rn" 'godoctor-rename
"re" 'godoctor-extract
"rt" 'godoctor-toggle
"rd" 'godoctor-godoc))))
2016-04-11 14:08:56 +00:00
2017-12-05 14:48:29 +00:00
(defun go/init-go-tag ()
(use-package go-tag
:init
(spacemacs/declare-prefix-for-mode 'go-mode "mr" "refactoring")
(spacemacs/set-leader-keys-for-major-mode 'go-mode
"rf" 'go-tag-add
"rF" 'go-tag-remove)))
2017-05-25 11:20:36 +00:00
(defun go/init-flycheck-gometalinter ()
2016-04-11 14:08:56 +00:00
(use-package flycheck-gometalinter
:defer t
:init
(add-hook 'go-mode-hook 'spacemacs//go-enable-gometalinter t)))
(defun go/init-go-gen-test()
(use-package go-gen-test
:init
(spacemacs/declare-prefix-for-mode 'go-mode "mt" "test")
(spacemacs/set-leader-keys-for-major-mode 'go-mode
"tf" 'go-gen-test-dwim
"tg" 'go-gen-test-exported
"tG" 'go-gen-test-all)))
(defun go/post-init-ggtags ()
(add-hook 'go-mode-local-vars-hook #'spacemacs/ggtags-mode-enable))
(defun go/post-init-counsel-gtags ()
(spacemacs/counsel-gtags-define-keys-for-mode 'go-mode))
(defun go/post-init-helm-gtags ()
(spacemacs/helm-gtags-define-keys-for-mode 'go-mode))