This repository has been archived by the owner on Apr 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
packages.el
217 lines (192 loc) · 6.88 KB
/
packages.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
;;; 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 gop-packages
'(
company
(company-go :toggle
(configuration-layer/package-usedp 'company))
flycheck
(flycheck-gometalinter :toggle
(and go-use-gometalinter
(configuration-layer/package-usedp
'flycheck)))
go-eldoc
go-mode
go-guru
;; for refactor
godoctor
go-fill-struct
go-impl
go-rename
go-tag
;; for test
go-gen-test
;; for org-babel
ob-go
;; for go-imenu
(go-imenu :location (recipe :fetcher github
:repo "brantou/go-imenu.el"
:files ("go-imenu.el")))
))
(defun gop/post-init-company ()
(spacemacs|add-company-hook go-mode))
(defun gop/init-company-go ()
(use-package company-go
:defer t
:init
(progn
(setq company-go-show-annotation t)
(push 'company-go company-backends-go-mode))))
(defun gop/post-init-flycheck ()
(spacemacs/add-flycheck-hook 'go-mode))
(defun gop/init-go-mode()
(when (memq window-system '(mac ns x))
(dolist (var '("GOPATH" "GO15VENDOREXPERIMENT"))
(unless (getenv var)
(exec-path-from-shell-copy-env var))))
(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)
(save-selected-window
(async-shell-command (concat "go test " args))))
(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)))))
(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 gop/init-go-eldoc()
(add-hook 'go-mode-hook 'go-eldoc-setup))
(defun gop/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 gop/init-go-rename()
(use-package go-rename
:defer t
:init
(spacemacs/declare-prefix-for-mode 'go-mode "mr" "refactor")
(spacemacs/set-leader-keys-for-major-mode 'go-mode "rn" 'go-rename)))
(defun gop/init-go-tag()
(use-package go-tag
:defer t
:init
(spacemacs/declare-prefix-for-mode 'go-mode "mr" "refactor")
(spacemacs/set-leader-keys-for-major-mode 'go-mode
"rF" 'go-tag-remove
"rf" 'go-tag-add)))
(defun gop/init-go-impl()
(use-package go-impl
:defer t
:init (spacemacs/set-leader-keys-for-major-mode 'go-mode
"ri" 'go-impl)))
(defun gop/init-go-fill-struct ()
(use-package go-fill-struct
:defer t
:init (spacemacs/set-leader-keys-for-major-mode 'go-mode
"rs" 'go-fill-struct)))
(defun gop/init-godoctor ()
(use-package godoctor
:defer t
:init (spacemacs/set-leader-keys-for-major-mode 'go-mode
"rd" 'godoctor-godoc
"re" 'godoctor-extract
"rn" 'godoctor-rename
"rt" 'godoctor-toggle)))
(defun gop/init-go-gen-test()
(use-package go-gen-test
:defer t
:init
(progn
(spacemacs/declare-prefix-for-mode 'go-mode "mtg" "gen-test")
(spacemacs/set-leader-keys-for-major-mode 'go-mode
"tgg" 'go-gen-test-dwim
"tgf" 'go-gen-test-exported
"tgF" 'go-gen-test-all))))
(defun gop/init-flycheck-gometalinter()
(use-package flycheck-gometalinter
:defer t
:init
(add-hook 'go-mode-hook 'spacemacs//go-enable-gometalinter t)))
(defun gop/pre-init-ob-go ()
(spacemacs|use-package-add-hook org
:post-config
(use-package ob-go
:init (add-to-list 'org-babel-load-languages '(go . t)))))
(defun gop/init-ob-go ())
(defun gop/init-go-imenu()
(add-hook 'go-mode-hook 'go-imenu-setup))