From bc092acaeeb16c22f447a7f6dcc2656dce9363ef Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 8 Sep 2018 23:47:44 -0400 Subject: [PATCH] lang/go: use gofmt for partials goimports (if available) doesn't play well with partial code reformatting. --- modules/lang/go/config.el | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/lang/go/config.el b/modules/lang/go/config.el index 1c09c4a1e..bad6fd442 100644 --- a/modules/lang/go/config.el +++ b/modules/lang/go/config.el @@ -12,11 +12,13 @@ :references #'go-guru-referrers :documentation #'godoc-at-point) - (set-formatter! 'go-mode #'gofmt) - (when-let* ((goimports (executable-find "goimports"))) - (setq gofmt-command goimports)) - (when (featurep! :feature syntax-checker) - (setq gofmt-show-errors nil)) ; Leave it to flycheck + ;; Redefines default formatter to *not* use goimports if reformatting a + ;; region; as it doesn't play well with partial code. + (set-formatter! 'gofmt + '(("%s" (if (or (use-region-p) + (not (executable-find "goimports"))) + "gofmt" + "goimports")))) (add-hook 'go-mode-hook #'go-eldoc-setup)