emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/go-mode 903fb9e 216/495: Cancel narrowing before gofmt


From: ELPA Syncer
Subject: [nongnu] elpa/go-mode 903fb9e 216/495: Cancel narrowing before gofmt
Date: Sat, 7 Aug 2021 09:05:17 -0400 (EDT)

branch: elpa/go-mode
commit 903fb9e997166f2f1a23377a79fefe5ca49e830b
Author: Rui Ueyama <ruiu@google.com>
Commit: Dominik Honnef <dominikh@fork-bomb.org>

    Cancel narrowing before gofmt
    
    Previously gofmt would mess up your buffer if you run
    it while your buffer is being narrowed. This patch fixes
    the issue.
---
 go-mode.el | 50 ++++++++++++++++++++++++++------------------------
 1 file changed, 26 insertions(+), 24 deletions(-)

diff --git a/go-mode.el b/go-mode.el
index 0cf2855..af36149 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -689,30 +689,32 @@ buffer."
         (coding-system-for-read 'utf-8)
         (coding-system-for-write 'utf-8))
 
-    (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))
-        (if (zerop (call-process-region (point-min) (point-max) "diff" nil 
patchbuf nil "-n" "-" tmpfile))
-            (progn
-              (kill-buffer errbuf)
-              (message "Buffer is already gofmted"))
-          (go--apply-rcs-patch patchbuf)
-          (kill-buffer errbuf)
-          (message "Applied gofmt"))
-      (message "Could not apply gofmt. Check errors for details")
-      (gofmt--process-errors (buffer-file-name) tmpfile errbuf))
-
-    (kill-buffer patchbuf)
-    (delete-file tmpfile)))
+    (save-restriction
+      (widen)
+      (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))
+          (if (zerop (call-process-region (point-min) (point-max) "diff" nil 
patchbuf nil "-n" "-" tmpfile))
+              (progn
+                (kill-buffer errbuf)
+                (message "Buffer is already gofmted"))
+            (go--apply-rcs-patch patchbuf)
+            (kill-buffer errbuf)
+            (message "Applied gofmt"))
+        (message "Could not apply gofmt. Check errors for details")
+        (gofmt--process-errors (buffer-file-name) tmpfile errbuf))
+
+      (kill-buffer patchbuf)
+      (delete-file tmpfile))))
 
 
 (defun gofmt--process-errors (filename tmpfile errbuf)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]