Update spell.kak to use command/response fifo
This commit is contained in:
parent
3d7fb8ddbc
commit
2b68b6737c
|
@ -1,6 +1,5 @@
|
||||||
declare-option -hidden range-specs spell_regions
|
declare-option -hidden range-specs spell_regions
|
||||||
declare-option -hidden str spell_last_lang
|
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
|
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'
|
- language code above followed by a dash or underscore with an ISO country code, e.g. 'en-US'
|
||||||
} spell %{
|
} spell %{
|
||||||
try %{ add-highlighter window/ ranges 'spell_regions' }
|
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{
|
evaluate-commands %sh{
|
||||||
use_lang() {
|
use_lang() {
|
||||||
if ! printf %s "$1" | grep -qE '^[a-z]{2,3}([_-][A-Z]{2})?$'; then
|
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)'"
|
echo "fail 'Invalid language code (examples of expected format: en, en_US, en-US)'"
|
||||||
rm -rf "$(dirname "$kak_opt_spell_tmp_file")"
|
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
options="-l '$1'"
|
options="-l '$1'"
|
||||||
|
@ -36,8 +29,10 @@ define-command -params ..1 -docstring %{
|
||||||
use_lang "${kak_opt_spell_lang}"
|
use_lang "${kak_opt_spell_lang}"
|
||||||
fi
|
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 {
|
BEGIN {
|
||||||
line_num = 1
|
line_num = 1
|
||||||
regions = ENVIRON["kak_timestamp"]
|
regions = ENVIRON["kak_timestamp"]
|
||||||
|
@ -83,8 +78,7 @@ define-command -params ..1 -docstring %{
|
||||||
close(server_command)
|
close(server_command)
|
||||||
}
|
}
|
||||||
'
|
'
|
||||||
rm -rf $(dirname "$kak_opt_spell_tmp_file")
|
} <$kak_response_fifo >/dev/null 2>&1 &
|
||||||
} </dev/null >/dev/null 2>&1 &
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user