rc: Use the standard fail command to report errors

Merely using `echo` with markup doesn't log errors in the debug
buffers, and is also less readable.
This commit is contained in:
Frank LENORMAND 2019-11-14 08:32:55 +01:00
parent a7d3976a10
commit 5b1f9255a1
11 changed files with 25 additions and 30 deletions

View File

@ -13,7 +13,7 @@ hook global BufCreate .*[.](editorconfig) %{
define-command editorconfig-load -params ..1 -docstring "editorconfig-load [file]: set formatting behavior according to editorconfig" %{ define-command editorconfig-load -params ..1 -docstring "editorconfig-load [file]: set formatting behavior according to editorconfig" %{
evaluate-commands %sh{ evaluate-commands %sh{
command -v editorconfig >/dev/null 2>&1 || { printf %s\\n 'echo -markup "{Error}editorconfig could not be found"'; exit 1; } command -v editorconfig >/dev/null 2>&1 || { echo "fail editorconfig could not be found"; exit 1; }
file="${1:-$kak_buffile}" file="${1:-$kak_buffile}"
case $file in case $file in

View File

@ -188,7 +188,7 @@ define-command clang-diagnostics-next -docstring "Jump to the next line that con
if [ -n "$line" ]; then if [ -n "$line" ]; then
printf %s\\n "execute-keys ${line} g" printf %s\\n "execute-keys ${line} g"
else else
echo "echo -markup '{Error}no next clang diagnostic'" echo "fail no next clang diagnostic"
fi fi
} } } }

View File

@ -49,7 +49,7 @@ define-command -params ..1 \
menu_item = $2; gsub("!", "!!", menu_item); menu_item = $2; gsub("!", "!!", menu_item);
edit_path = path($2); gsub("&", "&&", edit_path); gsub("#", "##", edit_path); gsub("\\|", "||", edit_path); edit_path = path($2); gsub("&", "&&", edit_path); gsub("#", "##", edit_path); gsub("\\|", "||", edit_path);
select = $1; gsub(/</, "<lt>", select); gsub(/\t/, "<c-v><c-i>", select); gsub("!", "!!", select); gsub("&", "&&", select); gsub("#", "##", select); gsub("\\|", "||", select); select = $1; gsub(/</, "<lt>", select); gsub(/\t/, "<c-v><c-i>", select); gsub("!", "!!", select); gsub("&", "&&", select); gsub("#", "##", select); gsub("\\|", "||", select);
out = out "%!" menu_item ": {MenuInfo}" menu_info "! %!evaluate-commands %# try %& edit -existing %|" edit_path "|; execute-keys %|/\\Q" keys "<ret>vc| & catch %& echo -markup %|{Error}unable to find tag| &; try %& execute-keys %|s\\Q" select "<ret>| & # !" out = out "%!" menu_item ": {MenuInfo}" menu_info "! %!evaluate-commands %# try %& edit -existing %|" edit_path "|; execute-keys %|/\\Q" keys "<ret>vc| & catch %& fail unable to find tag &; try %& execute-keys %|s\\Q" select "<ret>| & # !"
} }
/[^\t]+\t[^\t]+\t[0-9]+/ { /[^\t]+\t[^\t]+\t[0-9]+/ {
menu_item = $2; gsub("!", "!!", menu_item); menu_item = $2; gsub("!", "!!", menu_item);
@ -57,9 +57,9 @@ define-command -params ..1 \
menu_info = $3; gsub("!", "!!", menu_info); gsub("{", "\\{", menu_info); menu_info = $3; gsub("!", "!!", menu_info); gsub("{", "\\{", menu_info);
edit_path = path($2); gsub("!", "!!", edit_path); gsub("#", "##", edit_path); gsub("&", "&&", edit_path); gsub("\\|", "||", edit_path); edit_path = path($2); gsub("!", "!!", edit_path); gsub("#", "##", edit_path); gsub("&", "&&", edit_path); gsub("\\|", "||", edit_path);
line_number = $3; line_number = $3;
out = out "%!" menu_item ": {MenuInfo}" menu_info "! %!evaluate-commands %# try %& edit -existing %|" edit_path "|; execute-keys %|" line_number "gx| & catch %& echo -markup %|{Error}unable to find tag| &; try %& execute-keys %|s\\Q" select "<ret>| & # !" out = out "%!" menu_item ": {MenuInfo}" menu_info "! %!evaluate-commands %# try %& edit -existing %|" edit_path "|; execute-keys %|" line_number "gx| & catch %& fail unable to find tag &; try %& execute-keys %|s\\Q" select "<ret>| & # !"
} }
END { print ( length(out) == 0 ? "echo -markup %{{Error}no such tag " ENVIRON["tagname"] "}" : "menu -markup -auto-single " out ) } END { print ( length(out) == 0 ? "fail no such tag " ENVIRON["tagname"] : "menu -markup -auto-single " out ) }
# Ensure x is an absolute file path, by prepending with tagroot # Ensure x is an absolute file path, by prepending with tagroot
function path(x) { return x ~/^\// ? x : tagroot x }' function path(x) { return x ~/^\// ? x : tagroot x }'
]] ]]

View File

@ -67,7 +67,7 @@ define-command doc-jump-to-anchor -params 1 %{
exit exit
fi fi
done done
printf "echo -markup {Error}No such anchor '%s'" "${anchor}" printf "fail No such anchor '%s'\n" "${anchor}"
} }
} }
@ -157,7 +157,7 @@ An optional keyword argument can be passed to the function, which will be automa
fi fi
printf %s\\n "evaluate-commands -try-client %opt{docsclient} %{ doc-render ${page}; ${jump_cmd} }" printf %s\\n "evaluate-commands -try-client %opt{docsclient} %{ doc-render ${page}; ${jump_cmd} }"
else else
printf %s\\n "echo -markup '{Error}No such doc file: ${page}'" printf 'fail No such doc file: %s\n' "${page}"
fi fi
} }
} }

View File

@ -11,7 +11,7 @@ define-command format-buffer -docstring "Format the contents of the buffer" %{
define-command format-selections -docstring "Format the selections individually" %{ define-command format-selections -docstring "Format the selections individually" %{
evaluate-commands %sh{ evaluate-commands %sh{
if [ -z "${kak_opt_formatcmd}" ]; then if [ -z "${kak_opt_formatcmd}" ]; then
printf "fail 'The option ''formatcmd'' must be set'" echo "fail 'The option ''formatcmd'' must be set'"
fi fi
} }
evaluate-commands -draft -no-hooks -save-regs '|' %{ evaluate-commands -draft -no-hooks -save-regs '|' %{
@ -24,7 +24,7 @@ define-command format-selections -docstring "Format the selections individually"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
cat "$format_out" cat "$format_out"
else else
printf 'eval -client %s %%{ echo -markup %%{{Error}formatter returned an error %s} }' "$kak_client" "$?" | kak -p "$kak_session" printf 'eval -client %s %%{ fail formatter returned an error %s }\n' "$kak_client" "$?" | kak -p "$kak_session"
cat "$format_in" cat "$format_in"
fi fi
rm -f "$format_in" "$format_out" rm -f "$format_in" "$format_out"

View File

@ -39,7 +39,7 @@ Available commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide-
cd_bufdir() { cd_bufdir() {
dirname_buffer="${kak_buffile%/*}" dirname_buffer="${kak_buffile%/*}"
cd "${dirname_buffer}" 2>/dev/null || { cd "${dirname_buffer}" 2>/dev/null || {
printf 'echo -markup {Error}Unable to change the current working directory to: %s' "${dirname_buffer}" printf 'fail Unable to change the current working directory to: %s\n' "${dirname_buffer}"
exit 1 exit 1
} }
} }
@ -103,7 +103,7 @@ Available commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide-
if git "${@}" > /dev/null 2>&1; then if git "${@}" > /dev/null 2>&1; then
printf %s "echo -markup '{Information}git $1 succeeded'" printf %s "echo -markup '{Information}git $1 succeeded'"
else else
printf %s "echo -markup '{Error}git $1 failed'" printf 'fail git %s failed\n' "$1"
fi fi
} }
@ -168,7 +168,7 @@ Available commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide-
if git commit "$@" > /dev/null 2>&1; then if git commit "$@" > /dev/null 2>&1; then
echo 'echo -markup "{Information}Commit succeeded"' echo 'echo -markup "{Information}Commit succeeded"'
else else
echo 'echo -markup "{Error}Commit failed"' echo 'fail Commit failed'
fi fi
exit exit
fi <<-EOF fi <<-EOF
@ -183,7 +183,7 @@ Available commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide-
if git commit -F '$msgfile' --cleanup=strip $* > /dev/null; then if git commit -F '$msgfile' --cleanup=strip $* > /dev/null; then
printf %s 'evaluate-commands -client $kak_client echo -markup %{{Information}Commit succeeded}; delete-buffer' printf %s 'evaluate-commands -client $kak_client echo -markup %{{Information}Commit succeeded}; delete-buffer'
else else
printf %s 'evaluate-commands -client $kak_client echo -markup %{{Error}Commit failed}' printf 'evaluate-commands -client %s fail Commit failed\n' "$kak_client"
fi fi
} }" } }"
} }
@ -227,7 +227,7 @@ Available commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide-
run_git_cmd "$@" run_git_cmd "$@"
;; ;;
*) *)
printf %s "echo -markup %{{Error}unknown git command '$1'}" printf "fail unknown git command '%s'\n" "$1"
exit exit
;; ;;
esac esac

View File

@ -11,7 +11,7 @@ declare-option -hidden int lint_warning_count
define-command lint -docstring 'Parse the current buffer with a linter' %{ define-command lint -docstring 'Parse the current buffer with a linter' %{
evaluate-commands %sh{ evaluate-commands %sh{
if [ -z "${kak_opt_lintcmd}" ]; then if [ -z "${kak_opt_lintcmd}" ]; then
printf %s\\n 'echo -markup {Error}The `lintcmd` option is not set' echo 'fail The `lintcmd` option is not set'
exit 1 exit 1
fi fi
@ -139,7 +139,7 @@ define-command lint-next-error -docstring "Jump to the next line that contains a
if [ -n "${range}" ]; then if [ -n "${range}" ]; then
printf 'select %s\n' "${range}" printf 'select %s\n' "${range}"
else else
printf 'echo -markup "{Error}no lint diagnostics"\n' echo 'fail no lint diagnostics'
fi fi
} }
} }
@ -167,7 +167,7 @@ define-command lint-previous-error -docstring "Jump to the previous line that co
range="${range:-${1%%|*}}" range="${range:-${1%%|*}}"
printf 'select %s\n' "${range}" printf 'select %s\n' "${range}"
else else
printf 'echo -markup "{Error}no lint diagnostics"\n' echo 'fail no lint diagnostics'
fi fi
} }
} }

View File

@ -45,16 +45,11 @@ define-command -hidden -params 2..3 man-impl %{ evaluate-commands %sh{
set-option buffer filetype man set-option buffer filetype man
set-option window manpage $buffer_name $* set-option window manpage $buffer_name $*
" "
elif [ "${retval}" -eq 16 ]; then
printf %s\\n "
echo -markup %{{Error}$(cat $manerr)}
nop %sh{ rm ${colout}; rm ${manerr} }
"
else else
printf %s\\n " printf '
fail $(cat $manerr) fail %%{%s}
nop %sh{ rm ${colout}; rm ${manerr} } nop %%sh{ rm "%s"; rm "%s" }
" ' "$(cat "$manerr")" "${colout}" "${manerr}"
fi fi
} } } }

View File

@ -56,7 +56,7 @@ define-command -params ..1 -docstring %{
;; ;;
'') line_num=$((line_num + 1));; '') line_num=$((line_num + 1));;
\*) ;; \*) ;;
*) printf 'echo -markup %%{{Error}%s}\n' "${line}" | kak -p "${kak_session}";; *) printf 'fail %s\n' "${line}" | kak -p "${kak_session}";;
esac esac
done done
printf 'set-option "buffer=%s" spell_regions %s' "${kak_bufname}" "${regions}" \ printf 'set-option "buffer=%s" spell_regions %s' "${kak_bufname}" "${regions}" \

View File

@ -12,7 +12,7 @@ declare-option -docstring "tmux pane id in which the REPL is running" str tmux_r
define-command -hidden -params 1..2 tmux-repl-impl %{ define-command -hidden -params 1..2 tmux-repl-impl %{
evaluate-commands %sh{ evaluate-commands %sh{
if [ -z "$TMUX" ]; then if [ -z "$TMUX" ]; then
echo "echo -markup '{Error}This command is only available in a tmux session'" echo 'fail This command is only available in a tmux session'
exit exit
fi fi
tmux_args="$1" tmux_args="$1"
@ -49,7 +49,7 @@ define-command -hidden tmux-send-text -params 0..1 -docstring "tmux-send-text [t
define-command -hidden tmux-repl-disabled %{ evaluate-commands %sh{ define-command -hidden tmux-repl-disabled %{ evaluate-commands %sh{
VERSION_TMUX=$(tmux -V) VERSION_TMUX=$(tmux -V)
printf %s "echo -markup %{{Error}The version of tmux is too old: got ${VERSION_TMUX}, expected >= 2.x}" printf 'fail The version of tmux is too old: got %s, expected >= 2.x\n' "${VERSION_TMUX}"
} } } }
evaluate-commands %sh{ evaluate-commands %sh{

View File

@ -11,7 +11,7 @@ All optional parameters are forwarded to the new window} \
-shell-completion \ -shell-completion \
x11-repl %{ evaluate-commands %sh{ x11-repl %{ evaluate-commands %sh{
if [ -z "${kak_opt_termcmd}" ]; then if [ -z "${kak_opt_termcmd}" ]; then
echo "echo -markup '{Error}termcmd option is not set'" echo 'fail termcmd option is not set'
exit exit
fi fi
if [ $# -eq 0 ]; then cmd="${SHELL:-sh}"; else cmd="$@"; fi if [ $# -eq 0 ]; then cmd="${SHELL:-sh}"; else cmd="$@"; fi