Last Updated: February 25, 2016
· eallik

Nice Emacs go-mode indenting and autoformat

This will give you nice 4-spaces-wide true tabs in go-mode as well as automatic formatting on file save:

(add-hook 'go-mode-hook
          (lambda ()
            (add-hook 'before-save-hook 'gofmt-before-save)
            (setq tab-width 4)
            (setq indent-tabs-mode 1)))

2 Responses
Add your response

Great! Thanks!

over 1 year ago ·

I don't like auto-formatting on save when working on shared code, as you then need to exclude (or add patch) hunks from commits that differ just in formatting. I was actually looking for un-hooking before-save in clojure-mode. Your tip gave me a hint on how to accomplish this. Thanks!

over 1 year ago ·