1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-29 01:24:52 +03:00

Take the formatting function out of the hook

This commit is contained in:
Frank LENORMAND 2015-09-06 18:14:17 +03:00
parent f81e5593db
commit e5da5aca23

View File

@ -59,14 +59,18 @@ def -hidden _golang-indent-on-closing-curly-brace %[
try %[ exec -itersel -draft <a-h><a-k>^\h+\}$<ret>hms\`|.\'<ret>1<a-&> ] try %[ exec -itersel -draft <a-h><a-k>^\h+\}$<ret>hms\`|.\'<ret>1<a-&> ]
] ]
def golang-enable-gofmt -docstring "Format the code using the gofmt utility upon saving" %{ def golang-format-gofmt -docstring "Format the code using the gofmt utility" %{
hook buffer -group golang-formatter BufWritePre .* %{ %sh{
exec -draft %{%|"gofmt"<ret>} readonly x=$((kak_cursor_column - 1))
readonly y="${kak_cursor_line}"
echo "exec -draft %{%|gofmt<ret>}"
echo "exec gg ${y}g ${x}l"
} }
} }
def golang-disable-gofmt -docstring "Disable automatic code formatting" %{ def golang-disable-gofmt -docstring "Disable automatic code formatting" %{
rmhooks buffer golang-formatter rmhooks buffer golang-formatter
} }
# Initialization # 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 \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-opening-curly-brace
hook window InsertChar \} -group golang-indent _golang-indent-on-closing-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).* %{ hook global WinSetOption filetype=(?!golang).* %{
rmhl golang rmhl golang
rmhooks window golang-hooks rmhooks window golang-hooks
rmhooks window golang-indent rmhooks window golang-indent
unalias global format-code
} }