aboutsummaryrefslogtreecommitdiff
path: root/spellcheck.lua
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2026-09-23 09:57:25 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2026-09-23 09:57:25 +0200
commiteaa9a627875f6eed46f8ee823fd4d7cc92eefb1e (patch)
tree379b0ccae40bcda77cda15c3ab0b1d3fb4b0f2e3 /spellcheck.lua
parentc4844507850a13202f9483bdbb2b2f378c54e4ce (diff)
downloadvis-spellcheck-eaa9a627875f6eed46f8ee823fd4d7cc92eefb1e.tar.gz
vis-spellcheck-eaa9a627875f6eed46f8ee823fd4d7cc92eefb1e.zip
run make format
Diffstat (limited to 'spellcheck.lua')
-rw-r--r--spellcheck.lua63
1 files changed, 32 insertions, 31 deletions
diff --git a/spellcheck.lua b/spellcheck.lua
index 7f725c1..a68bd79 100644
--- a/spellcheck.lua
+++ b/spellcheck.lua
@@ -3,35 +3,33 @@
local vis = _G.vis
local spellcheck = {}
-spellcheck.default_lang = string.match(
- os.getenv('VIS_SPELLLANG') or os.getenv('LANG') or ''
- , "^%l%l_%u%u"
-) or 'en_US'
+spellcheck.default_lang = string.match(os.getenv('VIS_SPELLLANG') or os.getenv('LANG') or '',
+ '^%l%l_%u%u') or 'en_US'
spellcheck.spelling_autoenable = false
spellcheck.get_lang = function()
- return vis.win and vis.win.file.spelling_language
- or spellcheck.default_lang
+ return vis.win and vis.win.file.spelling_language or spellcheck.default_lang
end
-local which do
- local path = os.getenv("PATH"):gsub(":","/?;") .. "/?"
+local which
+do
+ local path = os.getenv('PATH'):gsub(':', '/?;') .. '/?'
function which(executable)
- return package.searchpath(executable, path, "", "")
+ return package.searchpath(executable, path, '', '')
end
end
-if which("enchant") then
+if which('enchant') then
spellcheck.cmd = 'enchant -d %s -a'
spellcheck.list_cmd = 'enchant -l -d %s'
-elseif which("enchant-2") then
+elseif which('enchant-2') then
spellcheck.cmd = 'enchant-2 -d %s -a'
spellcheck.list_cmd = 'enchant-2 -l -d %s'
-elseif which("aspell") then
+elseif which('aspell') then
spellcheck.cmd = 'aspell pipe -l %s'
spellcheck.list_cmd = 'aspell list -l %s'
-elseif which("hunspell") then
+elseif which('hunspell') then
spellcheck.cmd = 'hunspell -d %s'
spellcheck.list_cmd = 'hunspell -l -d %s'
else
@@ -139,8 +137,8 @@ end
local ignored = {}
-- escapes operators of pattern
-local escape_lua_pattern = function (s)
- return s:gsub("[*$^().?+%%%[%]-]","%%%0")
+local escape_lua_pattern = function(s)
+ return s:gsub('[*$^().?+%%%[%]-]', '%%%0')
end
-- Return an iterator over all not ignored typos and their positions in text.
@@ -154,7 +152,9 @@ local function typo_iter(text, typos, ignored) -- luacheck: ignore ignored
local typo
repeat
typo = unfiltered_iterator(iter_state)
- if not typo then return end
+ if not typo then
+ return
+ end
until not ignored[typo]
local start, finish
@@ -179,9 +179,8 @@ local function typo_iter(text, typos, ignored) -- luacheck: ignore ignored
finish = start + #typo - 1
if text:sub(start, finish) ~= typo then
- vis:info(string.format(
- 'can\'t find typo %s after %d. Please report this bug.',
- typo, index))
+ vis:info(string.format('can\'t find typo %s after %d. Please report this bug.', typo,
+ index))
end
end
end
@@ -200,7 +199,9 @@ vis.events.subscribe(vis.events.WIN_HIGHLIGHT, function(win)
end
-- Be backward compatible with vis < v0.9
local viewport = win.viewport.bytes or win.viewport
- if not viewport then return end
+ if not viewport then
+ return
+ end
local viewport_text = win.file:content(viewport)
local typos
@@ -211,8 +212,7 @@ vis.events.subscribe(vis.events.WIN_HIGHLIGHT, function(win)
end
for start, finish in typo_iter(viewport_text, typos, ignored) do
- win:style(spellcheck.typo_style_id, viewport.start + start - 1,
- viewport.start + finish - 1)
+ win:style(spellcheck.typo_style_id, viewport.start + start - 1, viewport.start + finish - 1)
end
last_viewport = viewport_text
@@ -298,8 +298,7 @@ local enable_spellcheck = function()
return
end
- if not spellcheck.disable_syntax_awareness and vis.win.syntax and
- vis.lexers.load then
+ if not spellcheck.disable_syntax_awareness and vis.win.syntax and vis.lexers.load then
local lexer = vis.lexers.load(vis.win.syntax, nil, true)
if lexer and lexer.lex then
local old_lex_func = lexer.lex
@@ -308,7 +307,9 @@ local enable_spellcheck = function()
-- reset last data to enforce new highlighting
last_data = ''
-- clear token cache to relex the window
- if vis.win.token_cache then vis.win.token_cache = {} end
+ if vis.win.token_cache then
+ vis.win.token_cache = {}
+ end
return
end
end
@@ -338,7 +339,9 @@ local disable_spellcheck = function()
lexer.lex = old_lex_func
wrapped_lex_funcs[vis.win] = nil
-- clear token cache to relex the window
- if vis.win.token_cache then vis.win.token_cache = {} end
+ if vis.win.token_cache then
+ vis.win.token_cache = {}
+ end
else
spellcheck.check_full_viewport[vis.win] = nil
end
@@ -499,12 +502,10 @@ local function set_spelllang_option(value)
end
-- Detect if vis supports the get-callback for option registration
-if not pcall(vis.option_register, vis, 'spelllang', 'string',
- set_spelllang_option, spellcheck.get_lang,
- 'The language used for spellchecking')
-then
+if not pcall(vis.option_register, vis, 'spelllang', 'string', set_spelllang_option,
+ spellcheck.get_lang, 'The language used for spellchecking') then
vis:option_register('spelllang', 'string', set_spelllang_option,
- 'The language used for spellchecking')
+ 'The language used for spellchecking')
end
vis:command_register('spelllang', function()