Merge remote-tracking branch 'lenormf/fix-spell-next'

This commit is contained in:
Maxime Coste 2020-05-30 09:22:06 +10:00
commit 0b56c777c0

View File

@ -93,44 +93,51 @@ define-command spell-next %{ evaluate-commands %sh{
anchor_col="${kak_selection_desc%%,*}" anchor_col="${kak_selection_desc%%,*}"
anchor_col="${anchor_col##*.}" anchor_col="${anchor_col##*.}"
start_first="${kak_opt_spell_regions#* }" start_first="${kak_opt_spell_regions%%|*}"
start_first="${start_first%%|*}" start_first="${start_first#* }"
start_first="${start_first#\'}"
find_next_word_desc() { # Make sure properly formatted selection descriptions are in `%opt{spell_regions}`
## XXX: the `spell` command adds sorted selection descriptions to the range if ! printf %s "${start_first}" | grep -qE '^[0-9]+\.[0-9]+,[0-9]+\.[0-9]+$'; then
printf %s\\n "${1}" \
| sed -e "s/'//g" -e 's/^[0-9]* //' -e 's/|[^ ]*//g' \
| tr ' ' '\n' \
| while IFS=, read -r start end; do
start_line="${start%.*}"
start_col="${start#*.}"
end_line="${end%.*}"
end_col="${end#*.}"
if [ "${start_line}" -lt "${anchor_line}" ]; then
continue
elif [ "${start_line}" -eq "${anchor_line}" ] \
&& [ "${start_col}" -le "${anchor_col}" ]; then
continue
fi
printf 'select %s,%s\n' "${start}" "${end}"
break
done
}
# no selection descriptions are in `spell_regions`
if ! expr "${start_first}" : '[0-9][0-9]*\.[0-9][0-9]*,[0-9][0-9]*\.[0-9]' >/dev/null; then
exit exit
fi fi
next_word_desc=$(find_next_word_desc "${kak_opt_spell_regions}") printf %s "${kak_opt_spell_regions#* }" | awk -v start_first="${start_first}" \
if [ -n "${next_word_desc}" ]; then -v anchor_line="${anchor_line}" \
printf %s\\n "${next_word_desc}" -v anchor_col="${anchor_col}" '
else BEGIN {
printf 'select %s\n' "${start_first}" anchor_line = int(anchor_line)
fi anchor_col = int(anchor_col)
}
{
for (i = 1; i <= NF; i++) {
sel = $i
sub(/\|.+$/, "", sel)
start_line = sel
sub(/\..+$/, "", start_line)
start_line = int(start_line)
start_col = sel
sub(/,.+$/, "", start_col)
sub(/^.+\./, "", start_col)
start_col = int(start_col)
if (start_line < anchor_line \
|| (start_line == anchor_line && start_col <= anchor_col))
continue
target_sel = sel
break
}
}
END {
if (!target_sel)
target_sel = start_first
printf "select %s\n", target_sel
}'
} } } }
define-command \ define-command \