kakoune/rc/base/spell.kak
Frank LENORMAND f6a2925950 Fix, complete and add docstring documentation to builtin commands
Level out the builtin commands loaded at startup in terms of format and
expressiveness. The following convention was followed:
* commands that take more than one argument have to be described along
  with their parameters prior to the actual documentation, otherwise the
  docstring consists in a capitalized sentence
  e.g. `command <arg1>: do something`
* optional arguments are enclosed in square brackets, to comply with the
  format used for hardcoded commands
  e.g. `cd [<directory>]`
* describe the effects of the command in the documentation string and
  omit implementation details unless they are relevant. Usually command
  names include the name of the tool they use, so they don't need to be
  redundantly mentioned
  e.g. `tmux-new-pane <arguments>: open a new pane`
* document the format the parameters to the commands, or list them if
  they are to be chosen among a list of static values (c.f. `spell.kak`)
2016-10-11 10:26:17 +03:00

53 lines
2.1 KiB
Plaintext

decl -hidden range-faces spell_regions
decl -hidden str spell_tmp_file
def -params ..1 \
-docstring %{spell [<language>]: spell check the current buffer
The first optional argument is the language against which the check will be performed
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 %{ addhl ranges 'spell_regions' }
%sh{
file=$(mktemp -d -t kak-spell.XXXXXXXX)/buffer
printf 'eval -no-hooks write %s\n' "${file}"
printf 'set buffer spell_tmp_file %s\n' "${file}"
}
%sh{
if [ $# -ge 1 ]; then
if [ ${#1} -ne 2 -a ${#1} -ne 5 ]; then
echo 'echo -color Error Invalid language code (examples of expected format: en, en_US, en-US)'
rm -r $(dirname $kak_opt_spell_tmp_file)
exit 1
else
options="-l $1"
fi
fi
sed 's/^/^/' < $kak_opt_spell_tmp_file | aspell -a $options 2>&1 | tee /tmp/spell-out | {
line_num=1
regions=$kak_timestamp
read line # drop the identification message
while read line; do
case "$line" in
[\#\&]*)
if expr "$line" : '^&' >/dev/null; then
begin=$(printf %s\\n "$line" | cut -d ' ' -f 4 | sed 's/:$//')
else
begin=$(printf %s\\n "$line" | cut -d ' ' -f 3)
fi
word=$(printf %s\\n "$line" | cut -d ' ' -f 2)
end=$((begin + ${#word}))
regions="$regions:$line_num.$begin,$line_num.$end|Error"
;;
'') line_num=$((line_num + 1));;
\*) ;;
*) printf 'echo -color Error %%{%s}\n' "${line}";;
esac
done
printf 'set buffer spell_regions %%{%s}' "${regions}"
}
rm -r $(dirname $kak_opt_spell_tmp_file)
}
}