              (if (gofmt--is-goimports-p)
                  (concat (file-name-directory filename) (file-name-nondirectory tmpfile))
                tmpfile)))
-        (while (search-forward-regexp (concat "^\\(" (regexp-quote truefile) "\\):") nil t)
+        (while (search-forward-regexp
+                (concat "^\\(" (regexp-quote (go--file-local-name truefile))
+                        "\\):")
+                nil t)
           (replace-match (file-name-nondirectory filename) t t nil 1)))
       (compilation-mode)
       (display-buffer errbuf))))

    (1- (position-bytes (point-max)))))


(provide 'go-mode)

;;; go-mode.el ends here

                          ;; accepting a full path, and some features
                          ;; of goimports rely on knowing the full
                          ;; name.
                          (list "-srcdir" (go--file-local-name
                                           (file-truename buffer-file-name))))))
          (setq our-gofmt-args
                (append our-gofmt-args gofmt-args
                        (list "-w" (go--file-local-name tmpfile))))
          (message "Calling gofmt: %s %s" gofmt-command our-gofmt-args)
          ;; We're using errbuf for the mixed stdout and stderr output. This
          ;; is not an issue because gofmt -w does not produce any stdout
          ;; output in case of success.
          (if (zerop (apply #'process-file gofmt-command nil errbuf nil our-gofmt-args))
              (progn
                ;; There is no remote variant of ‘call-process-region’, but we
                ;; can invoke diff locally, and the results should be the same.
                (if (zerop (let ((local-copy (file-local-copy tmpfile)))
                             (unwind-protect
                                 (call-process-region
                                  (point-min) (point-max) "diff" nil patchbuf
                                  nil "-n" "-" (or local-copy tmpfile))
                               (when local-copy (delete-file local-copy)))))
                    (message "Buffer is already gofmted")
                  (go--apply-rcs-patch patchbuf)
                  (message "Applied gofmt"))
