2017-05-16 13:35:43 +02:00
|
|
|
decl -docstring "shell command to which the contents of the current buffer is piped" \
|
|
|
|
str formatcmd
|
|
|
|
|
2017-06-23 14:09:18 +02:00
|
|
|
def format -docstring "Format the contents of the current buffer" %{ eval -draft %{
|
2015-10-22 15:41:19 +02:00
|
|
|
%sh{
|
2017-06-23 14:09:18 +02:00
|
|
|
if [ -n "${kak_opt_formatcmd}" ]; then
|
|
|
|
path_file_tmp=$(mktemp "${TMPDIR:-/tmp}"/kak-formatter-XXXXXX)
|
|
|
|
printf %s\\n "
|
|
|
|
write \"${path_file_tmp}\"
|
|
|
|
|
|
|
|
%sh{
|
|
|
|
readonly path_file_out=\$(mktemp \"${TMPDIR:-/tmp}\"/kak-formatter-XXXXXX)
|
|
|
|
|
|
|
|
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' \"%sh{ rm -f '\${path_file_out}' }\"
|
|
|
|
else
|
|
|
|
printf '%s\\n' \"
|
2017-07-19 17:18:52 +02:00
|
|
|
eval -client '${kak_client}' echo -markup '{Error}formatter returned an error (\$?)'
|
2017-06-23 14:09:18 +02:00
|
|
|
\"
|
|
|
|
rm -f \"\${path_file_out}\"
|
|
|
|
fi
|
|
|
|
|
|
|
|
rm -f \"${path_file_tmp}\"
|
|
|
|
}
|
|
|
|
"
|
2017-06-26 22:10:04 +02:00
|
|
|
else
|
2017-07-19 17:18:52 +02:00
|
|
|
printf '%s\n' "eval -client '${kak_client}' echo -markup '{Error}formatcmd option not specified'"
|
2015-10-22 15:41:19 +02:00
|
|
|
fi
|
|
|
|
}
|
2017-06-23 14:09:18 +02:00
|
|
|
} }
|