2015-10-22 15:41:19 +02:00
|
|
|
decl str formatcmd ""
|
2016-10-11 09:03:41 +02:00
|
|
|
def format -docstring "Format the contents of the current buffer" %{
|
2015-10-22 15:41:19 +02:00
|
|
|
%sh{
|
|
|
|
if [ ! -z "${kak_opt_formatcmd}" ]; then
|
2016-09-22 01:54:17 +02:00
|
|
|
readonly kak_opt_formatcmd=$(printf '%s' "${kak_opt_formatcmd}" | sed 's/ /<space>/g')
|
2015-10-22 15:41:19 +02:00
|
|
|
## Save the current position of the cursor
|
|
|
|
readonly x=$((kak_cursor_column - 1))
|
|
|
|
readonly y="${kak_cursor_line}"
|
|
|
|
|
2016-09-22 01:54:17 +02:00
|
|
|
printf %s\\n "exec -draft %{%|${kak_opt_formatcmd}<ret>}"
|
2015-10-22 15:41:19 +02:00
|
|
|
## Try to restore the position of the cursor as it was prior to formatting
|
2016-04-23 07:47:01 +02:00
|
|
|
printf %s\\n "exec gg ${y}g ${x}l"
|
2015-10-22 15:41:19 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|