From 6ee2acd674d3a89cad89c28cdb4408d2c76e1031 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Wed, 22 Jul 2015 12:02:10 +0300 Subject: [PATCH] Add an option to auto-format Go buffers on write --- rc/golang.kak | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/rc/golang.kak b/rc/golang.kak index d2f25376..7bd43a90 100644 --- a/rc/golang.kak +++ b/rc/golang.kak @@ -59,6 +59,16 @@ def -hidden _golang-indent-on-closing-curly-brace %[ try %[ exec -itersel -draft ^\h+\}$hms\`|.\'1 ] ] +def golang-enable-gofmt %{ + hook buffer -group golang-formatter BufWritePre .* %{ + exec -draft %{%|"gofmt"} + } +} + +def golang-disable-gofmt %{ + rmhooks buffer golang-formatter +} + # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ @@ -74,6 +84,6 @@ hook global WinSetOption filetype=golang %{ hook global WinSetOption filetype=(?!golang).* %{ rmhl golang - rmhooks window golang-hooks - rmhooks window golang-indent + rmhooks window golang-hooks + rmhooks window golang-indent }