From 6c1842f86d34d0e9afdea3e445c36091b5bf8246 Mon Sep 17 00:00:00 2001 From: Nomarian Date: Thu, 9 Oct 2025 10:26:35 -0400 Subject: No forking when trying to check for spellchecking utilities in $PATH (use package.searchpath instead) --- spellcheck.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'spellcheck.lua') 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. -- cgit v1.2.3