For more details on this refer to the Go Language Auto-formatting on Save topic.
The goimports utility is drop in replacement for gofmt and like gofmt it formats the code, but this utility also adds/removes imports as required.
So How Does it Work?
The Zeus file save trigger allows a macro to be attached to any file save event and in this case the goimports macro is configured to fire whenever the file is saved.
So consider this code:
Code: Select all
package main
import "bytes"
func main() {
fmt.Printf("Hello world!\n")
}
Code: Select all
package main
import "fmt"
func main() {
fmt.Printf("Hello world!\n")
}

Note: For details on setting up the Go compiler refer to this tutorial.
Setup for New Zeus Users
For user new to Zeus wanting to try out this feature just do the following:
- Download the latest Zeus release found here: http://www.zeusedit.com/download.html
- Open any Go file, make a small change to that file and save those changes.
- Follow the instructions in the resulting dialog.
For Zeus users already running an older version of Zeus just follow the following instructions:
- Download and build goimports which is found here: https://github.com/bradfitz/goimports
- Copy the goimports.exe to the Zeus binary install folder
- Make new goimports script by copying the gofmt script from this link: http://www.zeusedit.com/zforum/viewtopic.php?t=6819
- Find this line in the new goimports script
Code: Select all
-- build up the final styling command line local cmd = "gofmt.exe" .. " " .. cmd_options .. " \"" .. file_name .. "\""
- Change that line to read as follows
Code: Select all
-- build up the final styling command line local cmd = "goimports.exe" .. " " .. cmd_options .. " \"" .. file_name .. "\""
- Configure the script as per the instructions from this topic: http://www.zeusedit.com/zforum/viewtopic.php?t=6819