2013-12-19 15:26:26 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
Command goimports updates your Go import lines,
|
|
|
|
adding missing ones and removing unreferenced ones.
|
2013-12-17 19:21:03 -07:00
|
|
|
|
2014-11-09 14:50:40 -07:00
|
|
|
$ go get golang.org/x/tools/cmd/goimports
|
2013-12-17 19:21:03 -07:00
|
|
|
|
2014-02-12 09:35:02 -07:00
|
|
|
It's a drop-in replacement for your editor's gofmt-on-save hook.
|
2014-05-19 10:48:30 -06:00
|
|
|
It has the same command-line interface as gofmt and formats
|
2014-02-12 09:35:02 -07:00
|
|
|
your code in the same way.
|
2013-12-17 19:21:03 -07:00
|
|
|
|
2014-07-01 11:24:22 -06:00
|
|
|
For emacs, make sure you have the latest go-mode.el:
|
|
|
|
https://github.com/dominikh/go-mode.el
|
2013-12-17 19:21:03 -07:00
|
|
|
Then in your .emacs file:
|
|
|
|
(setq gofmt-command "goimports")
|
2014-07-01 11:24:22 -06:00
|
|
|
(add-to-list 'load-path "/home/you/somewhere/emacs/")
|
2013-12-17 19:21:03 -07:00
|
|
|
(require 'go-mode-load)
|
|
|
|
(add-hook 'before-save-hook 'gofmt-before-save)
|
|
|
|
|
|
|
|
For vim, set "gofmt_command" to "goimports":
|
2014-12-11 19:58:46 -07:00
|
|
|
https://golang.org/change/39c724dd7f252
|
|
|
|
https://golang.org/wiki/IDEsAndTextEditorPlugins
|
2013-12-17 19:21:03 -07:00
|
|
|
etc
|
|
|
|
|
|
|
|
For GoSublime, follow the steps described here:
|
2014-01-02 12:02:13 -07:00
|
|
|
http://michaelwhatcott.com/gosublime-goimports/
|
2013-12-17 19:21:03 -07:00
|
|
|
|
|
|
|
For other editors, you probably know what to do.
|
|
|
|
|
2016-07-15 12:28:37 -06:00
|
|
|
To exclude directories in your $GOPATH from being scanned for Go
|
|
|
|
files, goimports respects a configuration file at
|
|
|
|
$GOPATH/src/.goimportsignore which may contain blank lines, comment
|
|
|
|
lines (beginning with '#'), or lines naming a directory relative to
|
|
|
|
the configuration file to ignore when scanning. No globbing or regex
|
|
|
|
patterns are allowed. Use the "-v" verbose flag to verify it's
|
|
|
|
working and see what goimports is doing.
|
|
|
|
|
|
|
|
File bugs or feature requests at:
|
|
|
|
|
|
|
|
https://golang.org/issues/new?title=x/tools/cmd/goimports:+
|
|
|
|
|
2013-12-17 19:21:03 -07:00
|
|
|
Happy hacking!
|
2013-12-19 15:26:26 -07:00
|
|
|
|
|
|
|
*/
|
2014-12-08 21:00:58 -07:00
|
|
|
package main // import "golang.org/x/tools/cmd/goimports"
|