mirror of
https://github.com/LazyVim/LazyVim.git
synced 2026-03-10 09:27:25 +00:00
fix(options): track some initial options right after loading options.lua. See #6463
This commit is contained in:
@@ -304,6 +304,8 @@ function M.load(name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
M.did_init = false
|
M.did_init = false
|
||||||
|
M._options = {} ---@type vim.wo|vim.bo
|
||||||
|
|
||||||
function M.init()
|
function M.init()
|
||||||
if M.did_init then
|
if M.did_init then
|
||||||
return
|
return
|
||||||
@@ -326,6 +328,12 @@ function M.init()
|
|||||||
-- this is needed to make sure options will be correctly applied
|
-- this is needed to make sure options will be correctly applied
|
||||||
-- after installing missing plugins
|
-- after installing missing plugins
|
||||||
M.load("options")
|
M.load("options")
|
||||||
|
|
||||||
|
-- save some options to track defaults
|
||||||
|
M._options.indentexpr = vim.o.indentexpr
|
||||||
|
M._options.foldmethod = vim.o.foldmethod
|
||||||
|
M._options.foldexpr = vim.o.foldexpr
|
||||||
|
|
||||||
-- defer built-in clipboard handling: "xsel" and "pbcopy" can be slow
|
-- defer built-in clipboard handling: "xsel" and "pbcopy" can be slow
|
||||||
lazy_clipboard = vim.opt.clipboard
|
lazy_clipboard = vim.opt.clipboard
|
||||||
vim.opt.clipboard = ""
|
vim.opt.clipboard = ""
|
||||||
|
|||||||
@@ -317,11 +317,12 @@ local _defaults = {} ---@type table<string, boolean>
|
|||||||
---@return boolean was_set
|
---@return boolean was_set
|
||||||
function M.set_default(option, value)
|
function M.set_default(option, value)
|
||||||
local l = vim.api.nvim_get_option_value(option, { scope = "local" })
|
local l = vim.api.nvim_get_option_value(option, { scope = "local" })
|
||||||
local g = vim.api.nvim_get_option_value(option, { scope = "global" })
|
local g = LazyVim.config._options[option] or vim.api.nvim_get_option_value(option, { scope = "global" })
|
||||||
|
|
||||||
_defaults[("%s=%s"):format(option, value)] = true
|
_defaults[("%s=%s"):format(option, value)] = true
|
||||||
local key = ("%s=%s"):format(option, l)
|
local key = ("%s=%s"):format(option, l)
|
||||||
|
|
||||||
|
local source = ""
|
||||||
if l ~= g and not _defaults[key] then
|
if l ~= g and not _defaults[key] then
|
||||||
-- Option does not match global and is not a default value
|
-- Option does not match global and is not a default value
|
||||||
-- Check if it was set by a script in $VIMRUNTIME
|
-- Check if it was set by a script in $VIMRUNTIME
|
||||||
@@ -330,11 +331,12 @@ function M.set_default(option, value)
|
|||||||
local scriptinfo = vim.tbl_filter(function(e)
|
local scriptinfo = vim.tbl_filter(function(e)
|
||||||
return e.sid == info.last_set_sid
|
return e.sid == info.last_set_sid
|
||||||
end, vim.fn.getscriptinfo())
|
end, vim.fn.getscriptinfo())
|
||||||
|
source = scriptinfo[1] and scriptinfo[1].name or ""
|
||||||
local by_rtp = #scriptinfo == 1 and vim.startswith(scriptinfo[1].name, vim.fn.expand("$VIMRUNTIME"))
|
local by_rtp = #scriptinfo == 1 and vim.startswith(scriptinfo[1].name, vim.fn.expand("$VIMRUNTIME"))
|
||||||
if not by_rtp then
|
if not by_rtp then
|
||||||
if vim.g.lazyvim_debug_set_default then
|
if vim.g.lazyvim_debug_set_default then
|
||||||
LazyVim.warn(
|
LazyVim.warn(
|
||||||
("Not setting option `%s` to `%s` because it was changed by a filetype plugin."):format(option, value),
|
("Not setting option `%s` to `%q` because it was changed by a plugin."):format(option, value),
|
||||||
{ title = "LazyVim", once = true }
|
{ title = "LazyVim", once = true }
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@@ -343,7 +345,13 @@ function M.set_default(option, value)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if vim.g.lazyvim_debug_set_default then
|
if vim.g.lazyvim_debug_set_default then
|
||||||
LazyVim.info(("Setting option `%s` to `%s`"):format(option, value), { title = "LazyVim", once = true })
|
LazyVim.info({
|
||||||
|
("Setting option `%s` to `%q`"):format(option, value),
|
||||||
|
("Was: %q"):format(l),
|
||||||
|
("Global: %q"):format(g),
|
||||||
|
source ~= "" and ("Last set by: %s"):format(source) or "",
|
||||||
|
"buf: " .. vim.api.nvim_buf_get_name(0),
|
||||||
|
}, { title = "LazyVim", once = true })
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_set_option_value(option, value, { scope = "local" })
|
vim.api.nvim_set_option_value(option, value, { scope = "local" })
|
||||||
|
|||||||
Reference in New Issue
Block a user