rc spell: Rewrite :spell-next
in Awk
This commit is contained in:
parent
e9e15e6a44
commit
4eac927a01
|
@ -96,40 +96,40 @@ define-command spell-next %{ evaluate-commands %sh{
|
||||||
start_first="${kak_opt_spell_regions%%|*}"
|
start_first="${kak_opt_spell_regions%%|*}"
|
||||||
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
|
|
||||||
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 ! printf %s "${start_first}" | grep -qE '^[0-9]+\.[0-9]+,[0-9]+\.[0-9]+$'; then
|
if ! printf %s "${start_first}" | grep -qE '^[0-9]+\.[0-9]+,[0-9]+\.[0-9]+$'; then
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
next_word_desc=$(find_next_word_desc "${kak_opt_spell_regions}")
|
printf %s "${kak_opt_spell_regions#* }" | awk -v anchor_line="${anchor_line}" \
|
||||||
if [ -n "${next_word_desc}" ]; then
|
-v anchor_col="${anchor_col}" '
|
||||||
printf %s\\n "${next_word_desc}"
|
BEGIN {
|
||||||
else
|
anchor_line = int(anchor_line)
|
||||||
printf 'select %s\n' "${start_first}"
|
anchor_col = int(anchor_col)
|
||||||
fi
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
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
|
||||||
|
|
||||||
|
printf "select %s\n", sel
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}'
|
||||||
} }
|
} }
|
||||||
|
|
||||||
define-command \
|
define-command \
|
||||||
|
|
Loading…
Reference in New Issue
Block a user