branch: elpa/go-mode
commit 15d227ae1cf8d55ae4395108bccc8ad6ca7d1eba
Author: Juergen Hoetzel <[email protected]>
Commit: Dominik Honnef <[email protected]>

    gofmt: wrap external commands in `unwind-protect'
    
    This ensures that the temporary file and buffer get deleted.
---
 AUTHORS    |  1 +
 go-mode.el | 47 ++++++++++++++++++++++++-----------------------
 2 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/AUTHORS b/AUTHORS
index 4010f5f..f7de154 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -14,6 +14,7 @@ Iwasaki Yudai <[email protected]>
 James Aguilar <[email protected]>
 Jan Newmarch <[email protected]>
 Jean-Marc Eurin <[email protected]>
+Juergen Hoetzel <[email protected]>
 Kevin Ballard <[email protected]>
 Mats Lidell <[email protected]>
 Peter Kleiweg <[email protected]>
diff --git a/go-mode.el b/go-mode.el
index 820870c..dc34318 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -982,29 +982,30 @@ with goflymake \(see URL 
`https://github.com/dougm/goflymake'), gocode
         (coding-system-for-read 'utf-8)
         (coding-system-for-write 'utf-8))
 
-    (save-restriction
-      (widen)
-      (if errbuf
-          (with-current-buffer errbuf
-            (setq buffer-read-only nil)
-            (erase-buffer)))
-      (with-current-buffer patchbuf
-        (erase-buffer))
-
-      (write-region nil nil tmpfile)
-
-      ;; 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 (call-process gofmt-command nil errbuf nil "-w" tmpfile))
-          (progn
-            (if (zerop (call-process-region (point-min) (point-max) "diff" nil 
patchbuf nil "-n" "-" tmpfile))
-                (message "Buffer is already gofmted")
-              (go--apply-rcs-patch patchbuf)
-              (message "Applied gofmt"))
-            (if errbuf (gofmt--kill-error-buffer errbuf)))
-        (message "Could not apply gofmt")
-        (if errbuf (gofmt--process-errors (buffer-file-name) tmpfile errbuf)))
+    (unwind-protect
+        (save-restriction
+          (widen)
+          (if errbuf
+              (with-current-buffer errbuf
+                (setq buffer-read-only nil)
+                (erase-buffer)))
+          (with-current-buffer patchbuf
+            (erase-buffer))
+
+          (write-region nil nil tmpfile)
+
+          ;; 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 (call-process gofmt-command nil errbuf nil "-w" tmpfile))
+              (progn
+                (if (zerop (call-process-region (point-min) (point-max) "diff" 
nil patchbuf nil "-n" "-" tmpfile))
+                    (message "Buffer is already gofmted")
+                  (go--apply-rcs-patch patchbuf)
+                  (message "Applied gofmt"))
+                (if errbuf (gofmt--kill-error-buffer errbuf)))
+            (message "Could not apply gofmt")
+            (if errbuf (gofmt--process-errors (buffer-file-name) tmpfile 
errbuf))))
 
       (kill-buffer patchbuf)
       (delete-file tmpfile))))

Reply via email to