mirror of
https://github.com/neovim/neovim.git
synced 2026-07-21 08:31:47 +00:00
fix(startup): emitting useless OptionSet #39830
Problem: During startup, we manually trigger a useless and misleading `OptionSet` event, which doesn't set `v:option_*` values (this is a limitation of `nvim_exec_autocmds`).ad4bc2d90c/runtime/lua/vim/_core/defaults.lua (L939). Solution: The `nvim_exec_autocmds('OptionSet',…)` call does not serve any purpose since5cbb9d613b, so just drop it.
This commit is contained in:
@@ -270,6 +270,8 @@ CHANGED FEATURES *news-changed*
|
|||||||
|
|
||||||
These existing features changed their behavior.
|
These existing features changed their behavior.
|
||||||
|
|
||||||
|
• |OptionSet| is no longer triggered during startup by automatic
|
||||||
|
|'background'| detection.
|
||||||
• |:Open| with no arguments uses the current file.
|
• |:Open| with no arguments uses the current file.
|
||||||
• The "buffer" key was renamed to "buf" in these functions (but the old name
|
• The "buffer" key was renamed to "buf" in these functions (but the old name
|
||||||
"buffer" is still accepted, for backwards compatibility):
|
"buffer" is still accepted, for backwards compatibility):
|
||||||
|
|||||||
@@ -851,7 +851,7 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
global
|
global
|
||||||
When set to "dark" or "light", adjusts the default color groups for
|
When set to "dark" or "light", adjusts the default color groups for
|
||||||
that background type. The |TUI| or other UI sets this on startup
|
that background type. The |TUI| or other UI sets this on startup
|
||||||
(triggering |OptionSet|) if it can detect the background color.
|
if it can detect the background color.
|
||||||
|
|
||||||
This option does NOT change the background color, it tells Nvim what
|
This option does NOT change the background color, it tells Nvim what
|
||||||
the "inherited" (terminal/GUI) background looks like.
|
the "inherited" (terminal/GUI) background looks like.
|
||||||
|
|||||||
@@ -946,20 +946,6 @@ do
|
|||||||
local luminance = (0.299 * rr) + (0.587 * gg) + (0.114 * bb)
|
local luminance = (0.299 * rr) + (0.587 * gg) + (0.114 * bb)
|
||||||
local bg = luminance < 0.5 and 'dark' or 'light'
|
local bg = luminance < 0.5 and 'dark' or 'light'
|
||||||
vim.api.nvim_set_option_value('background', bg, {})
|
vim.api.nvim_set_option_value('background', bg, {})
|
||||||
|
|
||||||
-- Ensure OptionSet still triggers when we set the background during startup
|
|
||||||
if vim.v.vim_did_enter == 0 then
|
|
||||||
vim.api.nvim_create_autocmd('VimEnter', {
|
|
||||||
group = group,
|
|
||||||
once = true,
|
|
||||||
nested = true,
|
|
||||||
callback = function()
|
|
||||||
vim.api.nvim_exec_autocmds('OptionSet', {
|
|
||||||
pattern = 'background',
|
|
||||||
})
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|||||||
2
runtime/lua/vim/_meta/options.gen.lua
generated
2
runtime/lua/vim/_meta/options.gen.lua
generated
@@ -224,7 +224,7 @@ vim.go.awa = vim.go.autowriteall
|
|||||||
|
|
||||||
--- When set to "dark" or "light", adjusts the default color groups for
|
--- When set to "dark" or "light", adjusts the default color groups for
|
||||||
--- that background type. The `TUI` or other UI sets this on startup
|
--- that background type. The `TUI` or other UI sets this on startup
|
||||||
--- (triggering `OptionSet`) if it can detect the background color.
|
--- if it can detect the background color.
|
||||||
---
|
---
|
||||||
--- This option does NOT change the background color, it tells Nvim what
|
--- This option does NOT change the background color, it tells Nvim what
|
||||||
--- the "inherited" (terminal/GUI) background looks like.
|
--- the "inherited" (terminal/GUI) background looks like.
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ local options = {
|
|||||||
desc = [=[
|
desc = [=[
|
||||||
When set to "dark" or "light", adjusts the default color groups for
|
When set to "dark" or "light", adjusts the default color groups for
|
||||||
that background type. The |TUI| or other UI sets this on startup
|
that background type. The |TUI| or other UI sets this on startup
|
||||||
(triggering |OptionSet|) if it can detect the background color.
|
if it can detect the background color.
|
||||||
|
|
||||||
This option does NOT change the background color, it tells Nvim what
|
This option does NOT change the background color, it tells Nvim what
|
||||||
the "inherited" (terminal/GUI) background looks like.
|
the "inherited" (terminal/GUI) background looks like.
|
||||||
|
|||||||
@@ -4290,23 +4290,28 @@ describe('TUI bg color', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('triggers OptionSet from automatic background processing', function()
|
it('does not trigger OptionSet from automatic background processing', function()
|
||||||
|
command('set background=light')
|
||||||
|
local child_server = new_pipename()
|
||||||
local screen = tt.setup_child_nvim({
|
local screen = tt.setup_child_nvim({
|
||||||
'--clean',
|
'--clean',
|
||||||
|
'--listen',
|
||||||
|
child_server,
|
||||||
'--cmd',
|
'--cmd',
|
||||||
'colorscheme vim',
|
'colorscheme vim',
|
||||||
'--cmd',
|
'--cmd',
|
||||||
'set noswapfile',
|
'set noswapfile',
|
||||||
'-c',
|
'-c',
|
||||||
'autocmd OptionSet background echo "did OptionSet, yay!"',
|
[[let g:background_optionset = 0]],
|
||||||
|
'-c',
|
||||||
|
[[autocmd OptionSet background let g:background_optionset += 1]],
|
||||||
})
|
})
|
||||||
screen:expect([[
|
screen:expect({ any = '%[No Name%]' })
|
||||||
^ |
|
local child_session = n.connect(child_server)
|
||||||
{5:~} |*3
|
retry(nil, nil, function()
|
||||||
{3:[No Name] 0,0-1 All}|
|
eq({ true, 'light' }, { child_session:request('nvim_eval', '&background') })
|
||||||
did OptionSet, yay! |
|
end)
|
||||||
{5:-- TERMINAL --} |
|
eq({ true, 0 }, { child_session:request('nvim_eval', 'g:background_optionset') })
|
||||||
]])
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('sends theme update notifications when background changes #31652', function()
|
it('sends theme update notifications when background changes #31652', function()
|
||||||
|
|||||||
Reference in New Issue
Block a user