From 2b68b6737c6b010836637e3fe57bda66a12555ad Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 19 Jun 2021 11:21:50 +1000 Subject: [PATCH] Update spell.kak to use command/response fifo --- rc/tools/spell.kak | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/rc/tools/spell.kak b/rc/tools/spell.kak index 121fe3dd..49bee50c 100644 --- a/rc/tools/spell.kak +++ b/rc/tools/spell.kak @@ -1,6 +1,5 @@ declare-option -hidden range-specs spell_regions declare-option -hidden str spell_last_lang -declare-option -hidden str spell_tmp_file declare-option -docstring "default language to use when none is passed to the spell-check command" str spell_lang @@ -13,16 +12,10 @@ define-command -params ..1 -docstring %{ - language code above followed by a dash or underscore with an ISO country code, e.g. 'en-US' } spell %{ try %{ add-highlighter window/ ranges 'spell_regions' } - evaluate-commands %sh{ - file=$(mktemp -d "${TMPDIR:-/tmp}"/kak-spell.XXXXXXXX)/buffer - printf 'eval -no-hooks write -sync %s\n' "${file}" - printf 'set-option buffer spell_tmp_file %s\n' "${file}" - } evaluate-commands %sh{ use_lang() { if ! printf %s "$1" | grep -qE '^[a-z]{2,3}([_-][A-Z]{2})?$'; then echo "fail 'Invalid language code (examples of expected format: en, en_US, en-US)'" - rm -rf "$(dirname "$kak_opt_spell_tmp_file")" exit 1 else options="-l '$1'" @@ -36,8 +29,10 @@ define-command -params ..1 -docstring %{ use_lang "${kak_opt_spell_lang}" fi + printf 'eval -no-hooks write %s\n' "${kak_response_fifo}" > $kak_command_fifo + { - sed 's/^/^/' "$kak_opt_spell_tmp_file" | eval "aspell --byte-offsets -a $options" 2>&1 | awk ' + sed 's/^/^/' | eval "aspell --byte-offsets -a $options" 2>&1 | awk ' BEGIN { line_num = 1 regions = ENVIRON["kak_timestamp"] @@ -83,8 +78,7 @@ define-command -params ..1 -docstring %{ close(server_command) } ' - rm -rf $(dirname "$kak_opt_spell_tmp_file") - } /dev/null 2>&1 & + } <$kak_response_fifo >/dev/null 2>&1 & } }