From 40c64db15f579e8f119f1850b14b851b1c1bde2b Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 22 Oct 2025 19:21:17 +0200 Subject: use vis' pipe buffer support to check a string for typos Since lua does not support bidirectional popen, we used to write to a temporary file each time we checked some string for typos. A string is always checked when using the syntax aware mode. Using the buffered pipe offered by vis removes potential overhead introduced by the write/read cycle and preserve SSD writes. --- spellcheck.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/spellcheck.lua b/spellcheck.lua index 3ef5e04..4e4797c 100644 --- a/spellcheck.lua +++ b/spellcheck.lua @@ -61,6 +61,9 @@ end local supress_stderr = ' 2>/dev/null' +-- Detect if vis supports piping a buffer to an external command. +local vis_supports_pipe_buf = pcall(vis.pipe, vis, 'foo', 'true', false) + -- 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. @@ -70,7 +73,8 @@ local supress_stderr = ' 2>/dev/null' local function get_typos(range_or_text) local cmd = spellcheck.list_cmd:format(spellcheck.get_lang()) local typos - if type(range_or_text) == 'string' then + -- Legacy fallback using a temporary file as output + if type(range_or_text) == 'string' and not vis_supports_pipe_buf then local text = range_or_text local tmp_name = os.tmpname() local full_cmd = cmd .. '> ' .. tmp_name .. supress_stderr @@ -88,8 +92,12 @@ local function get_typos(range_or_text) tmp_file:close() os.remove(tmp_name) else - local range = range_or_text - local ret, so, _ = vis:pipe(vis.win.file, range, cmd) + local ret, so + if type(range_or_text) == 'string' then + ret, so = vis:pipe(range_or_text, cmd) + else + ret, so = vis:pipe(vis.win.file, range_or_text, cmd) + end if ret ~= 0 then vis:info('calling ' .. cmd .. ' failed (' .. ret .. ')') -- cgit v1.2.3