diff options
| author | Nomarian <nomarian@outlook.com> | 2025-10-09 10:26:35 -0400 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-10-12 21:00:36 +0200 |
| commit | 6c1842f86d34d0e9afdea3e445c36091b5bf8246 (patch) | |
| tree | 61dba15ca6594d693a4a881ddc8843b40e57d2f8 | |
| parent | 54b736e479f29a6e95b2fe6a865800265f0e9b31 (diff) | |
| download | vis-spellcheck-6c1842f86d34d0e9afdea3e445c36091b5bf8246.tar.gz vis-spellcheck-6c1842f86d34d0e9afdea3e445c36091b5bf8246.zip | |
No forking when trying to check for spellchecking utilities in $PATH (use package.searchpath instead)
| -rw-r--r-- | spellcheck.lua | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/spellcheck.lua b/spellcheck.lua index ff2db5e..84f2ef5 100644 --- a/spellcheck.lua +++ b/spellcheck.lua @@ -15,19 +15,23 @@ spellcheck.get_lang = function() or spellcheck.default_lang end -local supress_stdout = ' >/dev/null' -local supress_stderr = ' 2>/dev/null' -local supress_output = supress_stdout .. supress_stderr -if os.execute('type enchant' .. supress_output) then +local which do + local path = os.getenv"PATH":gsub(":","/?;") .. "/?" + function which(executable) + return package.searchpath(executable, path, "", "") + end +end + +if which"enchant" then spellcheck.cmd = 'enchant -d %s -a' spellcheck.list_cmd = 'enchant -l -d %s' -elseif os.execute('type enchant-2' .. supress_output) then +elseif which"enchant-2" then spellcheck.cmd = 'enchant-2 -d %s -a' spellcheck.list_cmd = 'enchant-2 -l -d %s' -elseif os.execute('type aspell' .. supress_output) then +elseif which"aspell" then spellcheck.cmd = 'aspell pipe -l %s' spellcheck.list_cmd = 'aspell list -l %s' -elseif os.execute('type hunspell' .. supress_output) then +elseif which"hunspell" then spellcheck.cmd = 'hunspell -d %s' spellcheck.list_cmd = 'hunspell -l -d %s' else @@ -55,6 +59,8 @@ if vis.lexers then end end +local supress_stderr = ' 2>/dev/null' + -- Return nil or a sequence of misspelled words in a specific file range or text -- by calling the spellchecker's list command. -- If given a range we will use vis:pipe to get our typos from the spellchecker. |
