kakoune/rc/formatter.kak
Frank LENORMAND 8f432a2eea Introduce formatter.kak to handle formatting.
The modified files used to handle formatting code with the same code,
and a different command, the process is now centralized into a single
file. Language support files should set the `formatcmd` string to
whatever formatter is the most popular in their respective community,
eventually with default options.
2015-10-22 16:41:19 +03:00

15 lines
525 B
Plaintext

decl str formatcmd ""
def format -docstring "Format the entire buffer with an external utility" %{
%sh{
if [ ! -z "${kak_opt_formatcmd}" ]; then
## Save the current position of the cursor
readonly x=$((kak_cursor_column - 1))
readonly y="${kak_cursor_line}"
echo "exec -draft %{%|${kak_opt_formatcmd// /<space>}<ret>}"
## Try to restore the position of the cursor as it was prior to formatting
echo "exec gg ${y}g ${x}l"
fi
}
}