diff --git a/cmd/goimports/doc.go b/cmd/goimports/doc.go index c793241ef2..f70b46d4fb 100644 --- a/cmd/goimports/doc.go +++ b/cmd/goimports/doc.go @@ -5,13 +5,12 @@ adding missing ones and removing unreferenced ones. $ go get code.google.com/p/go.tools/cmd/goimports -It's a fork of gofmt, and will also format your code, so it can be -used as a replacement for your gofmt-on-save hook in your editor of -choice. +It's a drop-in replacement for your editor's gofmt-on-save hook. +It has the the same command-line interface as gofmt and formats +your code in the same way. -For emacs, make sure you have the latest (Go 1.2) go-mode.el: +For emacs, make sure you have the latest (Go 1.2+) go-mode.el: https://go.googlecode.com/hg/misc/emacs/go-mode.el - Then in your .emacs file: (setq gofmt-command "goimports") (add-to-list 'load-path "/home/you/goroot/misc/emacs/") @@ -19,7 +18,6 @@ Then in your .emacs file: (add-hook 'before-save-hook 'gofmt-before-save) For vim, set "gofmt_command" to "goimports": - https://code.google.com/p/go/source/detail?r=39c724dd7f252 https://code.google.com/p/go/source/browse#hg%2Fmisc%2Fvim etc diff --git a/cmd/goimports/goimports.go b/cmd/goimports/goimports.go index 1f0b44194d..c48cadbb0f 100644 --- a/cmd/goimports/goimports.go +++ b/cmd/goimports/goimports.go @@ -26,15 +26,16 @@ var ( write = flag.Bool("w", false, "write result to (source) file instead of stdout") doDiff = flag.Bool("d", false, "display diffs instead of rewriting files") - options = &imports.Options{} + options = &imports.Options{ + TabWidth: 8, + TabIndent: true, + Comments: true, + } exitCode = 0 ) func init() { flag.BoolVar(&options.AllErrors, "e", false, "report all errors (not just the first 10 on different lines)") - flag.BoolVar(&options.Comments, "comments", true, "print comments") - flag.IntVar(&options.TabWidth, "tabwidth", 8, "tab width") - flag.BoolVar(&options.TabIndent, "tabs", true, "indent with tabs") } func report(err error) {