1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-27 02:23:26 +03:00

Merge remote-tracking branch 'lenormf/spell-lang'

This commit is contained in:
Maxime Coste 2019-11-11 21:51:57 +11:00
commit d2d0e629fa
2 changed files with 28 additions and 16 deletions

View File

@ -34,6 +34,7 @@ define-command -hidden modeline-parse-impl %{
ft|filetype) tr="filetype ${value}";; ft|filetype) tr="filetype ${value}";;
bomb) tr="BOM utf8";; bomb) tr="BOM utf8";;
nobomb) tr="BOM none";; nobomb) tr="BOM none";;
spelllang|spl) tr="spell_lang ${value%%,*}";;
*) printf %s\\n "echo -debug 'Unsupported vim variable: ${key}'";; *) printf %s\\n "echo -debug 'Unsupported vim variable: ${key}'";;
esac esac
@ -46,7 +47,7 @@ define-command -hidden modeline-parse-impl %{
readonly value="$2" readonly value="$2"
case "${key}" in case "${key}" in
scrolloff|tabstop|indentwidth|autowrap_column|eolformat|filetype|BOM);; scrolloff|tabstop|indentwidth|autowrap_column|eolformat|filetype|BOM|spell_lang);;
*) printf %s\\n "echo -debug 'Unsupported kakoune variable: ${key}'" *) printf %s\\n "echo -debug 'Unsupported kakoune variable: ${key}'"
return;; return;;
esac esac

View File

@ -1,14 +1,17 @@
declare-option -hidden range-specs spell_regions declare-option -hidden range-specs spell_regions
declare-option -hidden str spell_lang declare-option -hidden str spell_last_lang
declare-option -hidden str spell_tmp_file declare-option -hidden str spell_tmp_file
define-command -params ..1 \ declare-option -docstring "default language to use when none is passed to the spell-check command" str spell_lang
-docstring %{spell [<language>]: spell check the current buffer
The first optional argument is the language against which the check will be performed define-command -params ..1 -docstring %{
Formats of language supported: spell [<language>]: spell check the current buffer
- ISO language code, e.g. 'en'
- language code above followed by a dash or underscore with an ISO country code, e.g. 'en-US'} \ The first optional argument is the language against which the check will be performed (overrides `spell_lang`)
spell %{ Formats of language supported:
- ISO language code, e.g. 'en'
- 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' } try %{ add-highlighter window/ ranges 'spell_regions' }
evaluate-commands %sh{ evaluate-commands %sh{
file=$(mktemp -d "${TMPDIR:-/tmp}"/kak-spell.XXXXXXXX)/buffer file=$(mktemp -d "${TMPDIR:-/tmp}"/kak-spell.XXXXXXXX)/buffer
@ -16,15 +19,21 @@ Formats of language supported:
printf 'set-option buffer spell_tmp_file %s\n' "${file}" printf 'set-option buffer spell_tmp_file %s\n' "${file}"
} }
evaluate-commands %sh{ evaluate-commands %sh{
if [ $# -ge 1 ]; then use_lang() {
if [ ${#1} -ne 2 ] && [ ${#1} -ne 5 ]; then if ! printf %s "$1" | grep -qE '^[a-z]{2,3}([_-][A-Z]{2})?$'; then
echo "echo -markup '{Error}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")" rm -rf "$(dirname "$kak_opt_spell_tmp_file")"
exit 1 exit 1
else else
options="-l '$1'" options="-l '$1'"
printf 'set-option buffer spell_lang %s\n' "$1" printf 'set-option buffer spell_last_lang %s\n' "$1"
fi fi
}
if [ $# -ge 1 ]; then
use_lang "$1"
elif [ -n "${kak_opt_spell_lang}" ]; then
use_lang "${kak_opt_spell_lang}"
fi fi
{ {
@ -107,9 +116,11 @@ define-command spell-next %{ evaluate-commands %sh{
fi fi
} } } }
define-command spell-replace %{ evaluate-commands %sh{ define-command \
if [ -n "$kak_opt_spell_lang" ]; then -docstring "Suggest replacement words for the current selection, against the last language used by the spell-check command" \
options="-l '$kak_opt_spell_lang'" spell-replace %{ evaluate-commands %sh{
if [ -n "$kak_opt_spell_last_lang" ]; then
options="-l '$kak_opt_spell_last_lang'"
fi fi
suggestions=$(printf %s "$kak_selection" | eval "aspell -a $options" | grep '^&' | cut -d: -f2) suggestions=$(printf %s "$kak_selection" | eval "aspell -a $options" | grep '^&' | cut -d: -f2)
menu=$(printf %s "${suggestions#?}" | awk -F', ' ' menu=$(printf %s "${suggestions#?}" | awk -F', ' '