From c294bc397b6a50fa3e1709246250e8b394555ce1 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Mon, 6 Apr 2026 09:44:03 -0700 Subject: [PATCH 1/2] fix(tui): check background color on resume Problem: We normally get the background color via continuous reporting. However, if we were backgrounded while the light/dark mode changed, we won't have received the report, and we'll have the wrong background color. Without this change, if you background nvim, toggle the light/dark mode, resume, and check `:set bg`, it will not match the current state. Solution: Query it on resume as well. (This requires separating the query from the flush, to just do the query along with all the others, while waiting to flush until we've set up uv.) With this change, if you background nvim, toggle the light/dark mode, resume, and check `:set bg`, it will have updated. --- runtime/doc/news.txt | 2 ++ src/nvim/tui/tui.c | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 81df75ad6c..4af8dd6716 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -394,6 +394,8 @@ TUI sequence. • The TUI now renders the SGR dim (faint), blink, conceal, and overline attributes. +• The TUI will re-query the terminal's background color when resuming from + a suspended state, and Nvim will update 'background' accordingly. UI diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index 1cdcf59fec..8eea4fb5b5 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -337,14 +337,20 @@ static void tui_reset_key_encoding(TUIData *tui) } } +static void tui_query_bg_color_noflush(TUIData *tui) + FUNC_ATTR_NONNULL_ALL +{ + out(tui, S_LEN("\x1b]11;?\x07\x1b[5n")); +} + /// Write the OSC 11 + DSR sequence to the terminal emulator to query the current -/// background color. +/// background color, and flush the terminal. /// /// Response will be handled by the TermResponse handler in _core/defaults.lua. void tui_query_bg_color(TUIData *tui) FUNC_ATTR_NONNULL_ALL { - out(tui, S_LEN("\x1b]11;?\x07\x1b[5n")); + tui_query_bg_color_noflush(tui); flush_buf(tui); } @@ -483,6 +489,11 @@ static void terminfo_start(TUIData *tui) // Query the terminal to see if it supports Kitty's keyboard protocol tui_query_kitty_keyboard(tui); + // Query the terminal's background color. We normally get it via continuous reporting (set via + // `kTermModeThemeUpdates` above), but if we were backgrounded while the light/dark mode changed, + // we won't have received the report, so we also query it on resume. + tui_query_bg_color_noflush(tui); + int ret; uv_loop_init(&tui->write_loop); if (tui->out_isatty) { From ceaa8b648a8e45e3b35b6ede8df884f29345d42b Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Mon, 6 Apr 2026 18:48:42 +0200 Subject: [PATCH 2/2] feat(filetype): `vim.filetype.inspect()` returns copy of registry Problem: No way of inspecting the (user-added) filetype detection rules. Solution: Add `vim.filetype.inspect()` returning copies of the internal `extension`, `filename`, `pattern` tables. Due to the dynamic nature of filetype detection, this will in general not allow getting the list of known filetypes, but at least one can see if a given extension is known. --- runtime/doc/lua.txt | 14 ++++++++++++++ runtime/doc/news.txt | 2 ++ runtime/lua/vim/filetype.lua | 16 ++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index a1cd23ec2a..46407a6396 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -2409,6 +2409,20 @@ vim.filetype.get_option({filetype}, {option}) Return: ~ (`string|boolean|integer`) Option value +vim.filetype.inspect() *vim.filetype.inspect()* + Inspect the current state of the filetype registry. + + Returns a copy of the internal tables used for filetype detection by + extension, filename, or pattern. Note: Due to the dynamic nature of + filetype detection, this is only useful for checking whether a certain + extension, filename, or pattern has been registered so far. In addition, + the `pattern` table is in an internal format optimized for fast lookup. + Prefer |vim.filetype.match()| for checking the detected filetype for a + given pattern. + + Return: ~ + (`table>>`) + vim.filetype.match({args}) *vim.filetype.match()* Perform filetype detection. diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 4af8dd6716..3ef77fbb47 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -299,6 +299,8 @@ LUA • |vim.json.encode()| `sort_keys` option sorts by key. • |vim.json.decode()| `skip_comments` option allows comments in JSON data. • EXPERIMENTAL: |vim.pos|, |vim.range| provide Position/Range abstraction. +• |vim.filetype.inspect()| returns a copy of the internal tables used for + filetype detection. OPTIONS diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index 37cdb7aed8..d77b27ada5 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -3295,4 +3295,20 @@ function M.get_option(filetype, option) return require('vim.filetype.options').get_option(filetype, option) end +--- Inspect the current state of the filetype registry. +--- +--- Returns a copy of the internal tables used for filetype detection by extension, filename, or +--- pattern. Note: Due to the dynamic nature of filetype detection, this is only useful for checking +--- whether a certain extension, filename, or pattern has been registered so far. In addition, the +--- `pattern` table is in an internal format optimized for fast lookup. Prefer |vim.filetype.match()| +--- for checking the detected filetype for a given pattern. +---@return table>> +function M.inspect() + return { + extension = vim.deepcopy(extension), + filename = vim.deepcopy(filename), + pattern = vim.deepcopy(pattern), + } +end + return M