From e5da5aca23058135456f8e0a14e98ff8ca383db2 Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Sun, 6 Sep 2015 18:14:17 +0300 Subject: [PATCH] Take the formatting function out of the hook --- rc/golang.kak | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/rc/golang.kak b/rc/golang.kak index 83a7d7734..5f57544ba 100644 --- a/rc/golang.kak +++ b/rc/golang.kak @@ -59,14 +59,18 @@ def -hidden _golang-indent-on-closing-curly-brace %[ try %[ exec -itersel -draft ^\h+\}$hms\`|.\'1 ] ] -def golang-enable-gofmt -docstring "Format the code using the gofmt utility upon saving" %{ - hook buffer -group golang-formatter BufWritePre .* %{ - exec -draft %{%|"gofmt"} +def golang-format-gofmt -docstring "Format the code using the gofmt utility" %{ + %sh{ + readonly x=$((kak_cursor_column - 1)) + readonly y="${kak_cursor_line}" + + echo "exec -draft %{%|gofmt}" + echo "exec gg ${y}g ${x}l" } } def golang-disable-gofmt -docstring "Disable automatic code formatting" %{ - rmhooks buffer golang-formatter + rmhooks buffer golang-formatter } # Initialization @@ -80,10 +84,15 @@ hook global WinSetOption filetype=golang %{ hook window InsertChar \n -group golang-indent _golang-indent-on-new-line hook window InsertChar \{ -group golang-indent _golang-indent-on-opening-curly-brace hook window InsertChar \} -group golang-indent _golang-indent-on-closing-curly-brace + + alias global format-code golang-format-gofmt } hook global WinSetOption filetype=(?!golang).* %{ rmhl golang + rmhooks window golang-hooks rmhooks window golang-indent + + unalias global format-code }