Improve fmt-in-write by storing results in a tempfile
Improve fmt-in-write by storing results in a tempfile

The current implementation of `gofmt -w` is incomplete as it cannot be
used from a BufWritePre hook. The command is run on a buffer's backing
file, but if the user's buffer has not been flushed to disk, gofmt
processes the existing file and we discard the user's changes.

We can avoid this situation by using a tempfile and moving the file into
place after a successful fmt.

Also note that `let &syntax = &syntax` is the preferred way of resetting
the syntax engine for a particular buffer.

t-yuki/vim-go,ev46/vim-go,syohex/vim-go,wingyplus/vim-go,prodis/vim-go,rxwen/vim-go,mizoR/vim-go,lioonline/vim-go,wheelcomplex/vim-go,mrnugget/vim-go,glittershark/vim-go,apriendeau/vim-go,andviro/vim-go,vim-IDE/vim-go,shaunstanislaus/vim-go,vim-IDE/vim-go,vashstorm/vim-go,jacobxk/vim-go,DrGo/vim-go,emmagras/vim-go,mechmind/vim-go,youleiy/vim-go,phemmer/vim-go,vim-IDE/vim-go,nowk/vim-go,ebfe/vim-go,hiteshjoshi/vim-go,andviro/vim-go