diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index 2f935f0882..e2baaadd21 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -2955,25 +2955,25 @@ vim.glob.to_lpeg({pattern}) *vim.glob.to_lpeg()* Lua module: vim.hl *vim.hl* vim.hl.hl_op({opts}) *vim.hl.hl_op()* - Highlight the related text region during a |TextYankPost| or |TextPutPost| - event. + Highlights the affected text region during a |TextYankPost| or + |TextPutPost| event. - Add the following to your `init.vim`: >vim + Add this to your `init.vim`: >vim autocmd TextYankPost * silent! lua vim.hl.hl_op {higroup='Visual', timeout=300} - autocmd TextPutPost * silent! lua vim.hl.hl_op {higroup='Visual', timeout=300} + autocmd TextPutPost * silent! lua vim.hl.hl_op {higroup='Visual', timeout=300} < Parameters: ~ • {opts} (`table?`) Optional parameters - • event event structure (default vim.v.event) - • higroup highlight group for the text region (default - "IncSearch") - • on_macro highlight when executing macro (default false) - • on_visual highlight when the event is in |Visual| mode - (default true) - • priority integer priority (default - |vim.hl.priorities|`.user`) - • timeout time in ms before highlight is cleared (default 150) + • event (default vim.v.event) Event structure. + • higroup (default "IncSearch") Highlight group for the text + region. + • on_macro (default false) Highlight during |macro| execution. + • on_visual (default true) Highlight during |Visual| mode. + • priority (default |vim.hl.priorities|`.user`) Integer + priority. + • timeout (default 150) Time in ms before highlight is + cleared. vim.hl.priorities *vim.hl.priorities* Table with default priorities used for highlighting: diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index 1d7dc96b79..c3f544e231 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -249,7 +249,8 @@ TUI • The TUI will re-query the terminal's background color when resuming from a suspended state, and Nvim will update 'background' accordingly. -• TUI uses |$NVIM_TERMDEFS| to override terminfo entries. +• User can override the builtin "terminfo" via |$NVIM_TERMDEFS|. This is + similar to Vim's |t_xx| options. UI diff --git a/runtime/doc/tui.txt b/runtime/doc/tui.txt index 55d56cd925..249086e786 100644 --- a/runtime/doc/tui.txt +++ b/runtime/doc/tui.txt @@ -52,13 +52,14 @@ own terminfo is usually as simple as running this: < *$NVIM_TERMDEFS* -To override terminfo entries without modifying terminfo files, use -$NVIM_TERMDEFS. This may be useful on Windows, where Unibilium can't read -terminfo files. When this is set, terminfo files are not used, but builtin -terminfo entries are. Any values in this variable will override the builtin -definitions. For example, to disable alternate screen, override the sequence -nvim sends to reset the cursor style, and set the sequences that get -interpreted as and : > +To override the builtin terminfo, set $NVIM_TERMDEFS to a JSON object whose +keys correspond to one or more of the fields below, each of which will +override its counterpart (if any) in the builtin terminfo. The system terminfo +will be skipped entirely: only builtin definitions, plus the $NVIM_TERMDEFS +overrides, will be used. + +For example, to disable alternate screen, override the "reset the cursor +style" sequence, and set the and sequences: > NVIM_TERMDEFS='{ "enter_ca_mode": "", diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 70deda3a96..9efd5656b1 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -941,7 +941,8 @@ TUI: *t_xx* *termcap-options* *t_AB* *t_Sb* *t_vb* *t_SI* - Nvim does not have special `t_XX` options nor keycodes to configure terminal capabilities. Instead Nvim treats the terminal as any other UI, - e.g. 'guicursor' sets the terminal cursor style if possible. + e.g. 'guicursor' sets the terminal cursor style if possible. You can use + |$NVIM_TERMDEFS| if you still need to override the builtin definitions. *termcap* - Nvim never uses the termcap database, only |terminfo| and |builtin-terms|. diff --git a/runtime/lua/vim/hl.lua b/runtime/lua/vim/hl.lua index 861d40402d..f67a7a8b96 100644 --- a/runtime/lua/vim/hl.lua +++ b/runtime/lua/vim/hl.lua @@ -154,23 +154,22 @@ local hl_op_state = {} local events_ns = api.nvim_create_namespace('nvim.hl.events') ---- Highlight the related text region during a |TextYankPost| or |TextPutPost| ---- event. +--- Highlights the affected text region during a |TextYankPost| or |TextPutPost| event. --- ---- Add the following to your `init.vim`: +--- Add this to your `init.vim`: --- --- ```vim --- autocmd TextYankPost * silent! lua vim.hl.hl_op {higroup='Visual', timeout=300} ---- autocmd TextPutPost * silent! lua vim.hl.hl_op {higroup='Visual', timeout=300} +--- autocmd TextPutPost * silent! lua vim.hl.hl_op {higroup='Visual', timeout=300} --- ``` --- --- @param opts table|nil Optional parameters ---- - event event structure (default vim.v.event) ---- - higroup highlight group for the text region (default "IncSearch") ---- - on_macro highlight when executing macro (default false) ---- - on_visual highlight when the event is in |Visual| mode (default true) ---- - priority integer priority (default |vim.hl.priorities|`.user`) ---- - timeout time in ms before highlight is cleared (default 150) +--- - event (default vim.v.event) Event structure. +--- - higroup (default "IncSearch") Highlight group for the text region. +--- - on_macro (default false) Highlight during |macro| execution. +--- - on_visual (default true) Highlight during |Visual| mode. +--- - priority (default |vim.hl.priorities|`.user`) Integer priority. +--- - timeout (default 150) Time in ms before highlight is cleared. function M.hl_op(opts) vim.validate('opts', opts, 'table', true) opts = opts or {} @@ -180,23 +179,16 @@ function M.hl_op(opts) if not on_macro and vim.fn.reg_executing() ~= '' then return - end - if event.regtype == '' then + elseif + event.regtype == '' + or (event.operator ~= 'y' and event.operator ~= 'p' and event.operator ~= 'P') + then return - end - if not on_visual and event.visual then - return - end - - local state_key --- @type string - if event.operator == 'y' then - state_key = 'yank' - elseif event.operator == 'p' or event.operator == 'P' then - state_key = 'put' - else + elseif not on_visual and event.visual then return end + local state_key = event.operator == 'y' and 'yank' or 'put' local higroup = opts.higroup or 'IncSearch' local bufnr = api.nvim_get_current_buf() @@ -223,9 +215,9 @@ function M.hl_op(opts) } end ---- @deprecated Please use |vim.hl.hl_op()| instead. +--- @deprecated Use |vim.hl.hl_op()| instead. function M.on_yank(opts) - vim.deprecate('vim.hl.on_yank', 'vim.hl.hl_op', '0.13') + vim.deprecate('vim.hl.on_yank', 'vim.hl.hl_op', '0.14') return M.hl_op(opts) end diff --git a/runtime/lua/vim/tty.lua b/runtime/lua/vim/tty.lua index 4e2acb7fc5..2693c1bc97 100644 --- a/runtime/lua/vim/tty.lua +++ b/runtime/lua/vim/tty.lua @@ -169,7 +169,7 @@ local function broadcast_error(msg) end --- Get user overrides for terminfo entries as a table. See |$NVIM_TERMDEFS| -function M.get_termdefs() +function M._get_termdefs() local termdefs_raw = os.getenv('NVIM_TERMDEFS') if termdefs_raw ~= nil then local ok, termdefs_or_err = pcall(vim.json.decode, termdefs_raw) diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index c9673caa27..72c535db26 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -356,11 +356,10 @@ void tui_query_bg_color(TUIData *tui) flush_buf(tui); } -/// Use $NVIM_TERMDEFS to apply user overrides to terminfo. +/// Use $NVIM_TERMDEFS to apply user overrides to terminfo. This is our own homebaked "terminfo", +/// analogous to Vim's t_xx options. #37274 /// -/// This is necessary for Windows, where terminfo files are broken in Unibilium. #37274 -/// If/when Unibilium is removed, this will also be useful for anyone who wants to override -/// the built-in definitions. +/// This also positions us to drop Unibilium entirely. static void apply_termdefs(TUIData *tui) { // We allow empty values just to provide the user with a warning @@ -369,7 +368,7 @@ static void apply_termdefs(TUIData *tui) } Error lua_err = ERROR_INIT; - Object rv = NLUA_EXEC_STATIC("return require('vim.tty').get_termdefs()", + Object rv = NLUA_EXEC_STATIC("return require('vim.tty')._get_termdefs()", (Array)ARRAY_DICT_INIT, kRetObject, NULL, &lua_err); if (rv.type != kObjectTypeDict) { return; diff --git a/test/functional/legacy/textobjects_spec.lua b/test/functional/legacy/textobjects_spec.lua deleted file mode 100644 index 9ed8716bff..0000000000 --- a/test/functional/legacy/textobjects_spec.lua +++ /dev/null @@ -1,62 +0,0 @@ -local n = require('test.functional.testnvim')() - -local call = n.call -local clear = n.clear -local command = n.command -local expect = n.expect -local source = n.source - -describe('Text object', function() - before_each(function() - clear() - command('set shada=') - source([[ - function SelectionOut(data) - new - call setline(1, a:data) - call setreg('"', '') - normal! ggfrmavi)y - $put =getreg('\"') - call setreg('"', '') - normal! `afbmavi)y - $put =getreg('\"') - call setreg('"', '') - normal! `afgmavi)y - $put =getreg('\"') - endfunction - ]]) - end) - - it('Test for vi) without cpo-M', function() - command('set cpo-=M') - call('SelectionOut', '(red \\(blue) green)') - - expect([[ - (red \(blue) green) - red \(blue - red \(blue - ]]) - end) - - it('Test for vi) with cpo-M #1', function() - command('set cpo+=M') - call('SelectionOut', '(red \\(blue) green)') - - expect([[ - (red \(blue) green) - red \(blue) green - blue - red \(blue) green]]) - end) - - it('Test for vi) with cpo-M #2', function() - command('set cpo+=M') - call('SelectionOut', '(red (blue\\) green)') - - expect([[ - (red (blue\) green) - red (blue\) green - blue\ - red (blue\) green]]) - end) -end)