@@ -1751,10 +1751,16 @@ The following extra functions are defined:
1751
1751
- `godef-describe' and `godef-jump'
1752
1752
- `go-coverage'
1753
1753
1754
- If you want to automatically run `gofmt' before saving a file,
1755
- add the following hook to your Emacs configuration:
1754
+ If you want to automatically run `gofmt' before saving a file enable the
1755
+ gofmt minor mode. To do so you can add the following to to your Emacs
1756
+ configuration:
1756
1757
1757
- \( add-hook 'before-save-hook #'gofmt-before-save)
1758
+ \( add-hook 'go-mode-hook #'gofmt-mode)
1759
+
1760
+ Or if you use `use-package' :
1761
+
1762
+ \( use-package go-mode
1763
+ :hook ((go-mode . gofmt-mode)))
1758
1764
1759
1765
If you want to use `godef-jump' instead of etags (or similar),
1760
1766
consider binding godef-jump to `M-.' , which is the default key
@@ -1995,15 +2001,13 @@ arguments can be set as a list via ‘gofmt-args’."
1995
2001
(kill-buffer errbuf))))
1996
2002
1997
2003
;;;### autoload
1998
- (defun gofmt-before-save ()
1999
- " Add this to .emacs to run gofmt on the current buffer when saving:
2000
- \( add-hook 'before-save-hook 'gofmt-before-save).
2001
-
2002
- Note that this will cause ‘go-mode’ to get loaded the first time
2003
- you save any file, kind of defeating the point of autoloading."
2004
-
2005
- (interactive )
2006
- (when (eq major-mode 'go-mode ) (gofmt)))
2004
+ (define-minor-mode gofmt-mode
2005
+ " Runs gofmt before saving the file."
2006
+ :lighter " gofmt"
2007
+ :global nil
2008
+ (if gofmt-mode
2009
+ (add-hook 'before-save-hook 'gofmt nil 'local )
2010
+ (remove-hook 'before-save-hook 'gofmt 'local )))
2007
2011
2008
2012
(defun godoc--read-query ()
2009
2013
" Read a godoc query from the minibuffer."
0 commit comments