From f75f484b842daf9f548f26755d7ee3c9b7346eeb Mon Sep 17 00:00:00 2001 From: Tim Allen Date: Mon, 21 Sep 2020 21:07:35 +1000 Subject: [PATCH 1/2] spell.kak: Present spelling suggestions with :prompt Previously, spelling suggestions were presented with the :menu command, requiring the user to cycle through wild and fanciful alternatives to get to the one they wanted. Now, we present suggestions with the :prompt command, which allows the user to type to filter down the list, and also to customise the replacement after they've chose it (perhaps to fix capitalisation or add apostrophe-S). We also use the mispelled word as the initial content of the prompt. That filters out the wildest alternatives by default, and allows the user to edit the original word instead of forcing them to choose from among the suggestions. To get the full list of suggestions, it's easy enough to just backspace until the word you want appears in the list. --- rc/tools/spell.kak | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) 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" \ From 93e5a3b51f81febeadaeb474dd97fd4bb881b787 Mon Sep 17 00:00:00 2001 From: Tim Allen Date: Tue, 22 Sep 2020 01:29:03 +1000 Subject: [PATCH 2/2] spell.kak: Replace "kak -f" with "sed" for efficiency. --- rc/tools/spell.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/tools/spell.kak b/rc/tools/spell.kak index db8e9daf..b9fe5903 100644 --- a/rc/tools/spell.kak +++ b/rc/tools/spell.kak @@ -152,7 +152,7 @@ define-command \ fi printf %s "$kak_selection" | eval "aspell -a $options" | - kak -f '^&d%s^[^:]*: d%s, c' + sed -n -e '/^&/ { s/^[^:]*: //; s/, /\n/g; p }' } \ "Replace with: " \ %{