-
-
Notifications
You must be signed in to change notification settings - Fork 211
Description
Most editors run goimports on the file directly.
go-mode.el's gofmt function on the other hand writes the buffer to a tempfile and then runs goimports on the temp filename. This is problematic because goimports needs to look around the user's $GOPATH and figure out which things can be used and not used (for "internal" and "vendor" directories). This is what motivated the addition of the -srcdir
flag to goimports.
Unfortunately, -srcdir
isn't enough. I also need to know the filename for some in-development feature additions to goimports. (see https://golang.org/cl/23444 from @briantkennedy)
I don't want to add new flags to goimprots.
I propose to change goimports to let -srcdir
mean either a complete filename, or a directory. goimports can detect what it is.
Then the change I propose to go-mode.el is:
diff --git a/go-mode.el b/go-mode.el
index 8acc0e1..9705e76 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -1152,7 +1152,7 @@ with goflymake \(see URL `https://github.com/dougm/goflymake'), gocode
(when (and (gofmt--is-goimports-p) buffer-file-name)
(setq our-gofmt-args
(append our-gofmt-args
- (list "-srcdir" (file-name-directory (file-truename buffer-file-name))))))
+ (list "-srcdir" (file-truename buffer-file-name))))) ; see https://github.com/dominikh/go-mode.el/issues/146
(setq our-gofmt-args (append our-gofmt-args
gofmt-args
(list "-w" tmpfile)))
/cc @adonovan