Wednesday 15 February 2012

go - goimports behaves differently when called from emacs -



go - goimports behaves differently when called from emacs -

i'm observing puzzling behaviour of goimports command called emacs. i'm using svgo go package, , minimal programme illustration in doc imports "github.com/ajstarks/svgo"

the code works fine. goimports command "tool prepare (add, remove) go imports automatically". since "github.com/ajstarks/svgo" needed, don't expect goimports remove it. , it's true when phone call terminal:

$ head gg.go bundle main import ( "os" "github.com/ajstarks/svgo" ) func main() {

then:

$ goimports gg.go | head bundle main import ( "os" "github.com/ajstarks/svgo" ) func main() {

as expected, rearranged imports next "first standard library, external packages". funny part: when phone call goimports emacs, deletes "github.com/ajstarks/svgo" line! (and programme no longer compiles).

here's (the relevant part of) .init file:

(setq exec-path (cons "/usr/local/go/bin" exec-path)) (add-to-list 'exec-path "~/go/bin") (defun my-go-mode-hook () (setq gofmt-command "goimports") ; utilize goimports instead of go-fmt (add-hook 'before-save-hook 'gofmt-before-save)) (add-hook 'go-mode-hook 'my-go-mode-hook)

if comment (setq gofmt-command "goimports") line, svgo import doesn't deleted.

how's possible?

emacs go

No comments:

Post a Comment