diff options
author | Frank Seifferth <frankseifferth@posteo.net> | 2021-10-07 15:33:36 +0200 |
---|---|---|
committer | Frank Seifferth <frankseifferth@posteo.net> | 2021-10-07 15:33:36 +0200 |
commit | 5109c41cf37c4ac2868491a6cad7faeae96973e5 (patch) | |
tree | b620cfb28dddaf6694aad3f28976c2b514edfbc0 | |
parent | be1e08c900fe53ebe4dfdc458f93081a4c02ed64 (diff) | |
download | vis-spellcheck-5109c41cf37c4ac2868491a6cad7faeae96973e5.tar.gz |
Use 'vis.win.file.spell_language' rather than 'spellcheck.lang'
There is some discussion on the editorconfig side
about whether a 'spell_language' key could be added
(cf. https://github.com/editorconfig/editorconfig/issues/315,
https://github.com/seifferth/vis-editorconfig/pull/8). This key would
specify the natural language a file is written in and it would then
be up to the editor or plugin doing the spellchecking to respect that
setting and behave accordingly.
Since it is out of the scope of the vis-editorconfig plugin to
implement spellchecking, and since I would like the vis-editorconfig
plugin to work both with and without vis-spellcheck, I suggest
to use 'vis.win.file.spell_language' to store the document
language. With commit 0ee415c in the vis-editorconfig repo
(https://github.com/seifferth/vis-editorconfig), this value is already
set to the appropriate value. This commit adjusts the spellchecking
plugin to use the same global value. I did some testing that suggests
it should work.
There might still be some hickups if 'vis.win.file' does not exist.
This is a non-issue for editorconfig, since editorconfig only works
if 'vis.win.file.path' exists (which configuration is used depends
on the path). The Readme would also need some adjustment.
-rw-r--r-- | spellcheck.lua | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/spellcheck.lua b/spellcheck.lua index abc0f16..1771f7f 100644 --- a/spellcheck.lua +++ b/spellcheck.lua @@ -2,9 +2,16 @@ -- Use of this source code is governed by a MIT license found in the LICENSE file. local spellcheck = {} if os.getenv('LANG') then - spellcheck.lang = os.getenv('LANG'):sub(0, 5) + spellcheck.default_lang = os.getenv('LANG'):sub(0, 5) else - spellcheck.lang = 'en_US' + spellcheck.default_lang = 'en_US' +end +spellcheck.get_lang = function () + if vis.win.file.spell_language then + return vis.win.file.spell_language + else + return spellcheck.default_lang + end end local supress_stdout = ' >/dev/null' local supress_stderr = ' 2>/dev/null' @@ -44,7 +51,7 @@ spellcheck.check_tokens = { -- to a temporary file. See http://lua-users.org/lists/lua-l/2007-10/msg00189.html. -- The returned string consists of each misspell followed by a newline. local function get_typos(range_or_text) - local cmd = spellcheck.list_cmd:format(spellcheck.lang) + local cmd = spellcheck.list_cmd:format(spellcheck.get_lang()) local typos if type(range_or_text) == 'string' then local text = range_or_text @@ -342,7 +349,7 @@ vis:map(vis.modes.NORMAL, '<C-w>w', function() return end - local cmd = spellcheck.cmd:format(spellcheck.lang) + local cmd = spellcheck.cmd:format(spellcheck.get_lang()) local ret, so, se = vis:pipe(win.file, range, cmd) if ret ~= 0 then vis:message('calling ' .. cmd .. ' failed (' .. se .. ')') @@ -419,7 +426,7 @@ vis:map(vis.modes.NORMAL, '<C-w>i', function() end, 'Ignore misspelled word') vis:option_register('spelllang', 'string', function(value) - spellcheck.lang = value + vis.win.file.spell_language = value vis:info('Spellchecking language is now ' .. value) -- force new highlight for full viewport last_viewport = nil |