summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorKevin Ballard <kevin@sb.org>2009-11-12 18:40:42 -0800
committerKevin Ballard <kevin@sb.org>2009-11-12 18:40:42 -0800
commit9a286997d4eaa467bd617414cf56ece833f50aa2 (patch)
tree81168af23225b5e09336a3f13ee4bb686f2a5b7b /misc
parentb823121815713c494cf9658643b1f87c595dae72 (diff)
downloadgolang-9a286997d4eaa467bd617414cf56ece833f50aa2.tar.gz
Teach emacs M-x gofmt to save region/restrictions
R=agl, agl1 http://codereview.appspot.com/152078 Committer: Adam Langley <agl@golang.org>
Diffstat (limited to 'misc')
-rw-r--r--misc/emacs/go-mode.el13
1 files changed, 12 insertions, 1 deletions
diff --git a/misc/emacs/go-mode.el b/misc/emacs/go-mode.el
index 47d790db4..42336a0fe 100644
--- a/misc/emacs/go-mode.el
+++ b/misc/emacs/go-mode.el
@@ -475,4 +475,15 @@ Useful for development work."
"Pipe the current buffer through the external tool `gofmt`."
(interactive)
- (shell-command-on-region 1 (+ (buffer-size) 1) "gofmt" t t shell-command-default-error-buffer))
+ ;; for some reason save-excursion isn't working
+ ;; probably because shell-command-on-region deletes the contents of the
+ ;; region before filling in the new values
+ ;; so we will save the point/mark by hand
+ ;; similarly we can't use push-mark/pop-mark
+ (let ((old-mark (mark t)) (old-point (point)))
+ (save-restriction
+ (let (deactivate-mark)
+ (widen)
+ (shell-command-on-region (point-min) (point-max) "gofmt" t t shell-command-default-error-buffer)))
+ (goto-char (min old-point (point-max)))
+ (if old-mark (set-mark (min old-mark (point-max))))))