From 88775a91b3104df38732b4911b495ac5c5f20e7a Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Sun, 6 Sep 2015 18:05:33 +0300 Subject: [PATCH] Take the formatting function out of the hook --- rc/dlang.kak | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/rc/dlang.kak b/rc/dlang.kak index 53ab4752..406134be 100644 --- a/rc/dlang.kak +++ b/rc/dlang.kak @@ -16,8 +16,8 @@ addhl -group / regions -default code dlang \ string '"' (?${kak_opt_dlang_dfmt_options// /}}" - } +def dlang-format-dfmt -docstring "Format the code using the dfmt utility" %{ + %sh{ + readonly x=$((kak_cursor_column - 1)) + readonly y="${kak_cursor_line}" + + echo "exec -draft %{%|dfmt${kak_opt_dlang_dfmt_options// /}}" + echo "exec gg ${y}g ${x}l" } } def dlang-disable-dfmt -docstring "Disable automatic code formatting" %{ - rmhooks buffer dlang-formatter + rmhooks buffer dlang-formatter } # Initialization @@ -94,10 +96,15 @@ hook global WinSetOption filetype=dlang %{ hook window InsertChar \n -group dlang-indent _dlang-indent-on-new-line hook window InsertChar \{ -group dlang-indent _dlang-indent-on-opening-curly-brace hook window InsertChar \} -group dlang-indent _dlang-indent-on-closing-curly-brace + + alias global format-code dlang-format-dfmt } hook global WinSetOption filetype=(?!dlang).* %{ rmhl dlang + rmhooks window dlang-hooks rmhooks window dlang-indent + + unalias global format-code }