From 4e1644d4d3cb6b2ae7bd7110add8424e5217882b Mon Sep 17 00:00:00 2001 From: Olivia Kinnear Date: Sat, 6 Dec 2025 16:20:02 -0600 Subject: [PATCH] feat(spell): opt-out of confirm when downloading spellfiles #36836 --- runtime/doc/plugins.txt | 2 ++ runtime/lua/nvim/spellfile.lua | 31 ++++++++++++------- test/functional/plugin/spellfile_spec.lua | 37 ++++++++++++++++++++++- 3 files changed, 58 insertions(+), 12 deletions(-) diff --git a/runtime/doc/plugins.txt b/runtime/doc/plugins.txt index c732f72cce..ebbb01e813 100644 --- a/runtime/doc/plugins.txt +++ b/runtime/doc/plugins.txt @@ -185,6 +185,8 @@ The plugin can be disabled by setting `g:loaded_spellfile_plugin = 1`. otherwise https://ftp.nluug.nl/pub/vim/runtime/spell. • {timeout_ms} (`integer`, default: 15000) Number of milliseconds after which the |vim.net.request()| times out. + • {confirm} (`boolean`, default: `true`) Whether to ask user to + confirm download. config({opts}) *spellfile.config()* diff --git a/runtime/lua/nvim/spellfile.lua b/runtime/lua/nvim/spellfile.lua index 63882c37a3..45bfd5b872 100644 --- a/runtime/lua/nvim/spellfile.lua +++ b/runtime/lua/nvim/spellfile.lua @@ -25,11 +25,16 @@ local M = {} --- Number of milliseconds after which the [vim.net.request()] times out. --- (default: 15000) --- @field timeout_ms integer +--- +--- Whether to ask user to confirm download. +--- (default: `true`) +--- @field confirm boolean --- @type nvim.spellfile.Opts local config = { url = vim.g.spellfile_URL or 'https://ftp.nluug.nl/pub/vim/runtime/spell', timeout_ms = 15000, + confirm = true, } --- Configure spellfile download options. For example: @@ -270,18 +275,22 @@ function M.get(lang) return end - local prompt = ('No spell file found for %s (%s). Download? [y/N] '):format( - info.lang, - info.encoding - ) - vim.ui.input({ prompt = prompt }, function(input) - -- properly clear the message window - vim.api.nvim_echo({ { ' ' } }, false, { kind = 'empty' }) - if not input or input:lower() ~= 'y' then - return - end + if config.confirm then + local prompt = ('No spell file found for %s (%s). Download? [y/N] '):format( + info.lang, + info.encoding + ) + vim.ui.input({ prompt = prompt }, function(input) + -- properly clear the message window + vim.api.nvim_echo({ { ' ' } }, false, { kind = 'empty' }) + if not input or input:lower() ~= 'y' then + return + end + download(info) + end) + else download(info) - end) + end return info end diff --git a/test/functional/plugin/spellfile_spec.lua b/test/functional/plugin/spellfile_spec.lua index 11cff25437..262b63a0b7 100644 --- a/test/functional/plugin/spellfile_spec.lua +++ b/test/functional/plugin/spellfile_spec.lua @@ -2,6 +2,7 @@ local n = require('test.functional.testnvim')() local t = require('test.testutil') local eq = t.eq +local neq = t.neq local exec_lua = n.exec_lua describe('nvim.spellfile', function() @@ -40,7 +41,10 @@ describe('nvim.spellfile', function() vim.fn.input = function() prompted = true; return 'n' end local requests = 0 - vim.net.request = function(...) requests = requests + 1 end + vim.net.request = function(_, _, cb) + requests = requests + 1 + cb() + end s.get('en_gb') @@ -148,4 +152,35 @@ describe('nvim.spellfile', function() eq(true, out.done) eq(false, out.did_reload) end) + + it('no confirmation when using confirm = false', function() + local out = exec_lua( + [[ + local rtp_dir = ... + local s = require('nvim.spellfile') + + vim.fn.input = function(...) + error('prompt was triggered') + return 'n' + end + + local requests = 0 + vim.net.request = function(_, _, cb) + requests = requests + 1 + cb() + end + + s.config({ confirm = false }) + s.get('en_gb') + + -- Reset value + s.config({ confirm = true }) + + return { requests = requests } + ]], + rtp_dir + ) + + neq(0, out.requests) + end) end)