1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-02 00:46:42 +03:00
kakoune/rc/core/formatter.kak

16 lines
621 B
Plaintext
Raw Normal View History

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