dominikh / go-mode.el

Emacs mode for the Go programming language
BSD 3-Clause "New" or "Revised" License
1.37k stars 209 forks source link

gofmt makes point jump unpredictably #375

Closed betaprior closed 3 years ago

betaprior commented 3 years ago

After the invocation of gofmt, either interactively or as part of a save hook, my cursor jumps possibly tens of lines away from where it started (I think it might go to the beginning of a function, but I am not sure). To make matters worse, often when that happens the text in the buffer scrolls and I lose my place. Since I invoke gofmt in a before-save hook, this happens all the time and is quite frustrating. A naive fix below, for some reason, does not work (cursor still jumps, although in a different direction). I don't understand gofmt command code enough to understand what my be causing this. Any ideas?

;; doesn't work :(
  let ((save-point (point)))
    (call-interactively #'gofmt)
    (goto-char save-point))
betaprior commented 3 years ago

Actually, the workaround above works (it appeared to fail due to some non-trivial interaction with other code, but that's outside the scope of this issue).