From 246735520f0810c9162b047f7df32c43ed5105b1 Mon Sep 17 00:00:00 2001 From: Jan-Jaap Korpershoek Date: Wed, 15 Apr 2020 13:51:46 +0200 Subject: [PATCH 1/2] Add spell-add command --- rc/tools/spell.kak | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/rc/tools/spell.kak b/rc/tools/spell.kak index b4e7a0e7..b6d030aa 100644 --- a/rc/tools/spell.kak +++ b/rc/tools/spell.kak @@ -148,3 +148,21 @@ define-command \ ') printf 'try %%{ menu -auto-single %s }' "${menu}" } } + +define-command -params 0.. \ + -docstring "Add the current selection to the dictionary" \ + spell-add %{ nop %sh{ + if [ -n "$kak_opt_spell_last_lang" ]; then + options="-l '$kak_opt_spell_last_lang'" + fi + if [ $# -eq 0 ]; then + # use selections + eval set -- "$kak_quoted_selections" + fi + words="" + while [ $# -gt 0 ]; do + words="$words"$(printf '*%s\\n#\\n' "$1") + shift + done + printf %b\\n "$words" | eval "aspell -a $options" +}} From 063a702bf4b8c441c22d73588edafce7bf7437e9 Mon Sep 17 00:00:00 2001 From: Jan-Jaap Korpershoek Date: Mon, 27 Apr 2020 12:28:29 +0200 Subject: [PATCH 2/2] Add error handling Rewrite line by line to make escaping easier --- rc/tools/spell.kak | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/rc/tools/spell.kak b/rc/tools/spell.kak index b6d030aa..d062f3e4 100644 --- a/rc/tools/spell.kak +++ b/rc/tools/spell.kak @@ -151,7 +151,7 @@ define-command \ define-command -params 0.. \ -docstring "Add the current selection to the dictionary" \ - spell-add %{ nop %sh{ + spell-add %{ evaluate-commands %sh{ if [ -n "$kak_opt_spell_last_lang" ]; then options="-l '$kak_opt_spell_last_lang'" fi @@ -159,10 +159,12 @@ define-command -params 0.. \ # use selections eval set -- "$kak_quoted_selections" fi - words="" while [ $# -gt 0 ]; do - words="$words"$(printf '*%s\\n#\\n' "$1") + word="$1" + if ! printf '*%s\n#\n' "${word}" | eval "aspell -a $options" >/dev/null; then + printf 'fail "Unable to add word: %s"' "$(printf %s "${word}" | sed 's/"/&&/g')" + exit 1 + fi shift done - printf %b\\n "$words" | eval "aspell -a $options" }}