mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-07-22 04:21:08 +00:00
fix(options): set_default option
This commit is contained in:
parent
ccbaf55c2f
commit
2401d5fca6
1 changed files with 21 additions and 22 deletions
|
|
@ -310,36 +310,35 @@ local _defaults = {} ---@type table<string, boolean>
|
||||||
--
|
--
|
||||||
-- It will only set the option if:
|
-- It will only set the option if:
|
||||||
-- * it is the same as the global value
|
-- * 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
|
-- * it was last set by a script in $VIMRUNTIME
|
||||||
---@param option string
|
---@param option string
|
||||||
---@param value string|number|boolean
|
---@param value string|number|boolean
|
||||||
---@return boolean was_set
|
---@return boolean was_set
|
||||||
function M.set_default(option, value)
|
function M.set_default(option, value)
|
||||||
local key = ("%s=%s"):format(option, value)
|
local l = vim.api.nvim_get_option_value(option, { scope = "local" })
|
||||||
_defaults[key] = true
|
local g = vim.api.nvim_get_option_value(option, { scope = "global" })
|
||||||
|
|
||||||
if not _defaults[key] then
|
_defaults[("%s=%s"):format(option, value)] = true
|
||||||
local l = vim.api.nvim_get_option_value(option, { scope = "local" })
|
local key = ("%s=%s"):format(option, l)
|
||||||
local g = vim.api.nvim_get_option_value(option, { scope = "global" })
|
|
||||||
|
|
||||||
if l ~= g then
|
if l ~= g and not _defaults[key] then
|
||||||
-- Option changed, so check if it was set by an ft plugin
|
-- Option does not match global and is not a default value
|
||||||
local info = vim.api.nvim_get_option_info2(option, { scope = "local" })
|
-- Check if it was set by a script in $VIMRUNTIME
|
||||||
---@param e vim.fn.getscriptinfo.ret
|
local info = vim.api.nvim_get_option_info2(option, { scope = "local" })
|
||||||
local scriptinfo = vim.tbl_filter(function(e)
|
---@param e vim.fn.getscriptinfo.ret
|
||||||
return e.sid == info.last_set_sid
|
local scriptinfo = vim.tbl_filter(function(e)
|
||||||
end, vim.fn.getscriptinfo())
|
return e.sid == info.last_set_sid
|
||||||
local by_rtp = #scriptinfo == 1 and vim.startswith(scriptinfo[1].name, vim.fn.expand("$VIMRUNTIME"))
|
end, vim.fn.getscriptinfo())
|
||||||
if not by_rtp then
|
local by_rtp = #scriptinfo == 1 and vim.startswith(scriptinfo[1].name, vim.fn.expand("$VIMRUNTIME"))
|
||||||
if vim.g.lazyvim_debug_set_default then
|
if not by_rtp then
|
||||||
LazyVim.warn(
|
if vim.g.lazyvim_debug_set_default then
|
||||||
("Not setting option `%s` to `%s` because it was changed by a filetype plugin."):format(option, value),
|
LazyVim.warn(
|
||||||
{ title = "LazyVim", once = true }
|
("Not setting option `%s` to `%s` because it was changed by a filetype plugin."):format(option, value),
|
||||||
)
|
{ title = "LazyVim", once = true }
|
||||||
end
|
)
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue