Emacs go-mode gofmt diff problem

By Xah Lee. Date: .

Shit. In emacs golang go-mode.el, the Alt+x gofmt command doesn't work on Microsoft Windows because it's trying to call unix shell command diff. Sloppy, plus, it shouldn't need to.

emacs go mode diff error 2021-01-15 hMChb
emacs go mode diff error 2021-01-15

gofmt command itself supports diff, by gofmt -d

gofmt diff 2021-01-15 tTvvp
gofmt diff 2021-01-15

now write my own. emacs lisp command to call gofmt. golang

(defun xah-gofmt ()
    "Reformat current file by calling shell command gofmt.
URL `http://ergoemacs.org/misc/emacs_go-mode_gofmt_diff.html'
Version 2021-01-15"
    (let ((xfname (buffer-file-name)))
      (when xfname
        (when (buffer-modified-p )
        (shell-command (format "gofmt -w %s" xfname)))))