refactor(api)!: use singular/plural consistently in the autocmd API

This commit is contained in:
György Andorka 2022-03-31 19:13:22 +02:00 committed by Christian Clason
parent ea8ad79990
commit 9d40b2fda9
4 changed files with 34 additions and 32 deletions

View File

@ -3151,7 +3151,7 @@ nvim_tabpage_set_var({tabpage}, {name}, {value})
============================================================================== ==============================================================================
Autocmd Functions *api-autocmd* Autocmd Functions *api-autocmd*
nvim_clear_autocmd({*opts}) *nvim_clear_autocmd()* nvim_clear_autocmds({*opts}) *nvim_clear_autocmds()*
Clear all autocommands that match the corresponding {opts}. To Clear all autocommands that match the corresponding {opts}. To
delete a particular autocmd, see |nvim_del_autocmd|. delete a particular autocmd, see |nvim_del_autocmd|.
@ -3310,8 +3310,9 @@ nvim_del_autocmd({id}) *nvim_del_autocmd()*
See also: ~ See also: ~
|nvim_create_autocmd()| |nvim_create_autocmd()|
nvim_exec_autocmd({event}, {*opts}) *nvim_exec_autocmd()* nvim_exec_autocmds({event}, {*opts}) *nvim_exec_autocmds()*
Execute an autocommand |autocmd-execute|. Execute all autocommands for {event} that match the
corresponding {opts} |autocmd-execute|.
Parameters: ~ Parameters: ~
{event} (String|Array) The event or events to execute {event} (String|Array) The event or events to execute
@ -3333,7 +3334,7 @@ nvim_exec_autocmd({event}, {*opts}) *nvim_exec_autocmd()*
|:doautocmd| |:doautocmd|
nvim_get_autocmds({*opts}) *nvim_get_autocmds()* nvim_get_autocmds({*opts}) *nvim_get_autocmds()*
Get autocommands that match the requirements passed to {opts}. Get all autocommands that match the corresponding {opts}.
These examples will get autocommands matching ALL the given These examples will get autocommands matching ALL the given
criteria: > criteria: >

View File

@ -36,7 +36,7 @@
// Used to delete autocmds from nvim_del_autocmd // Used to delete autocmds from nvim_del_autocmd
static int64_t next_autocmd_id = 1; static int64_t next_autocmd_id = 1;
/// Get autocommands that match the requirements passed to {opts}. /// Get all autocommands that match the corresponding {opts}.
/// ///
/// These examples will get autocommands matching ALL the given criteria: /// These examples will get autocommands matching ALL the given criteria:
/// <pre> /// <pre>
@ -562,7 +562,7 @@ void nvim_del_autocmd(Integer id)
/// - group: (string|int) The augroup name or id. /// - group: (string|int) The augroup name or id.
/// - NOTE: If not passed, will only delete autocmds *not* in any group. /// - NOTE: If not passed, will only delete autocmds *not* in any group.
/// ///
void nvim_clear_autocmd(Dict(clear_autocmd) *opts, Error *err) void nvim_clear_autocmds(Dict(clear_autocmds) *opts, Error *err)
FUNC_API_SINCE(9) FUNC_API_SINCE(9)
{ {
// TODO(tjdevries): Future improvements: // TODO(tjdevries): Future improvements:
@ -697,7 +697,8 @@ void nvim_del_augroup_by_name(String name)
augroup_del(name.data, false); augroup_del(name.data, false);
} }
/// Execute an autocommand |autocmd-execute|. /// Execute all autocommands for {event} that match the corresponding
/// {opts} |autocmd-execute|.
/// @param event (String|Array) The event or events to execute /// @param event (String|Array) The event or events to execute
/// @param opts Dictionary of autocommand options: /// @param opts Dictionary of autocommand options:
/// - group (string|integer) optional: the autocommand group name or /// - group (string|integer) optional: the autocommand group name or
@ -709,7 +710,7 @@ void nvim_del_augroup_by_name(String name)
/// - modeline (bool) optional: defaults to true. Process the /// - modeline (bool) optional: defaults to true. Process the
/// modeline after the autocommands |<nomodeline>|. /// modeline after the autocommands |<nomodeline>|.
/// @see |:doautocmd| /// @see |:doautocmd|
void nvim_exec_autocmd(Object event, Dict(exec_autocmd) *opts, Error *err) void nvim_exec_autocmds(Object event, Dict(exec_autocmds) *opts, Error *err)
FUNC_API_SINCE(9) FUNC_API_SINCE(9)
{ {
int au_group = AUGROUP_ALL; int au_group = AUGROUP_ALL;

View File

@ -123,7 +123,7 @@ return {
"nocombine"; "nocombine";
}; };
-- Autocmds -- Autocmds
clear_autocmd = { clear_autocmds = {
"buffer"; "buffer";
"event"; "event";
"group"; "group";
@ -139,7 +139,7 @@ return {
"once"; "once";
"pattern"; "pattern";
}; };
exec_autocmd = { exec_autocmds = {
"buffer"; "buffer";
"group"; "group";
"modeline"; "modeline";

View File

@ -168,7 +168,7 @@ describe('autocmd api', function()
}) })
]] ]]
meths.exec_autocmd("User", {pattern = "Test"}) meths.exec_autocmds("User", {pattern = "Test"})
eq({{ eq({{
buflocal = false, buflocal = false,
command = 'A test autocommand', command = 'A test autocommand',
@ -179,7 +179,7 @@ describe('autocmd api', function()
pattern = 'Test', pattern = 'Test',
}}, meths.get_autocmds({event = "User", pattern = "Test"})) }}, meths.get_autocmds({event = "User", pattern = "Test"}))
meths.set_var("some_condition", true) meths.set_var("some_condition", true)
meths.exec_autocmd("User", {pattern = "Test"}) meths.exec_autocmds("User", {pattern = "Test"})
eq({}, meths.get_autocmds({event = "User", pattern = "Test"})) eq({}, meths.get_autocmds({event = "User", pattern = "Test"}))
end) end)
end) end)
@ -517,7 +517,7 @@ describe('autocmd api', function()
end) end)
end) end)
describe('nvim_exec_autocmd', function() describe('nvim_exec_autocmds', function()
it("can trigger builtin autocmds", function() it("can trigger builtin autocmds", function()
meths.set_var("autocmd_executed", false) meths.set_var("autocmd_executed", false)
@ -527,7 +527,7 @@ describe('autocmd api', function()
}) })
eq(false, meths.get_var("autocmd_executed")) eq(false, meths.get_var("autocmd_executed"))
meths.exec_autocmd("BufReadPost", {}) meths.exec_autocmds("BufReadPost", {})
eq(true, meths.get_var("autocmd_executed")) eq(true, meths.get_var("autocmd_executed"))
end) end)
@ -541,10 +541,10 @@ describe('autocmd api', function()
}) })
-- Doesn't execute for other non-matching events -- Doesn't execute for other non-matching events
meths.exec_autocmd("CursorHold", { buffer = 1 }) meths.exec_autocmds("CursorHold", { buffer = 1 })
eq(-1, meths.get_var("buffer_executed")) eq(-1, meths.get_var("buffer_executed"))
meths.exec_autocmd("BufLeave", { buffer = 1 }) meths.exec_autocmds("BufLeave", { buffer = 1 })
eq(1, meths.get_var("buffer_executed")) eq(1, meths.get_var("buffer_executed"))
end) end)
@ -558,7 +558,7 @@ describe('autocmd api', function()
}) })
-- Doesn't execute for other non-matching events -- Doesn't execute for other non-matching events
meths.exec_autocmd("CursorHold", { buffer = 1 }) meths.exec_autocmds("CursorHold", { buffer = 1 })
eq('none', meths.get_var("filename_executed")) eq('none', meths.get_var("filename_executed"))
meths.command('edit __init__.py') meths.command('edit __init__.py')
@ -566,7 +566,7 @@ describe('autocmd api', function()
end) end)
it('cannot pass buf and fname', function() it('cannot pass buf and fname', function()
local ok = pcall(meths.exec_autocmd, "BufReadPre", { pattern = "literally_cannot_error.rs", buffer = 1 }) local ok = pcall(meths.exec_autocmds, "BufReadPre", { pattern = "literally_cannot_error.rs", buffer = 1 })
eq(false, ok) eq(false, ok)
end) end)
@ -584,16 +584,16 @@ describe('autocmd api', function()
}) })
-- Doesn't execute for other non-matching events -- Doesn't execute for other non-matching events
meths.exec_autocmd("CursorHoldI", { buffer = 1 }) meths.exec_autocmds("CursorHoldI", { buffer = 1 })
eq('none', meths.get_var("filename_executed")) eq('none', meths.get_var("filename_executed"))
meths.exec_autocmd("CursorHoldI", { buffer = tonumber(meths.get_current_buf()) }) meths.exec_autocmds("CursorHoldI", { buffer = tonumber(meths.get_current_buf()) })
eq('__init__.py', meths.get_var("filename_executed")) eq('__init__.py', meths.get_var("filename_executed"))
-- Reset filename -- Reset filename
meths.set_var("filename_executed", 'none') meths.set_var("filename_executed", 'none')
meths.exec_autocmd("CursorHoldI", { pattern = '__init__.py' }) meths.exec_autocmds("CursorHoldI", { pattern = '__init__.py' })
eq('__init__.py', meths.get_var("filename_executed")) eq('__init__.py', meths.get_var("filename_executed"))
end) end)
@ -605,9 +605,9 @@ describe('autocmd api', function()
command = 'let g:matched = "matched"' command = 'let g:matched = "matched"'
}) })
meths.exec_autocmd("User", { pattern = "OtherCommand" }) meths.exec_autocmds("User", { pattern = "OtherCommand" })
eq('none', meths.get_var('matched')) eq('none', meths.get_var('matched'))
meths.exec_autocmd("User", { pattern = "TestCommand" }) meths.exec_autocmds("User", { pattern = "TestCommand" })
eq('matched', meths.get_var('matched')) eq('matched', meths.get_var('matched'))
end) end)
@ -621,7 +621,7 @@ describe('autocmd api', function()
}) })
eq(false, meths.get_var("group_executed")) eq(false, meths.get_var("group_executed"))
meths.exec_autocmd("FileType", { group = auid }) meths.exec_autocmds("FileType", { group = auid })
eq(true, meths.get_var("group_executed")) eq(true, meths.get_var("group_executed"))
end) end)
@ -636,7 +636,7 @@ describe('autocmd api', function()
}) })
eq(false, meths.get_var("group_executed")) eq(false, meths.get_var("group_executed"))
meths.exec_autocmd("FileType", { group = auname }) meths.exec_autocmds("FileType", { group = auname })
eq(true, meths.get_var("group_executed")) eq(true, meths.get_var("group_executed"))
end) end)
end) end)
@ -973,7 +973,7 @@ describe('autocmd api', function()
end) end)
end) end)
describe('nvim_clear_autocmd', function() describe('nvim_clear_autocmds', function()
it('should clear based on event + pattern', function() it('should clear based on event + pattern', function()
command('autocmd InsertEnter *.py :echo "Python can be cool sometimes"') command('autocmd InsertEnter *.py :echo "Python can be cool sometimes"')
command('autocmd InsertEnter *.txt :echo "Text Files Are Cool"') command('autocmd InsertEnter *.txt :echo "Text Files Are Cool"')
@ -985,7 +985,7 @@ describe('autocmd api', function()
local before_delete_all = meths.get_autocmds { event = search.event } local before_delete_all = meths.get_autocmds { event = search.event }
eq(2, #before_delete_all) eq(2, #before_delete_all)
meths.clear_autocmd(search) meths.clear_autocmds(search)
local after_delete = meths.get_autocmds(search) local after_delete = meths.get_autocmds(search)
eq(0, #after_delete) eq(0, #after_delete)
@ -1001,7 +1001,7 @@ describe('autocmd api', function()
local before_delete = meths.get_autocmds(search) local before_delete = meths.get_autocmds(search)
eq(2, #before_delete) eq(2, #before_delete)
meths.clear_autocmd(search) meths.clear_autocmds(search)
local after_delete = meths.get_autocmds(search) local after_delete = meths.get_autocmds(search)
eq(0, #after_delete) eq(0, #after_delete)
end) end)
@ -1018,7 +1018,7 @@ describe('autocmd api', function()
local before_delete_events = meths.get_autocmds { event = { "InsertEnter", "InsertLeave" } } local before_delete_events = meths.get_autocmds { event = { "InsertEnter", "InsertLeave" } }
eq(4, #before_delete_events) eq(4, #before_delete_events)
meths.clear_autocmd(search) meths.clear_autocmds(search)
local after_delete = meths.get_autocmds(search) local after_delete = meths.get_autocmds(search)
eq(0, #after_delete) eq(0, #after_delete)
@ -1035,7 +1035,7 @@ describe('autocmd api', function()
local before_delete = meths.get_autocmds(search) local before_delete = meths.get_autocmds(search)
eq(2, #before_delete) eq(2, #before_delete)
meths.clear_autocmd { buffer = 0 } meths.clear_autocmds { buffer = 0 }
local after_delete = meths.get_autocmds(search) local after_delete = meths.get_autocmds(search)
eq(1, #after_delete) eq(1, #after_delete)
eq("*.TestPat1", after_delete[1].pattern) eq("*.TestPat1", after_delete[1].pattern)
@ -1053,12 +1053,12 @@ describe('autocmd api', function()
eq(2, #before_delete) eq(2, #before_delete)
-- Doesn't clear without passing group. -- Doesn't clear without passing group.
meths.clear_autocmd { buffer = 0 } meths.clear_autocmds { buffer = 0 }
local without_group = meths.get_autocmds(search) local without_group = meths.get_autocmds(search)
eq(2, #without_group) eq(2, #without_group)
-- Doest clear with passing group. -- Doest clear with passing group.
meths.clear_autocmd { buffer = 0, group = search.group } meths.clear_autocmds { buffer = 0, group = search.group }
local with_group = meths.get_autocmds(search) local with_group = meths.get_autocmds(search)
eq(1, #with_group) eq(1, #with_group)
end) end)