docs: use "ev" convention in event-handlers

Problem:
In autocmd examples, using "args" as the event-object name is vague and
may be confused with a user-command.

Solution:
Use "ev" as the conventional event-object name.
This commit is contained in:
Justin M. Keyes
2026-03-11 14:25:12 +01:00
parent bc67976c95
commit 7ea148a1dc
35 changed files with 191 additions and 205 deletions

View File

@@ -1130,8 +1130,8 @@ TermResponse When Nvim receives a DA1, OSC, DCS, or APC response from
-- (red) using OSC 4
vim.api.nvim_create_autocmd('TermResponse', {
once = true,
callback = function(args)
local resp = args.data.sequence
callback = function(ev)
local resp = ev.data.sequence
local r, g, b = resp:match("\027%]4;1;rgb:(%w+)/(%w+)/(%w+)")
end,
})

View File

@@ -1432,10 +1432,6 @@ gq{motion} Format the lines that {motion} moves over.
formatting |fo-table|.
The cursor is left on the first non-blank of the last
formatted line.
NOTE: The "Q" command formerly performed this
function. If you still want to use "Q" for
formatting, use this mapping: >
:nnoremap Q gq
gqgq *gqgq* *gqq*
gqq Format the current line. With a count format that

View File

@@ -425,8 +425,8 @@ DiagnosticChanged After diagnostics have changed. When used from Lua,
Example: >lua
vim.api.nvim_create_autocmd('DiagnosticChanged', {
callback = function(args)
local diagnostics = args.data.diagnostics
callback = function(ev)
local diagnostics = ev.data.diagnostics
vim.print(diagnostics)
end,
})

View File

@@ -107,7 +107,7 @@ BUFFER-LOCAL DEFAULTS
- |K| is mapped to |vim.lsp.buf.hover()| unless 'keywordprg' is customized or
a custom keymap for `K` exists.
- Document colors are enabled for highlighting color references in a document.
- To opt out call `vim.lsp.document_color.enable(false, args.buf)` on |LspAttach|.
- To opt out call `vim.lsp.document_color.enable(false, ev.buf)` on |LspAttach|.
DISABLING DEFAULTS *lsp-defaults-disable*
@@ -117,15 +117,15 @@ You can remove GLOBAL keymaps at any time using |vim.keymap.del()| or
To remove or override BUFFER-LOCAL defaults, define a |LspAttach| handler: >lua
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
callback = function(ev)
-- Unset 'formatexpr'
vim.bo[args.buf].formatexpr = nil
vim.bo[ev.buf].formatexpr = nil
-- Unset 'omnifunc'
vim.bo[args.buf].omnifunc = nil
vim.bo[ev.buf].omnifunc = nil
-- Unmap K
vim.keymap.del('n', 'K', { buffer = args.buf })
vim.keymap.del('n', 'K', { buffer = ev.buf })
-- Disable document colors
vim.lsp.document_color.enable(false, args.buf)
vim.lsp.document_color.enable(false, ev.buf)
end,
})
<
@@ -257,8 +257,8 @@ Example: Enable auto-completion and auto-formatting ("linting"): >lua
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('my.lsp', {}),
callback = function(args)
local client = assert(vim.lsp.get_client_by_id(args.data.client_id))
callback = function(ev)
local client = assert(vim.lsp.get_client_by_id(ev.data.client_id))
if client:supports_method('textDocument/implementation') then
-- Create a keymap for vim.lsp.buf.implementation ...
end
@@ -269,7 +269,7 @@ Example: Enable auto-completion and auto-formatting ("linting"): >lua
-- local chars = {}; for i = 32, 126 do table.insert(chars, string.char(i)) end
-- client.server_capabilities.completionProvider.triggerCharacters = chars
vim.lsp.completion.enable(true, client.id, args.buf, {autotrigger = true})
vim.lsp.completion.enable(true, client.id, ev.buf, {autotrigger = true})
end
-- Auto-format ("lint") on save.
@@ -278,9 +278,9 @@ Example: Enable auto-completion and auto-formatting ("linting"): >lua
and client:supports_method('textDocument/formatting') then
vim.api.nvim_create_autocmd('BufWritePre', {
group = vim.api.nvim_create_augroup('my.lsp', {clear=false}),
buffer = args.buf,
buffer = ev.buf,
callback = function()
vim.lsp.buf.format({ bufnr = args.buf, id = client.id, timeout_ms = 1000 })
vim.lsp.buf.format({ bufnr = ev.buf, id = client.id, timeout_ms = 1000 })
end,
})
end
@@ -615,15 +615,15 @@ LspDetach *LspDetach*
Example: >lua
vim.api.nvim_create_autocmd('LspDetach', {
callback = function(args)
callback = function(ev)
-- Get the detaching client
local client = vim.lsp.get_client_by_id(args.data.client_id)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
-- Remove the autocommand to format the buffer on save, if it exists
if client:supports_method('textDocument/formatting') then
vim.api.nvim_clear_autocmds({
event = 'BufWritePre',
buffer = args.buf,
buffer = ev.buf,
})
end
end,
@@ -639,11 +639,11 @@ LspNotify *LspNotify*
Example: >lua
vim.api.nvim_create_autocmd('LspNotify', {
callback = function(args)
local bufnr = args.buf
local client_id = args.data.client_id
local method = args.data.method
local params = args.data.params
callback = function(ev)
local bufnr = ev.buf
local client_id = ev.data.client_id
local method = ev.data.method
local params = ev.data.params
-- do something with the notification
if method == 'textDocument/...' then
@@ -704,11 +704,11 @@ LspRequest *LspRequest*
Example: >lua
vim.api.nvim_create_autocmd('LspRequest', {
callback = function(args)
local bufnr = args.buf
local client_id = args.data.client_id
local request_id = args.data.request_id
local request = args.data.request
callback = function(ev)
local bufnr = ev.buf
local client_id = ev.data.client_id
local request_id = ev.data.request_id
local request = ev.data.request
if request.type == 'pending' then
-- do something with pending requests
track_pending(client_id, bufnr, request_id, request)
@@ -733,11 +733,11 @@ LspTokenUpdate *LspTokenUpdate*
Example: >lua
vim.api.nvim_create_autocmd('LspTokenUpdate', {
callback = function(args)
local token = args.data.token
callback = function(ev)
local token = ev.data.token
if token.type == 'variable' and not token.modifiers.readonly then
vim.lsp.semantic_tokens.highlight_token(
token, args.buf, args.data.client_id, 'MyMutableVariableHighlight'
token, ev.buf, ev.data.client_id, 'MyMutableVariableHighlight'
)
end
end,
@@ -1045,9 +1045,9 @@ foldclose({kind}, {winid}) *vim.lsp.foldclose()*
To automatically fold imports when opening a file, you can use an autocmd: >lua
vim.api.nvim_create_autocmd('LspNotify', {
callback = function(args)
if args.data.method == 'textDocument/didOpen' then
vim.lsp.foldclose('imports', vim.fn.bufwinid(args.buf))
callback = function(ev)
if ev.data.method == 'textDocument/didOpen' then
vim.lsp.foldclose('imports', vim.fn.bufwinid(ev.buf))
end
end,
})
@@ -1078,8 +1078,8 @@ foldexpr({lnum}) *vim.lsp.foldexpr()*
vim.o.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
-- Prefer LSP folding if client supports it
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
callback = function(ev)
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if client:supports_method('textDocument/foldingRange') then
local win = vim.api.nvim_get_current_win()
vim.wo[win][0].foldexpr = 'v:lua.vim.lsp.foldexpr()'
@@ -2437,8 +2437,8 @@ enable({enable}, {filter}) *vim.lsp.on_type_formatting.enable()*
-- Enable for a specific client
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
local client_id = args.data.client_id
callback = function(ev)
local client_id = ev.data.client_id
local client = assert(vim.lsp.get_client_by_id(client_id))
if client.name == 'rust-analyzer' then
vim.lsp.on_type_formatting.enable(true, { client_id = client_id })
@@ -2629,11 +2629,11 @@ highlight_token({token}, {bufnr}, {client_id}, {hl_group}, {opts})
use inside |LspTokenUpdate| callbacks.
Parameters: ~
• {token} (`table`) A semantic token, found as `args.data.token` in
• {token} (`table`) Semantic token, provided as `ev.data.token` in
|LspTokenUpdate|
• {bufnr} (`integer`) The buffer to highlight, or `0` for current
buffer
• {client_id} (`integer`) The ID of the |vim.lsp.Client|
• {bufnr} (`integer`) Buffer to highlight, or `0` for current
buffer.
• {client_id} (`integer`) ID of the |vim.lsp.Client|
• {hl_group} (`string`) Highlight group name
• {opts} (`table?`) Optional parameters:
• {priority}? (`integer`, default:

View File

@@ -536,8 +536,8 @@ For example, this allows you to set buffer-local mappings for some filetypes:
>lua
vim.api.nvim_create_autocmd("FileType", {
pattern = "lua",
callback = function(args)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = args.buf })
callback = function(ev)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = ev.buf })
end
})
<

View File

@@ -226,10 +226,10 @@ from a |TermRequest| handler: >lua
})
local ns = vim.api.nvim_create_namespace('my.terminal.prompt')
vim.api.nvim_create_autocmd('TermRequest', {
callback = function(args)
if string.match(args.data.sequence, '^\027]133;A') then
local lnum = args.data.cursor[1]
vim.api.nvim_buf_set_extmark(args.buf, ns, lnum - 1, 0, {
callback = function(ev)
if string.match(ev.data.sequence, '^\027]133;A') then
local lnum = ev.data.cursor[1]
vim.api.nvim_buf_set_extmark(ev.buf, ns, lnum - 1, 0, {
sign_text = '▶',
sign_hl_group = 'SpecialChar',
})

View File

@@ -1165,9 +1165,9 @@ start({bufnr}, {lang}) *vim.treesitter.start()*
Example: >lua
vim.api.nvim_create_autocmd( 'FileType', { pattern = 'tex',
callback = function(args)
vim.treesitter.start(args.buf, 'latex')
vim.bo[args.buf].syntax = 'ON' -- only if additional legacy syntax is needed
callback = function(ev)
vim.treesitter.start(ev.buf, 'latex')
vim.bo[ev.buf].syntax = 'ON' -- only if additional legacy syntax is needed
end
})
<

View File

@@ -7,24 +7,24 @@ vim.api.nvim_create_augroup('filetypedetect', { clear = false })
vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile', 'StdinReadPost' }, {
group = 'filetypedetect',
callback = function(args)
if not vim.api.nvim_buf_is_valid(args.buf) then
callback = function(ev)
if not vim.api.nvim_buf_is_valid(ev.buf) then
return
end
local ft, on_detect, is_fallback = vim.filetype.match({
-- The unexpanded file name is needed here. #27914
-- However, bufname() can't be used, as it doesn't work with :doautocmd. #31306
filename = args.file,
buf = args.buf,
filename = ev.file,
buf = ev.buf,
})
if ft then
-- on_detect is called before setting the filetype so that it can set any buffer local
-- variables that may be used the filetype's ftplugin
if on_detect then
on_detect(args.buf)
on_detect(ev.buf)
end
vim._with({ buf = args.buf }, function()
vim._with({ buf = ev.buf }, function()
vim.api.nvim_cmd({
cmd = 'setf',
args = (is_fallback and { 'FALLBACK', ft } or { ft }),

View File

@@ -203,10 +203,10 @@ local function try_query_terminal_color(color)
local hex = nil
local au = vim.api.nvim_create_autocmd('TermResponse', {
once = true,
callback = function(args)
callback = function(ev)
hex = '#'
.. table.concat({
args.data.sequence:match('\027%]%d+;%d*;?rgb:(%w%w)%w%w/(%w%w)%w%w/(%w%w)%w%w'),
ev.data.sequence:match('\027%]%d+;%d*;?rgb:(%w%w)%w%w/(%w%w)%w%w/(%w%w)%w%w'),
})
end,
})

View File

@@ -566,14 +566,14 @@ do
group = nvim_terminal_augroup,
nested = true,
desc = 'Automatically close terminal buffers when started with no arguments and exiting without an error',
callback = function(args)
callback = function(ev)
if vim.v.event.status ~= 0 then
return
end
local info = vim.api.nvim_get_chan_info(vim.bo[args.buf].channel)
local info = vim.api.nvim_get_chan_info(vim.bo[ev.buf].channel)
local argv = info.argv or {}
if table.concat(argv, ' ') == vim.o.shell then
vim.api.nvim_buf_delete(args.buf, { force = true })
vim.api.nvim_buf_delete(ev.buf, { force = true })
end
end,
})
@@ -581,14 +581,14 @@ do
vim.api.nvim_create_autocmd('TermRequest', {
group = nvim_terminal_augroup,
desc = 'Handles OSC foreground/background color requests',
callback = function(args)
callback = function(ev)
--- @type integer
local channel = vim.bo[args.buf].channel
local channel = vim.bo[ev.buf].channel
if channel == 0 then
return
end
local fg_request = args.data.sequence == '\027]10;?'
local bg_request = args.data.sequence == '\027]11;?'
local fg_request = ev.data.sequence == '\027]10;?'
local bg_request = ev.data.sequence == '\027]11;?'
if fg_request or bg_request then
-- WARN: This does not return the actual foreground/background color,
-- but rather returns:
@@ -606,7 +606,7 @@ do
red,
green,
blue,
args.data.terminator
ev.data.terminator
)
vim.api.nvim_chan_send(channel, data)
end
@@ -617,12 +617,12 @@ do
vim.api.nvim_create_autocmd('TermRequest', {
group = nvim_terminal_augroup,
desc = 'Mark shell prompts indicated by OSC 133 sequences for navigation',
callback = function(args)
if string.match(args.data.sequence, '^\027]133;A') then
local lnum = args.data.cursor[1] ---@type integer
callback = function(ev)
if string.match(ev.data.sequence, '^\027]133;A') then
local lnum = ev.data.cursor[1] ---@type integer
if lnum >= 1 then
vim.api.nvim_buf_set_extmark(
args.buf,
ev.buf,
nvim_terminal_prompt_ns,
lnum - 1,
0,
@@ -669,11 +669,11 @@ do
vim.api.nvim_create_autocmd('TermOpen', {
group = nvim_terminal_augroup,
desc = 'Default settings for :terminal buffers',
callback = function(args)
vim.bo[args.buf].modifiable = false
vim.bo[args.buf].undolevels = -1
vim.bo[args.buf].scrollback = vim.o.scrollback < 0 and 10000 or math.max(1, vim.o.scrollback)
vim.bo[args.buf].textwidth = 0
callback = function(ev)
vim.bo[ev.buf].modifiable = false
vim.bo[ev.buf].undolevels = -1
vim.bo[ev.buf].scrollback = vim.o.scrollback < 0 and 10000 or math.max(1, vim.o.scrollback)
vim.bo[ev.buf].textwidth = 0
vim.wo[0][0].wrap = false
vim.wo[0][0].list = false
vim.wo[0][0].number = false
@@ -689,11 +689,11 @@ do
vim.wo[0][0].winhighlight = winhl .. 'StatusLine:StatusLineTerm,StatusLineNC:StatusLineTermNC'
vim.keymap.set({ 'n', 'x', 'o' }, '[[', function()
jump_to_prompt(nvim_terminal_prompt_ns, 0, args.buf, -vim.v.count1)
end, { buffer = args.buf, desc = 'Jump [count] shell prompts backward' })
jump_to_prompt(nvim_terminal_prompt_ns, 0, ev.buf, -vim.v.count1)
end, { buffer = ev.buf, desc = 'Jump [count] shell prompts backward' })
vim.keymap.set({ 'n', 'x', 'o' }, ']]', function()
jump_to_prompt(nvim_terminal_prompt_ns, 0, args.buf, vim.v.count1)
end, { buffer = args.buf, desc = 'Jump [count] shell prompts forward' })
jump_to_prompt(nvim_terminal_prompt_ns, 0, ev.buf, vim.v.count1)
end, { buffer = ev.buf, desc = 'Jump [count] shell prompts forward' })
end,
})
@@ -850,8 +850,8 @@ do
group = group,
nested = true,
desc = "Update the value of 'background' automatically based on the terminal emulator's background color",
callback = function(args)
local resp = args.data.sequence ---@type string
callback = function(ev)
local resp = ev.data.sequence ---@type string
-- DSR response that should come after the OSC 11 response if the
-- terminal supports it.
@@ -971,8 +971,8 @@ do
local id = vim.api.nvim_create_autocmd('TermResponse', {
group = group,
nested = true,
callback = function(args)
local resp = args.data.sequence ---@type string
callback = function(ev)
local resp = ev.data.sequence ---@type string
local decrqss = resp:match('^\027P1%$r([%d;:]+)m$')
if decrqss then

View File

@@ -670,8 +670,8 @@ local function check_sysinfo()
vim.api.nvim_create_autocmd('FileType', {
pattern = 'checkhealth',
once = true,
callback = function(args)
local buf = args.buf
callback = function(ev)
local buf = ev.buf
local win = vim.fn.bufwinid(buf)
if win == -1 then
return

View File

@@ -563,8 +563,8 @@ function lsp.enable(name, enable)
lsp_enable_autocmd_id = lsp_enable_autocmd_id
or api.nvim_create_autocmd('FileType', {
group = api.nvim_create_augroup('nvim.lsp.enable', {}),
callback = function(args)
lsp_enable_callback(args.buf)
callback = function(ev)
lsp_enable_callback(ev.buf)
end,
})
end
@@ -1431,8 +1431,8 @@ end
--- vim.o.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
--- -- Prefer LSP folding if client supports it
--- vim.api.nvim_create_autocmd('LspAttach', {
--- callback = function(args)
--- local client = vim.lsp.get_client_by_id(args.data.client_id)
--- callback = function(ev)
--- local client = vim.lsp.get_client_by_id(ev.data.client_id)
--- if client:supports_method('textDocument/foldingRange') then
--- local win = vim.api.nvim_get_current_win()
--- vim.wo[win][0].foldexpr = 'v:lua.vim.lsp.foldexpr()'
@@ -1452,9 +1452,9 @@ end
---
--- ```lua
--- vim.api.nvim_create_autocmd('LspNotify', {
--- callback = function(args)
--- if args.data.method == 'textDocument/didOpen' then
--- vim.lsp.foldclose('imports', vim.fn.bufwinid(args.buf))
--- callback = function(ev)
--- if ev.data.method == 'textDocument/didOpen' then
--- vim.lsp.foldclose('imports', vim.fn.bufwinid(ev.buf))
--- end
--- end,
--- })

View File

@@ -231,14 +231,11 @@ function State:new(bufnr)
api.nvim_create_autocmd('LspNotify', {
group = self.augroup,
buffer = bufnr,
callback = function(args)
local client = assert(vim.lsp.get_client_by_id(args.data.client_id))
callback = function(ev)
local client = assert(vim.lsp.get_client_by_id(ev.data.client_id))
if
client:supports_method('textDocument/foldingRange', bufnr)
and (
args.data.method == 'textDocument/didChange'
or args.data.method == 'textDocument/didOpen'
)
and (ev.data.method == 'textDocument/didChange' or ev.data.method == 'textDocument/didOpen')
then
self:refresh(client)
end

View File

@@ -768,7 +768,7 @@ local function on_completechanged(group, bufnr)
api.nvim_create_autocmd('CompleteChanged', {
group = group,
buffer = bufnr,
callback = function(args)
callback = function(ev)
local completed_item = vim.v.event.completed_item or {}
if (completed_item.info or '') ~= '' then
local data = vim.fn.complete_info({ 'selected' })
@@ -780,7 +780,7 @@ local function on_completechanged(group, bufnr)
#lsp.get_clients({
id = vim.tbl_get(completed_item, 'user_data', 'nvim', 'lsp', 'client_id'),
method = 'completionItem/resolve',
bufnr = args.buf,
bufnr = ev.buf,
}) == 0
then
return
@@ -791,7 +791,7 @@ local function on_completechanged(group, bufnr)
local param = vim.tbl_get(completed_item, 'user_data', 'nvim', 'lsp', 'completion_item')
if param then
Context.resolve_handler = Context.resolve_handler or CompletionResolver.new()
Context.resolve_handler:request(args.buf, param, completed_item.word)
Context.resolve_handler:request(ev.buf, param, completed_item.word)
end
end,
desc = 'Request and display LSP completion item documentation via completionItem/resolve',
@@ -1121,8 +1121,8 @@ local function enable_completions(client_id, bufnr, opts)
group = group,
buffer = bufnr,
desc = 'vim.lsp.completion: clean up client on detach',
callback = function(args)
disable_completions(args.data.client_id, args.buf)
callback = function(ev)
disable_completions(ev.data.client_id, ev.buf)
end,
})

View File

@@ -460,12 +460,12 @@ function M._enable(bufnr)
api.nvim_create_autocmd('LspDetach', {
buffer = bufnr,
callback = function(args)
callback = function(ev)
local clients = lsp.get_clients({ bufnr = bufnr, method = 'textDocument/diagnostic' })
if
not vim.iter(clients):any(function(c)
return c.id ~= args.data.client_id
return c.id ~= ev.data.client_id
end)
then
disable(bufnr)

View File

@@ -218,14 +218,14 @@ local function buf_enable(bufnr)
buffer = bufnr,
group = document_color_augroup,
desc = 'Refresh document_color on document changes',
callback = function(args)
local method = args.data.method --- @type string
callback = function(ev)
local method = ev.data.method --- @type string
if
(method == 'textDocument/didChange' or method == 'textDocument/didOpen')
and assert(bufstates[args.buf]).enabled
and assert(bufstates[ev.buf]).enabled
then
M._buf_refresh(args.buf, args.data.client_id)
M._buf_refresh(ev.buf, ev.data.client_id)
end
end,
})
@@ -234,16 +234,16 @@ local function buf_enable(bufnr)
buffer = bufnr,
group = document_color_augroup,
desc = 'Disable document_color if all supporting clients detach',
callback = function(args)
local clients = lsp.get_clients({ bufnr = args.buf, method = 'textDocument/documentColor' })
callback = function(ev)
local clients = lsp.get_clients({ bufnr = ev.buf, method = 'textDocument/documentColor' })
if
not vim.iter(clients):any(function(c)
return c.id ~= args.data.client_id
return c.id ~= ev.data.client_id
end)
then
-- There are no clients left in the buffer that support document color, so turn it off.
buf_disable(args.buf)
buf_disable(ev.buf)
end
end,
})

View File

@@ -264,26 +264,23 @@ local function _enable(bufnr)
end
api.nvim_create_autocmd('LspNotify', {
callback = function(args)
callback = function(ev)
---@type integer
local bufnr = args.buf
local bufnr = ev.buf
if
args.data.method ~= 'textDocument/didChange'
and args.data.method ~= 'textDocument/didOpen'
then
if ev.data.method ~= 'textDocument/didChange' and ev.data.method ~= 'textDocument/didOpen' then
return
end
if bufstates[bufnr].enabled then
refresh(bufnr, args.data.client_id)
refresh(bufnr, ev.data.client_id)
end
end,
group = augroup,
})
api.nvim_create_autocmd('LspAttach', {
callback = function(args)
callback = function(ev)
---@type integer
local bufnr = args.buf
local bufnr = ev.buf
api.nvim_buf_attach(bufnr, false, {
on_reload = function(_, cb_bufnr)
@@ -302,13 +299,13 @@ api.nvim_create_autocmd('LspAttach', {
group = augroup,
})
api.nvim_create_autocmd('LspDetach', {
callback = function(args)
callback = function(ev)
---@type integer
local bufnr = args.buf
local bufnr = ev.buf
local clients = vim.lsp.get_clients({ bufnr = bufnr, method = 'textDocument/inlayHint' })
if not vim.iter(clients):any(function(c)
return c.id ~= args.data.client_id
return c.id ~= ev.data.client_id
end) then
_disable(bufnr)
end

View File

@@ -222,8 +222,8 @@ function LinkedEditor.new(bufnr)
api.nvim_create_autocmd('LspDetach', {
group = augroup,
buffer = bufnr,
callback = function(args)
self:detach(args.data.client_id)
callback = function(ev)
self:detach(ev.data.client_id)
end,
})

View File

@@ -161,8 +161,8 @@ local function attach(client, bufnr)
buffer = bufnr,
desc = 'Detach on-type formatting module when the client detaches',
group = augroup,
callback = function(args)
local detached_client = assert(lsp.get_client_by_id(args.data.client_id))
callback = function(ev)
local detached_client = assert(lsp.get_client_by_id(ev.data.client_id))
detach(detached_client, bufnr)
end,
})
@@ -230,8 +230,8 @@ end
---
--- -- Enable for a specific client
--- vim.api.nvim_create_autocmd('LspAttach', {
--- callback = function(args)
--- local client_id = args.data.client_id
--- callback = function(ev)
--- local client_id = ev.data.client_id
--- local client = assert(vim.lsp.get_client_by_id(client_id))
--- if client.name == 'rust-analyzer' then
--- vim.lsp.on_type_formatting.enable(true, { client_id = client_id })

View File

@@ -1010,9 +1010,9 @@ end
--- mark will be deleted by the semantic token engine when appropriate; for
--- example, when the LSP sends updated tokens. This function is intended for
--- use inside |LspTokenUpdate| callbacks.
---@param token (table) A semantic token, found as `args.data.token` in |LspTokenUpdate|
---@param bufnr (integer) The buffer to highlight, or `0` for current buffer
---@param client_id (integer) The ID of the |vim.lsp.Client|
---@param token (table) Semantic token, provided as `ev.data.token` in |LspTokenUpdate|
---@param bufnr (integer) Buffer to highlight, or `0` for current buffer.
---@param client_id (integer) ID of the |vim.lsp.Client|
---@param hl_group (string) Highlight group name
---@param opts? vim.lsp.semantic_tokens.highlight_token.Opts Optional parameters:
function M.highlight_token(token, bufnr, client_id, hl_group, opts)

View File

@@ -33,8 +33,8 @@ function M.query(caps, cb)
local id = vim.api.nvim_create_autocmd('TermResponse', {
nested = true,
callback = function(args)
local resp = args.data.sequence ---@type string
callback = function(ev)
local resp = ev.data.sequence ---@type string
local k, rest = resp:match('^\027P1%+r(%x+)(.*)$')
if k and rest then
local cap = vim.text.hexdecode(k)

View File

@@ -438,9 +438,9 @@ end
---
--- ```lua
--- vim.api.nvim_create_autocmd( 'FileType', { pattern = 'tex',
--- callback = function(args)
--- vim.treesitter.start(args.buf, 'latex')
--- vim.bo[args.buf].syntax = 'ON' -- only if additional legacy syntax is needed
--- callback = function(ev)
--- vim.treesitter.start(ev.buf, 'latex')
--- vim.bo[ev.buf].syntax = 'ON' -- only if additional legacy syntax is needed
--- end
--- })
--- ```

View File

@@ -23,8 +23,8 @@ function M.paste(reg)
return function()
local contents = nil --- @type string?
local id = vim.api.nvim_create_autocmd('TermResponse', {
callback = function(args)
local resp = args.data.sequence ---@type string
callback = function(ev)
local resp = ev.data.sequence ---@type string
local encoded = resp:match('\027%]52;%w?;([A-Za-z0-9+/=]*)')
if encoded then
contents = vim.base64.decode(encoded)

View File

@@ -447,20 +447,20 @@ function M.open(left, right, opt)
vim.api.nvim_create_autocmd('BufWinEnter', {
group = layout.group,
pattern = 'quickfix',
callback = function(args)
callback = function(ev)
if not get_diff_entry() then
return
end
vim.api.nvim_buf_clear_namespace(args.buf, hl_id, 0, -1)
local lines = vim.api.nvim_buf_get_lines(args.buf, 0, -1, false)
vim.api.nvim_buf_clear_namespace(ev.buf, hl_id, 0, -1)
local lines = vim.api.nvim_buf_get_lines(ev.buf, 0, -1, false)
-- Map status codes to highlight groups
for i, line in ipairs(lines) do
local status = line:match('^(%a) ')
local hl_group = highlight_groups[status]
if hl_group then
vim.hl.range(args.buf, hl_id, hl_group, { i - 1, 0 }, { i - 1, 1 })
vim.hl.range(ev.buf, hl_id, hl_group, { i - 1, 0 }, { i - 1, 1 })
end
end
end,
@@ -469,8 +469,8 @@ function M.open(left, right, opt)
vim.api.nvim_create_autocmd('BufWinEnter', {
group = layout.group,
pattern = '*',
callback = function(args)
local entry = get_diff_entry(args.buf)
callback = function(ev)
local entry = get_diff_entry(ev.buf)
if not entry then
return
end

View File

@@ -1,13 +1,13 @@
local group = vim.api.nvim_create_augroup('nvim.editorconfig', {})
vim.api.nvim_create_autocmd({ 'BufNewFile', 'BufRead', 'BufFilePost' }, {
group = group,
callback = function(args)
callback = function(ev)
-- Buffer-local enable has higher priority
local enable = vim.F.if_nil(vim.b.editorconfig, vim.g.editorconfig, true)
if not enable then
return
end
require('editorconfig').config(args.buf)
require('editorconfig').config(ev.buf)
end,
})

View File

@@ -1,8 +1,8 @@
vim.g.loaded_remote_file_loader = true
--- Callback for BufReadCmd on remote URLs.
--- @param args { buf: integer }
local function on_remote_read(args)
--- @param ev { buf: integer }
local function on_remote_read(ev)
if vim.fn.executable('curl') ~= 1 then
vim.api.nvim_echo({
{ 'Warning: `curl` not found; remote URL loading disabled.', 'WarningMsg' },
@@ -10,7 +10,7 @@ local function on_remote_read(args)
return true
end
local bufnr = args.buf
local bufnr = ev.buf
local url = vim.api.nvim_buf_get_name(bufnr)
local view = vim.fn.winsaveview()

View File

@@ -36,8 +36,8 @@ vim.api.nvim_create_autocmd('UIEnter', {
vim.api.nvim_create_autocmd('TermResponse', {
group = id,
nested = true,
callback = function(args)
local resp = args.data.sequence ---@type string
callback = function(ev)
local resp = ev.data.sequence ---@type string
local params = resp:match('^\027%[%?([%d;]+)c$')
if params then
-- Check termfeatures again, it may have changed between the query and response.

View File

@@ -351,8 +351,8 @@ describe('autocmd api', function()
local output
vim.api.nvim_create_autocmd("User", {
pattern = "Test",
callback = function(args)
output = args.data
callback = function(ev)
output = ev.data
end,
})

View File

@@ -1776,14 +1776,10 @@ describe('nvim_buf_attach on_detach', function()
it('called before buf_freeall autocommands', function()
exec_lua(function()
vim.api.nvim_create_autocmd({ 'BufUnload', 'BufDelete', 'BufWipeout' }, {
callback = function(args)
callback = function(ev)
table.insert(
_G.events,
('%s: %d %s'):format(
args.event,
args.buf,
tostring(vim.api.nvim_buf_is_loaded(args.buf))
)
('%s: %d %s'):format(ev.event, ev.buf, tostring(vim.api.nvim_buf_is_loaded(ev.buf)))
)
end,
})

View File

@@ -2877,9 +2877,9 @@ describe('vim.diagnostic', function()
local changed_diags --- @type vim.Diagnostic[]?
vim.api.nvim_create_autocmd('DiagnosticChanged', {
buffer = _G.diagnostic_bufnr,
callback = function(args)
callback = function(ev)
--- @type vim.Diagnostic[]
changed_diags = args.data.diagnostics
changed_diags = ev.data.diagnostics
end,
})
vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, {})
@@ -4322,8 +4322,8 @@ describe('vim.diagnostic', function()
local triggered = {}
vim.api.nvim_create_autocmd('DiagnosticChanged', {
callback = function(args)
triggered = { args.buf, #args.data.diagnostics }
callback = function(ev)
triggered = { ev.buf, #ev.data.diagnostics }
end,
})
vim.api.nvim_buf_set_name(_G.diagnostic_bufnr, 'test | test')

View File

@@ -501,10 +501,10 @@ describe('semantic token highlighting', function()
insert(text)
exec_lua(function()
vim.api.nvim_create_autocmd('LspTokenUpdate', {
callback = function(args)
local token = args.data.token --- @type STTokenRange
callback = function(ev)
local token = ev.data.token --- @type STTokenRange
if token.type == 'function' and token.modifiers.declaration then
vim.lsp.semantic_tokens.highlight_token(token, args.buf, args.data.client_id, 'Macro')
vim.lsp.semantic_tokens.highlight_token(token, ev.buf, ev.data.client_id, 'Macro')
end
end,
})

View File

@@ -408,14 +408,14 @@ describe('LSP', function()
exec_lua(function()
_G.BUFFER = vim.api.nvim_create_buf(false, true)
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(args)
local client0 = assert(vim.lsp.get_client_by_id(args.data.client_id))
callback = function(ev)
local client0 = assert(vim.lsp.get_client_by_id(ev.data.client_id))
vim.g.lsp_attached = client0.name
end,
})
vim.api.nvim_create_autocmd('LspDetach', {
callback = function(args)
local client0 = assert(vim.lsp.get_client_by_id(args.data.client_id))
callback = function(ev)
local client0 = assert(vim.lsp.get_client_by_id(ev.data.client_id))
vim.g.lsp_detached = client0.name
end,
})

View File

@@ -422,12 +422,12 @@ describe(':terminal buffer', function()
exec_lua(function()
_G.last_event = nil
vim.api.nvim_create_autocmd({ 'TermEnter', 'TermLeave' }, {
callback = function(args)
_G.last_event = args.event
callback = function(ev)
_G.last_event = ev.event
.. ' '
.. vim.fs.basename(args.file)
.. vim.fs.basename(ev.file)
.. ' '
.. tostring(vim.b[args.buf].term_focused)
.. tostring(vim.b[ev.buf].term_focused)
end,
})
end)
@@ -706,8 +706,8 @@ describe(':terminal buffer', function()
force_crlf = false,
})
vim.api.nvim_create_autocmd('TermRequest', {
callback = function(args)
if args.data.sequence == '\027]11;?' then
callback = function(ev)
if ev.data.sequence == '\027]11;?' then
table.insert(_G.input, '\027]11;rgb:0000/0000/0000\027\\')
end
end
@@ -758,8 +758,8 @@ describe(':terminal buffer', function()
_G.cursor = {}
local term = vim.api.nvim_open_term(0, {})
vim.api.nvim_create_autocmd('TermRequest', {
callback = function(args)
_G.cursor = args.data.cursor
callback = function(ev)
_G.cursor = ev.data.cursor
end
})
return term

View File

@@ -67,8 +67,8 @@ describe(':terminal', function()
local chan = api.nvim_open_term(0, {})
exec_lua([[
vim.api.nvim_create_autocmd("TermRequest", {
callback = function(args)
_G.osc10_response = {sequence = args.data.sequence, terminator = args.data.terminator }
callback = function(ev)
_G.osc10_response = {sequence = ev.data.sequence, terminator = ev.data.terminator }
end
})
]])

View File

@@ -2672,8 +2672,8 @@ describe('TUI', function()
_G.urls = {}
vim.api.nvim_create_autocmd('TermRequest', {
buffer = buf,
callback = function(args)
local req = args.data.sequence
callback = function(ev)
local req = ev.data.sequence
if not req then
return
end
@@ -3733,14 +3733,14 @@ describe('TUI', function()
clear()
exec_lua([[
vim.api.nvim_create_autocmd('TermRequest', {
callback = function(args)
local req = args.data.sequence
callback = function(ev)
local req = ev.data.sequence
local sequence = req:match('^\027P%+q([%x;]+)$')
if sequence then
local t = {}
for cap in vim.gsplit(sequence, ';') do
local resp = string.format('\027P1+r%s\027\\', sequence)
vim.api.nvim_chan_send(vim.bo[args.buf].channel, resp)
vim.api.nvim_chan_send(vim.bo[ev.buf].channel, resp)
t[vim.text.hexdecode(cap)] = true
end
vim.g.xtgettcap = t
@@ -3784,15 +3784,15 @@ describe('TUI', function()
clear()
exec_lua([[
vim.api.nvim_create_autocmd('TermRequest', {
callback = function(args)
local req = args.data.sequence
callback = function(ev)
local req = ev.data.sequence
vim.g.termrequest = req
local xtgettcap = req:match('^\027P%+q([%x;]+)$')
if xtgettcap then
local t = {}
for cap in vim.gsplit(xtgettcap, ';') do
local resp = string.format('\027P1+r%s\027\\', xtgettcap)
vim.api.nvim_chan_send(vim.bo[args.buf].channel, resp)
vim.api.nvim_chan_send(vim.bo[ev.buf].channel, resp)
t[vim.text.hexdecode(cap)] = true
end
vim.g.xtgettcap = t
@@ -3852,12 +3852,12 @@ describe('TUI', function()
exec_lua([[
_G.query = false
vim.api.nvim_create_autocmd('TermRequest', {
callback = function(args)
local req = args.data.sequence
callback = function(ev)
local req = ev.data.sequence
local sequence = req:match('^\027P%+q([%x;]+)$')
if sequence and vim.text.hexdecode(sequence) == 'Ms' then
local resp = string.format('\027P1+r%s=%s\027\\', sequence, vim.text.hexencode('\027]52;;\027\\'))
vim.api.nvim_chan_send(vim.bo[args.buf].channel, resp)
vim.api.nvim_chan_send(vim.bo[ev.buf].channel, resp)
_G.query = true
return true
end
@@ -3908,8 +3908,8 @@ describe('TUI', function()
-- Check that we do not emit an XTGETTCAP request when DA1 indicates support
_G.query = false
vim.api.nvim_create_autocmd('TermRequest', {
callback = function(args)
local req = args.data.sequence
callback = function(ev)
local req = ev.data.sequence
local sequence = req:match('^\027P%+q([%x;]+)$')
if sequence and vim.text.hexdecode(sequence) == 'Ms' then
_G.query = true
@@ -3944,8 +3944,8 @@ describe('TUI', function()
exec_lua([[
_G.query = false
vim.api.nvim_create_autocmd('TermRequest', {
callback = function(args)
local req = args.data.sequence
callback = function(ev)
local req = ev.data.sequence
local sequence = req:match('^\027P%+q([%x;]+)$')
if sequence and vim.text.hexdecode(sequence) == 'Ms' then
_G.query = true
@@ -4026,8 +4026,8 @@ describe('TUI bg color', function()
it('queries the terminal for background color', function()
exec_lua([[
vim.api.nvim_create_autocmd('TermRequest', {
callback = function(args)
local req = args.data.sequence
callback = function(ev)
local req = ev.data.sequence
if req == '\027]11;?' then
vim.g.oscrequest = true
return true