]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1] misc/emacs: Restore the window position after a successful gofmt.
authorJean-Marc Eurin <jmeurin@google.com>
Wed, 13 Jun 2012 20:23:45 +0000 (16:23 -0400)
committerSameer Ajmani <sameer@golang.org>
Wed, 13 Jun 2012 20:23:45 +0000 (16:23 -0400)
««« backport 9d6693456f93
misc/emacs: Restore the window position after a successful gofmt.

This adds restoring the window position so that the buffer doesn't jump around after the erase/copy.

R=sameer
CC=golang-dev
https://golang.org/cl/5981055

»»»

misc/emacs/go-mode.el

index a98c7de589370b7244b40e508209d1ea50a727bc..b2e2d3ab2b5218e207ad72a1f64dd03ee3e0f615 100644 (file)
@@ -743,34 +743,37 @@ Replace the current buffer on success; display errors on failure."
   (let ((currconf (current-window-configuration)))
     (let ((srcbuf (current-buffer)))
       (with-temp-buffer
-       (let ((outbuf (current-buffer))
-             (errbuf (get-buffer-create "*Gofmt Errors*"))
-             (coding-system-for-read 'utf-8)    ;; use utf-8 with subprocesses
-             (coding-system-for-write 'utf-8))
-         (with-current-buffer errbuf (erase-buffer))
-         (with-current-buffer srcbuf
-           (save-restriction
-             (let (deactivate-mark)
-               (widen)
-               (if (= 0 (shell-command-on-region (point-min) (point-max) "gofmt"
-                                                 outbuf nil errbuf))
-                   ;; restore window config
-                   ;; gofmt succeeded: replace the current buffer with outbuf,
-                   ;; restore the mark and point, and discard errbuf.
-                   (let ((old-mark (mark t)) (old-point (point)))
-                     (set-window-configuration currconf)
-                     (erase-buffer)
-                     (insert-buffer-substring outbuf)
-                     (goto-char (min old-point (point-max)))
-                     (if old-mark (push-mark (min old-mark (point-max)) t))
-                     (kill-buffer errbuf))
-
-                 ;; gofmt failed: display the errors
-                 (display-buffer errbuf)))))
-
-         ;; Collapse any window opened on outbuf if shell-command-on-region
-         ;; displayed it.
-         (delete-windows-on outbuf))))))
+        (let ((outbuf (current-buffer))
+              (errbuf (get-buffer-create "*Gofmt Errors*"))
+              (coding-system-for-read 'utf-8)    ;; use utf-8 with subprocesses
+              (coding-system-for-write 'utf-8))
+          (with-current-buffer errbuf (erase-buffer))
+          (with-current-buffer srcbuf
+            (save-restriction
+              (let (deactivate-mark)
+                (widen)
+                (if (= 0 (shell-command-on-region (point-min) (point-max) "gofmt"
+                                                  outbuf nil errbuf))
+                    ;; restore window config
+                    ;; gofmt succeeded: replace the current buffer with outbuf,
+                    ;; restore the mark and point, and discard errbuf.
+                    (let ((old-mark (mark t))
+                          (old-point (point))
+                          (old-start (window-start)))
+                      (erase-buffer)
+                      (insert-buffer-substring outbuf)
+                      (set-window-configuration currconf)
+                      (set-window-start (selected-window) (min old-start (point-max)))
+                      (goto-char (min old-point (point-max)))
+                      (if old-mark (push-mark (min old-mark (point-max)) t))
+                      (kill-buffer errbuf))
+
+                  ;; gofmt failed: display the errors
+                  (display-buffer errbuf)))))
+
+          ;; Collapse any window opened on outbuf if shell-command-on-region
+          ;; displayed it.
+          (delete-windows-on outbuf))))))
 
 ;;;###autoload
 (defun gofmt-before-save ()