diff --git a/.config/kak/autoload/ltex-dict.kak b/.config/kak/autoload/ltex-dict.kak index 813d8310..71b73d8a 100644 --- a/.config/kak/autoload/ltex-dict.kak +++ b/.config/kak/autoload/ltex-dict.kak @@ -1,16 +1,44 @@ +# Author: Daniel Fichtinger +# License: ISC + +# How it works: +# the only way to specify a dictionary for ltex-ls is through +# the LSP configuration. in kak-lsp, this is in toml format and +# always set as an option from Kakoune. +# +# Live-reloading is supported, meaning that if we update the configuration +# mid-session, ltex-ls will load the new dictionary. However, we have to set +# the _full_ config each time +# +# So we define a command that reads a line-delimited list of words from our dictionary file +# It uses kak -f to format them into a toml array format s.t. +# foo\nbar\n becomes +# ["foo", "bar"] +# +# Then we filter the current lsp_servers option, and replace the \[.*\] occurrences +# _only_ on the dictionary line, to update the dict array to our new list. +# +# If we run this command hooked to ltex-ls startup, then our custom dictionary +# will be loaded. Now we can easily define a command to add a word to the dictionary -- all it has to do is append the word to the end of the dict file, the call ltex-dict-set provide-module ltex-dict %~ - declare-option str ltex_dict_path %exp{%val{config}/ltex-dict.txt} - define-command ltex-dict-set %{ + declare-option -docstring %{ + Path to the custom dictionary. Must be a textfile with newline delimited words. + + Default: %exp{%val{config}/ltex-dict.txt} + } str ltex_dict_path %exp{%val{config}/ltex-dict.txt} + define-command -hidden ltex-dict-set %{ set-option buffer lsp_servers %sh{ - echo >/tmp/test.txt list="$(cat "$kak_opt_ltex_dict_path" | kak -f '%Zbi\"a\"zr,x_i[a]')" - notify-send "$list" - echo "$kak_opt_lsp_servers" | sed "/^\s*dictionary =/ s/\[\]/$list/g" - echo "$kak_opt_lsp_servers" | sed "/^\s*dictionary =/ s/\[\]/REPLACED/g" >/tmp/test.txt + echo "$kak_opt_lsp_servers" | sed "/^\s*dictionary =/ s/\[.*\]/$list/g" } } - define-command ltex-add %{ + define-command -docstring %{ + Adds the current word word to the dictionary. + + If the selection size is 1, then the word the cursor is on is added. + If the selection is larger, its contents are added verbatim. + } ltex-add %{ execute-keys -draft %sh{ if [ "$kak_selection_length" = 1 ]; then printf 'bw_{ cat; echo; } | tee -a %s\n' "$kak_opt_ltex_dict_path" diff --git a/.config/kak/ltex-dict.txt b/.config/kak/ltex-dict.txt index b2240848..aa8f5324 100644 --- a/.config/kak/ltex-dict.txt +++ b/.config/kak/ltex-dict.txt @@ -1,3 +1,4 @@ foobartest apple SonarAuth +Fichtinger