Merge remote-tracking branch 'lenormf/fix-formatter'

This commit is contained in:
Maxime Coste 2017-07-16 13:08:04 +09:00
commit c625080ecf

View File

@ -4,10 +4,6 @@ decl -docstring "shell command to which the contents of the current buffer is pi
def format -docstring "Format the contents of the current buffer" %{ eval -draft %{ def format -docstring "Format the contents of the current buffer" %{ eval -draft %{
%sh{ %sh{
if [ -n "${kak_opt_formatcmd}" ]; then if [ -n "${kak_opt_formatcmd}" ]; then
## Save the current position of the cursor
readonly x=$((kak_cursor_column - 1))
readonly y="${kak_cursor_line}"
path_file_tmp=$(mktemp "${TMPDIR:-/tmp}"/kak-formatter-XXXXXX) path_file_tmp=$(mktemp "${TMPDIR:-/tmp}"/kak-formatter-XXXXXX)
printf %s\\n " printf %s\\n "
write \"${path_file_tmp}\" write \"${path_file_tmp}\"
@ -18,8 +14,6 @@ def format -docstring "Format the contents of the current buffer" %{ eval -draft
if cat \"${path_file_tmp}\" | eval \"${kak_opt_formatcmd}\" > \"\${path_file_out}\"; then if cat \"${path_file_tmp}\" | eval \"${kak_opt_formatcmd}\" > \"\${path_file_out}\"; then
printf '%s\\n' \"exec \\%|cat<space>'\${path_file_out}'<ret>\" printf '%s\\n' \"exec \\%|cat<space>'\${path_file_out}'<ret>\"
printf '%s\\n' \"%sh{ rm -f '\${path_file_out}' }\" printf '%s\\n' \"%sh{ rm -f '\${path_file_out}' }\"
## Try to restore the position of the cursor as it was prior to formatting
printf '%s\\n' 'exec gg ${y}g ${x}l'
else else
printf '%s\\n' \" printf '%s\\n' \"
eval -client '${kak_client}' echo -color Error formatter returned an error (\$?) eval -client '${kak_client}' echo -color Error formatter returned an error (\$?)