Tweak spell.kak, embrace printf and refactor a bit

This commit is contained in:
Maxime Coste 2016-10-06 13:32:51 +01:00
parent 92b4046ba8
commit f67d5076c4

View File

@ -5,8 +5,8 @@ def -params ..1 spell -docstring "Check spelling of the current buffer with aspe
try %{ addhl ranges 'spell_regions' } try %{ addhl ranges 'spell_regions' }
%sh{ %sh{
file=$(mktemp -d -t kak-spell.XXXXXXXX)/buffer file=$(mktemp -d -t kak-spell.XXXXXXXX)/buffer
printf %s\\n "eval -no-hooks write ${file}" printf 'eval -no-hooks write %s\n' "${file}"
printf %s\\n "set buffer spell_tmp_file ${file}" printf 'set buffer spell_tmp_file %s\n' "${file}"
} }
%sh{ %sh{
if [ $# -ge 1 ]; then if [ $# -ge 1 ]; then
@ -18,13 +18,13 @@ def -params ..1 spell -docstring "Check spelling of the current buffer with aspe
options="-l $1" options="-l $1"
fi fi
fi fi
sed -i 's/^/^/' $kak_opt_spell_tmp_file sed 's/^/^/' < $kak_opt_spell_tmp_file | aspell -a $options 2>&1 | tee /tmp/spell-out | {
aspell -a $options < $kak_opt_spell_tmp_file 2>&1 | {
line_num=1 line_num=1
regions=$kak_timestamp regions=$kak_timestamp
read line # drop the identification message
while read line; do while read line; do
case "$line" in case "$line" in
\&*|'#'*) [\#\&]*)
if expr "$line" : '^&' >/dev/null; then if expr "$line" : '^&' >/dev/null; then
begin=$(printf %s\\n "$line" | cut -d ' ' -f 4 | sed 's/:$//') begin=$(printf %s\\n "$line" | cut -d ' ' -f 4 | sed 's/:$//')
else else
@ -35,10 +35,11 @@ def -params ..1 spell -docstring "Check spelling of the current buffer with aspe
regions="$regions:$line_num.$begin,$line_num.$end|Error" regions="$regions:$line_num.$begin,$line_num.$end|Error"
;; ;;
'') line_num=$((line_num + 1));; '') line_num=$((line_num + 1));;
*) printf %s\\n "echo -color Error %{$line}";; \*) ;;
*) printf 'echo -color Error %%{%s}\n' "${line}";;
esac esac
done done
printf %s\\n "set buffer spell_regions %{$regions}" printf 'set buffer spell_regions %%{%s}' "${regions}"
} }
rm -r $(dirname $kak_opt_spell_tmp_file) rm -r $(dirname $kak_opt_spell_tmp_file)
} }