mirror of
https://github.com/neovim/neovim.git
synced 2025-11-15 06:49:01 +00:00
fix(ui2): emit FileType event after setting default pager options #36315
Problem: Setting a filetype before configuring default options for ui2 buffers (pager, cmd, ...) prevents users from setting their own options. Solution: Call nvim_set_option_value after defaults are set. Closes #36314 Co-authored-by: Luuk van Baal <luukvbaal@gmail.com>
This commit is contained in:
@@ -65,13 +65,9 @@ function M.check_targets()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if setopt then
|
if setopt then
|
||||||
local name = { cmd = 'Cmd', dialog = 'Dialog', msg = 'Msg', pager = 'Pager' }
|
-- Set options without firing OptionSet and BufFilePost.
|
||||||
-- Fire a FileType autocommand with window context to let the user reconfigure local options.
|
vim._with({ win = M.wins[type], noautocmd = true }, function()
|
||||||
-- First set 'eventignorewin' to avoid firing OptionSet and BufFilePost.
|
local ignore = 'all,-FileType' .. (type == 'pager' and ',-TextYankPost' or '')
|
||||||
api.nvim_win_call(M.wins[type], function()
|
|
||||||
local ft = name[type]:sub(1, 1):lower() .. name[type]:sub(2)
|
|
||||||
api.nvim_set_option_value('filetype', ft, { scope = 'local' })
|
|
||||||
local ignore = 'all' .. (type == 'pager' and ',-TextYankPost' or '')
|
|
||||||
api.nvim_set_option_value('eventignorewin', ignore, { scope = 'local' })
|
api.nvim_set_option_value('eventignorewin', ignore, { scope = 'local' })
|
||||||
api.nvim_set_option_value('wrap', true, { scope = 'local' })
|
api.nvim_set_option_value('wrap', true, { scope = 'local' })
|
||||||
api.nvim_set_option_value('linebreak', false, { scope = 'local' })
|
api.nvim_set_option_value('linebreak', false, { scope = 'local' })
|
||||||
@@ -87,7 +83,11 @@ function M.check_targets()
|
|||||||
api.nvim_set_option_value('winhighlight', hl, { scope = 'local' })
|
api.nvim_set_option_value('winhighlight', hl, { scope = 'local' })
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
api.nvim_buf_set_name(M.bufs[type], ('[%s]'):format(name[type]))
|
api.nvim_buf_set_name(M.bufs[type], ('[%s]'):format(type:sub(1, 1):upper() .. type:sub(2)))
|
||||||
|
-- Fire FileType with window context to let the user reconfigure local options.
|
||||||
|
vim._with({ win = M.wins[type] }, function()
|
||||||
|
api.nvim_set_option_value('filetype', type, { scope = 'local' })
|
||||||
|
end)
|
||||||
|
|
||||||
if type == 'pager' then
|
if type == 'pager' then
|
||||||
-- Close pager with `q`, same as `checkhealth`
|
-- Close pager with `q`, same as `checkhealth`
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
-- Tests for (protocol-driven) ui2, intended to replace the legacy message grid UI.
|
-- Tests for (protocol-driven) ui2, intended to replace the legacy message grid UI.
|
||||||
|
|
||||||
|
local t = require('test.testutil')
|
||||||
local n = require('test.functional.testnvim')()
|
local n = require('test.functional.testnvim')()
|
||||||
local Screen = require('test.functional.ui.screen')
|
local Screen = require('test.functional.ui.screen')
|
||||||
|
|
||||||
@@ -418,4 +419,23 @@ describe('messages2', function()
|
|||||||
|
|
|
|
||||||
]])
|
]])
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('FileType is fired after default options are set', function()
|
||||||
|
n.exec([[
|
||||||
|
let g:set = {}
|
||||||
|
au FileType pager set nowrap
|
||||||
|
au OptionSet * let g:set[expand('<amatch>')] = g:set->get(expand('<amatch>'), 0) + 1
|
||||||
|
echom 'foo'->repeat(&columns)
|
||||||
|
messages
|
||||||
|
]])
|
||||||
|
screen:expect([[
|
||||||
|
|
|
||||||
|
{1:~ }|*9
|
||||||
|
{3:─────────────────────────────────────────────────────}|
|
||||||
|
^foofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofo|
|
||||||
|
{1: }|
|
||||||
|
|
|
||||||
|
]])
|
||||||
|
t.eq({ filetype = 4 }, n.eval('g:set')) -- still fires for 'filetype'
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user