dotfiles/.config/kak/autoload/spell.kak

52 lines
1.7 KiB
Text

provide-module spell %~
define-command -override -hidden true nop
define-command -override -hidden false fail
declare-option -hidden bool autospell_enabled false
define-command -docstring %{
Enable autospell. Autospell refreshes spellchecks and hides spelling in insert mode.
} autospell-enable %{
set-option window autospell_enabled true
try %{
spell
hook -group auto-spell window ModeChange (push|pop):.*insert %{
try %{ spell-clear }
}
hook -group auto-spell window NormalIdle .* %{ try spell }
} catch %{
fail "Couldn't enable autospell!"
}
}
define-command -docstring %{
Disable autospell. Autospell refreshes spellchecks and hides spelling in insert mode.
} autospell-disable %{
set-option window autospell_enabled false
try spell-clear
remove-hooks window auto-spell
}
define-command autospell-toggle %{
try %{
%opt{autospell_enabled}
autospell-disable
} catch %{
autospell-enable
}
}
# keybindings
declare-user-mode spell
map -docstring 'autospell toggle' global spell t ': autospell-toggle<ret>'
map -docstring 'show spell' global spell s ': spell<ret>'
map -docstring 'spell next' global spell i ': spell-next<ret>'
map -docstring 'spell prev' global spell m ': spell-prev<ret>'
map -docstring 'spell clear' global spell c ': spell-clear<ret>'
map -docstring 'spell add' global spell a ': spell-add<ret>'
map -docstring 'spell replace' global spell r ': spell-replace<ret>'
map -docstring 'spelling' global user s ': enter-user-mode spell<ret>'
~