fix(options): set_default option

This commit is contained in:
Folke Lemaitre
2025-09-18 23:51:32 +02:00
parent ccbaf55c2f
commit 2401d5fca6

View File

@@ -310,21 +310,21 @@ local _defaults = {} ---@type table<string, boolean>
--
-- It will only set the option if:
-- * it is the same as the global value
-- * it is the same as a previously set default value
-- * it's current value is a default value
-- * it was last set by a script in $VIMRUNTIME
---@param option string
---@param value string|number|boolean
---@return boolean was_set
function M.set_default(option, value)
local key = ("%s=%s"):format(option, value)
_defaults[key] = true
if not _defaults[key] then
local l = vim.api.nvim_get_option_value(option, { scope = "local" })
local g = vim.api.nvim_get_option_value(option, { scope = "global" })
if l ~= g then
-- Option changed, so check if it was set by an ft plugin
_defaults[("%s=%s"):format(option, value)] = true
local key = ("%s=%s"):format(option, l)
if l ~= g and not _defaults[key] then
-- Option does not match global and is not a default value
-- Check if it was set by a script in $VIMRUNTIME
local info = vim.api.nvim_get_option_info2(option, { scope = "local" })
---@param e vim.fn.getscriptinfo.ret
local scriptinfo = vim.tbl_filter(function(e)
@@ -341,7 +341,6 @@ function M.set_default(option, value)
return false
end
end
end
if vim.g.lazyvim_debug_set_default then
LazyVim.info(("Setting option `%s` to `%s`"):format(option, value), { title = "LazyVim", once = true })