lang/go: add goimports & godoc + more warnings

This commit is contained in:
Henrik Lissner 2017-05-26 02:13:47 +02:00
parent ddef900f6d
commit 009d7c9d49
2 changed files with 28 additions and 9 deletions

View file

@ -3,7 +3,8 @@
This module adds [[https://golang.org][Go]] support.
+ Code completion (~gocode~)
+ eldoc support (~go-eldoc~)
+ Documentation lookup (~godoc~)
+ Eldoc support (~go-eldoc~)
+ REPL (~gore~)
+ Syntax-checking (~flycheck~)
+ Auto-formatting on save (~gofmt~)
@ -12,7 +13,7 @@ This module adds [[https://golang.org][Go]] support.
+ [[https://github.com/hlissner/emacs-snippets/tree/master/go-mode][Snippets]]
#+begin_quote
I have mixed feelings about Go. It's a decent compromise between C and higher-level languages. I like its simplicity and syntax (mostly), but it lacks /native/ support for certain luxuries I miss from other languages, like generics, optional arguments, and function overloading. You've got to learn to love ~interface{}~.
I have mixed feelings about Go. It's a decent compromise between C and higher-level languages. It's a pleasantly straight-forward language with elegant syntax, but it lacks /native/ support for certain luxuries I miss from other languages, like generics, optional arguments, and function overloading. You've got to learn to love ~interface{}~.
Still, Go has been a remarkably useful (and fast!) companion for a variety of small-to-medium backend web and CLI projects.
#+end_quote
@ -34,16 +35,20 @@ sudo pacman --needed --noconfirm -S go
This module requires a valid ~GOPATH~, and the following Go packages:
+ ~gocode~ (for code completion)
+ ~godoc~ (for documentation lookup)
+ ~goimports~ (for auto-formatting code on save and fixing imports)
+ ~gorename~ (for extra refactoring commands)
+ ~gore~ (for the REPL)
+ ~guru~ (for code navigation & refactoring commands)
+ ~gorename~ (for extra refactoring commands)
#+BEGIN_SRC sh
export GOPATH=~/work/go
go get -u github.com/nsf/gocode
go get -u github.com/motemen/gore
go get -u golang.org/x/tools/cmd/guru
go get -u github.com/nsf/gocode
go get -u golang.org/x/tools/cmd/godoc
go get -u golang.org/x/tools/cmd/goimports
go get -u golang.org/x/tools/cmd/gorename
go get -u golang.org/x/tools/cmd/guru
#+END_SRC

View file

@ -4,8 +4,13 @@
:mode "\\.go$"
:interpreter "go"
:config
(setq gofmt-command "goimports")
(add-hook 'go-mode-hook #'flycheck-mode)
(add-hook! go-mode (add-hook 'before-save-hook #'gofmt-before-save nil t))
(if (not (executable-find "goimports"))
(warn "go-mode: couldn't find goimports; no code formatting/fixed imports on save")
(add-hook! go-mode (add-hook 'before-save-hook #'gofmt-before-save nil t)))
(set! :build 'go-build 'go-mode #'+go/build)
(set! :repl 'go-mode #'gorepl-run)
@ -44,13 +49,19 @@
:commands (go-guru-describe go-guru-freevars go-guru-implements go-guru-peers
go-guru-referrers go-guru-definition go-guru-pointsto
go-guru-callstack go-guru-whicherrs go-guru-callers go-guru-callees
go-guru-expand-region))
go-guru-expand-region)
:config
(unless (executable-find "guru")
(warn "go-mode: couldn't find guru, refactoring commands won't work")))
(def-package! company-go
:when (featurep! :completion company)
:after go-mode
:config (set! :company-backend 'go-mode '(company-go)))
:config
(if (executable-find command-go-gocode-command)
(set! :company-backend 'go-mode '(company-go))
(warn "go-mode: couldn't find gocode, code completion won't work")))
(def-package! go-eldoc
@ -59,5 +70,8 @@
(def-package! gorepl-mode
:commands (gorepl-run gorepl-run-load-current-file))
:commands (gorepl-run gorepl-run-load-current-file)
:config
(unless (executable-find "gore")
(warn "go-mode: couldn't find gore, REPL support disabled")))