2015-10-22 15:41:19 +02:00
|
|
|
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}"
|
|
|
|
|
2016-03-15 12:25:47 +01:00
|
|
|
printf %s "exec -draft %{%|${kak_opt_formatcmd// /<space>}<ret>}"
|
2015-10-22 15:41:19 +02:00
|
|
|
## Try to restore the position of the cursor as it was prior to formatting
|
2016-03-15 12:25:47 +01:00
|
|
|
printf %s "exec gg ${y}g ${x}l"
|
2015-10-22 15:41:19 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|