1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-22 05:03:56 +03:00

Merge remote-tracking branch 'yoshiyoshyosh/spell'

This commit is contained in:
Maxime Coste 2024-10-22 08:19:30 +11:00
commit ea756d5971

View File

@ -87,58 +87,62 @@ define-command spell-clear %{
unset-option buffer spell_regions unset-option buffer spell_regions
} }
define-command spell-next %{ evaluate-commands %sh{ define-command spell-rel-jump -hidden -params 0..1 %{ evaluate-commands %sh{
anchor_line="${kak_selection_desc%%.*}" spell_first="${kak_opt_spell_regions%%|*}"
anchor_col="${kak_selection_desc%%,*}" spell_first="${spell_first#* }"
anchor_col="${anchor_col##*.}" spell_last="${kak_opt_spell_regions##* }"
spell_last="${spell_last%|*}"
start_first="${kak_opt_spell_regions%%|*}"
start_first="${start_first#* }"
# Make sure properly formatted selection descriptions are in `%opt{spell_regions}` # Make sure properly formatted selection descriptions are in `%opt{spell_regions}`
if ! printf %s "${start_first}" | grep -qE '^[0-9]+\.[0-9]+,[0-9]+\.[0-9]+$'; then if ! printf %s "${spell_first}" | grep -qE '^[0-9]+\.[0-9]+,[0-9]+\.[0-9]+$'; then
exit exit
fi fi
printf %s "${kak_opt_spell_regions#* }" | awk -v start_first="${start_first}" \ get_prev=0
-v anchor_line="${anchor_line}" \ if [ "$1" = "-rev" ]; then
-v anchor_col="${anchor_col}" ' get_prev=1
BEGIN { elif [ -n "$1" ]; then
anchor_line = int(anchor_line) echo "fail -- Unrecognised parameter $(kakquote "$1")"
anchor_col = int(anchor_col) fi
}
{ printf %s "${kak_opt_spell_regions#* }" | \
for (i = 1; i <= NF; i++) { awk -v spell_first="${spell_first}" -v spell_last="${spell_last}" \
sel = $i -v get_prev="${get_prev}" -F '[.,|]' -v RS=" " '
sub(/\|.+$/, "", sel) BEGIN {
split(ENVIRON["kak_selection_desc"], sel)
start_line = sel cursor_row = sel[3]
sub(/\..+$/, "", start_line) cursor_col = sel[4]
start_line = int(start_line) # reverse order so cursor can be at beginning for spell-prev
split(spell_last, tmp)
start_col = sel spell_last = tmp[3] "." tmp[4] "," tmp[1] "." tmp[2]
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) # $1 - $4 is candidate row.col,row.col
target_sel = start_first check_row = $1 > cursor_row
check_col = $1 == cursor_row && (get_prev ? $2 >= cursor_col : $2 > cursor_col)
printf "select %s\n", target_sel if (check_row || check_col) {
}' next_spell = $1 "." $2 "," $3 "." $4
exit
}
prev_spell = $3 "." $4 "," $1 "." $2
}
END {
target_spell = get_prev ? prev_spell : next_spell
if (!target_spell)
target_spell = get_prev ? spell_last : spell_first
printf "select %s\n", target_spell
}
'
} } } }
define-command spell-next %{ spell-rel-jump }
define-command spell-prev %{ spell-rel-jump -rev }
define-command \ define-command \
-docstring "Suggest replacement words for the current selection, against the last language used by the spell-check command" \ -docstring "Suggest replacement words for the current selection, against the last language used by the spell-check command" \
spell-replace %{ spell-replace %{