diff --git a/rc/tools/spell.kak b/rc/tools/spell.kak index 135b53df..db8e9daf 100644 --- a/rc/tools/spell.kak +++ b/rc/tools/spell.kak @@ -142,20 +142,27 @@ define-command spell-next %{ evaluate-commands %sh{ define-command \ -docstring "Suggest replacement words for the current selection, against the last language used by the spell-check command" \ - spell-replace %{ evaluate-commands %sh{ - options="" - if [ -n "$kak_opt_spell_last_lang" ]; then - options="-l '$kak_opt_spell_last_lang'" - fi - suggestions=$(printf %s "$kak_selection" | eval "aspell -a $options" | grep '^&' | cut -d: -f2) - menu=$(printf %s "${suggestions#?}" | awk -F', ' ' - { - for (i=1; i<=NF; i++) - printf "%s", "%{"$i"}" "%{execute-keys -itersel %{c"$i"be}}" + spell-replace %{ + prompt \ + -init %val{selection} \ + -shell-script-candidates %{ + options="" + if [ -n "$kak_opt_spell_last_lang" ]; then + options="-l '$kak_opt_spell_last_lang'" + fi + printf %s "$kak_selection" | + eval "aspell -a $options" | + kak -f '^&d%s^[^:]*: d%s, c' + } \ + "Replace with: " \ + %{ + evaluate-commands -save-regs a %{ + set-register a %val{text} + execute-keys c a + } } - ') - printf 'try %%{ menu -auto-single %s }' "${menu}" -} } +} + define-command -params 0.. \ -docstring "Add the current selection to the dictionary" \