mirror of
https://github.com/golang/go
synced 2024-11-24 21:00:09 -07:00
misc/emacs/go-lang.el: Fix restoration of multiple windows in a frame after gofmt
If a frame has multiple windows then the windows must all be restored after gofmt has finished and the old windows must be restored. Before this fix, only the Go code edit window would be left. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5280050
This commit is contained in:
parent
eef7809193
commit
350a5ce64f
@ -7,6 +7,7 @@
|
|||||||
;;; To do:
|
;;; To do:
|
||||||
|
|
||||||
;; * Indentation is *almost* identical to gofmt
|
;; * Indentation is *almost* identical to gofmt
|
||||||
|
;; ** We think struct literal keys are labels and outdent them
|
||||||
;; ** We disagree on the indentation of function literals in arguments
|
;; ** We disagree on the indentation of function literals in arguments
|
||||||
;; ** There are bugs with the close brace of struct literals
|
;; ** There are bugs with the close brace of struct literals
|
||||||
;; * Highlight identifiers according to their syntactic context: type,
|
;; * Highlight identifiers according to their syntactic context: type,
|
||||||
@ -355,7 +356,7 @@ indented one level."
|
|||||||
|
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(back-to-indentation)
|
(back-to-indentation)
|
||||||
(let ((cs (go-mode-cs)) (case-fold-search nil))
|
(let ((cs (go-mode-cs)))
|
||||||
;; Treat comments and strings differently only if the beginning
|
;; Treat comments and strings differently only if the beginning
|
||||||
;; of the line is contained within them
|
;; of the line is contained within them
|
||||||
(when (and cs (= (point) (car cs)))
|
(when (and cs (= (point) (car cs)))
|
||||||
@ -400,8 +401,7 @@ indented one level."
|
|||||||
(setq first nil))))
|
(setq first nil))))
|
||||||
|
|
||||||
;; case, default, and labels are outdented 1 level
|
;; case, default, and labels are outdented 1 level
|
||||||
;; assume that labels are alone on the line
|
(when (looking-at "\\<case\\>\\|\\<default\\>\\|\\w+\\s *:\\(\\S.\\|$\\)")
|
||||||
(when (looking-at "\\<case\\>\\|\\<default\\>\\|\\w+\\s *:\\s *$")
|
|
||||||
(decf indent tab-width))
|
(decf indent tab-width))
|
||||||
|
|
||||||
;; Continuation lines are indented 1 level
|
;; Continuation lines are indented 1 level
|
||||||
@ -504,6 +504,7 @@ Useful for development work."
|
|||||||
Replace the current buffer on success; display errors on failure."
|
Replace the current buffer on success; display errors on failure."
|
||||||
|
|
||||||
(interactive)
|
(interactive)
|
||||||
|
(let ((currconf (current-window-configuration)))
|
||||||
(let ((srcbuf (current-buffer)))
|
(let ((srcbuf (current-buffer)))
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(let ((outbuf (current-buffer))
|
(let ((outbuf (current-buffer))
|
||||||
@ -517,9 +518,11 @@ Replace the current buffer on success; display errors on failure."
|
|||||||
(widen)
|
(widen)
|
||||||
(if (= 0 (shell-command-on-region (point-min) (point-max) "gofmt"
|
(if (= 0 (shell-command-on-region (point-min) (point-max) "gofmt"
|
||||||
outbuf nil errbuf))
|
outbuf nil errbuf))
|
||||||
|
;; restore window config
|
||||||
;; gofmt succeeded: replace the current buffer with outbuf,
|
;; gofmt succeeded: replace the current buffer with outbuf,
|
||||||
;; restore the mark and point, and discard errbuf.
|
;; restore the mark and point, and discard errbuf.
|
||||||
(let ((old-mark (mark t)) (old-point (point)))
|
(let ((old-mark (mark t)) (old-point (point)))
|
||||||
|
(set-window-configuration currconf)
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(insert-buffer-substring outbuf)
|
(insert-buffer-substring outbuf)
|
||||||
(goto-char (min old-point (point-max)))
|
(goto-char (min old-point (point-max)))
|
||||||
@ -531,7 +534,7 @@ Replace the current buffer on success; display errors on failure."
|
|||||||
|
|
||||||
;; Collapse any window opened on outbuf if shell-command-on-region
|
;; Collapse any window opened on outbuf if shell-command-on-region
|
||||||
;; displayed it.
|
;; displayed it.
|
||||||
(delete-windows-on outbuf)))))
|
(delete-windows-on outbuf))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun gofmt-before-save ()
|
(defun gofmt-before-save ()
|
||||||
@ -541,7 +544,6 @@ Replace the current buffer on success; display errors on failure."
|
|||||||
(interactive)
|
(interactive)
|
||||||
(when (eq major-mode 'go-mode) (gofmt)))
|
(when (eq major-mode 'go-mode) (gofmt)))
|
||||||
|
|
||||||
|
|
||||||
(defun godoc-read-query ()
|
(defun godoc-read-query ()
|
||||||
"Read a godoc query from the minibuffer."
|
"Read a godoc query from the minibuffer."
|
||||||
;; Compute the default query as the symbol under the cursor.
|
;; Compute the default query as the symbol under the cursor.
|
||||||
|
Loading…
Reference in New Issue
Block a user