diff options
author | rxi <rxi@users.noreply.github.com> | 2020-04-23 19:03:07 +0100 |
---|---|---|
committer | rxi <rxi@users.noreply.github.com> | 2020-04-23 19:03:22 +0100 |
commit | b19d319e5a32410e7e1fca2c3f072825691d7904 (patch) | |
tree | 7321933478dff6184e2f25b7cf1ccfc55100c9ab | |
parent | 8e321f68aba76da51f1ea2de7fef3588ddc763ad (diff) | |
download | lite-xl-plugins-b19d319e5a32410e7e1fca2c3f072825691d7904.tar.gz lite-xl-plugins-b19d319e5a32410e7e1fca2c3f072825691d7904.zip |
Simplified spellcheck dictionary loading
-rw-r--r-- | spellcheck.lua | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/spellcheck.lua b/spellcheck.lua index 0c5aca9..bb6f835 100644 --- a/spellcheck.lua +++ b/spellcheck.lua @@ -7,27 +7,22 @@ local DocView = require "core.docview" config.spellcheck_files = { "%.txt$", "%.md$", "%.markdown$" } config.dictionary_file = "/usr/share/dict/words" -local inited = false local words -local function init_words() - if inited then return end - inited = true - core.add_thread(function() - local t = {} - local i = 0 - for line in io.lines(config.dictionary_file) do - for word in line:gmatch("%a+") do - t[word:lower()] = true - end - i = i + 1 - if i % 1000 == 0 then coroutine.yield() end +core.add_thread(function() + local t = {} + local i = 0 + for line in io.lines(config.dictionary_file) do + for word in line:gmatch("%a+") do + t[word:lower()] = true end - core.log_quiet("Finished loading dictionary file: %s", config.dictionary_file) - words = t - core.redraw = true - end) -end + i = i + 1 + if i % 1000 == 0 then coroutine.yield() end + end + words = t + core.redraw = true + core.log_quiet("Finished loading dictionary file: \"%s\"", config.dictionary_file) +end) local function matches_any(filename, ptns) @@ -42,7 +37,6 @@ local draw_line_text = DocView.draw_line_text function DocView:draw_line_text(idx, x, y) draw_line_text(self, idx, x, y) - init_words() if not words or not matches_any(self.doc.filename or "", config.spellcheck_files) then return |