+33
-8
lines changedFilter options
+33
-8
lines changed Original file line number Diff line number Diff line change
@@ -609,10 +609,16 @@ Integer nvim_create_autocmd(uint64_t channel_id, Object event, Dict(create_autoc
609
609
/// NOTE: Only autocommands created via the API have an id.
610
610
/// @param id Integer The id returned by nvim_create_autocmd
611
611
/// @see |nvim_create_autocmd()|
612
-
void nvim_del_autocmd(Integer id)
612
+
void nvim_del_autocmd(Integer id, Error *err)
613
613
FUNC_API_SINCE(9)
614
614
{
615
-
autocmd_delete_id(id);
615
+
if (id <= 0) {
616
+
api_set_error(err, kErrorTypeException, "Invalid autocmd id");
617
+
return;
618
+
}
619
+
if (!autocmd_delete_id(id)) {
620
+
api_set_error(err, kErrorTypeException, "Failed to delete autocmd");
621
+
}
616
622
}
617
623
618
624
/// Create or get an autocommand group |autocmd-groups|.
@@ -664,11 +670,15 @@ Integer nvim_create_augroup(uint64_t channel_id, String name, Dict(create_augrou
664
670
/// @param id Integer The id of the group.
665
671
/// @see |nvim_del_augroup_by_name()|
666
672
/// @see |nvim_create_augroup()|
667
-
void nvim_del_augroup_by_id(Integer id)
673
+
void nvim_del_augroup_by_id(Integer id, Error *err)
668
674
FUNC_API_SINCE(9)
669
675
{
670
-
char *name = augroup_name((int)id);
671
-
augroup_del(name, false);
676
+
TRY_WRAP({
677
+
try_start();
678
+
char *name = augroup_name((int)id);
679
+
augroup_del(name, false);
680
+
try_end(err);
681
+
});
672
682
}
673
683
674
684
/// Delete an autocommand group by name.
@@ -677,10 +687,14 @@ void nvim_del_augroup_by_id(Integer id)
677
687
/// this group will also be deleted and cleared. This group will no longer exist.
678
688
/// @param name String The name of the group.
679
689
/// @see |autocommand-groups|
680
-
void nvim_del_augroup_by_name(String name)
690
+
void nvim_del_augroup_by_name(String name, Error *err)
681
691
FUNC_API_SINCE(9)
682
692
{
683
-
augroup_del(name.data, false);
693
+
TRY_WRAP({
694
+
try_start();
695
+
augroup_del(name.data, false);
696
+
try_end(err);
697
+
});
684
698
}
685
699
686
700
/// Execute an autocommand |autocmd-execute|.
Original file line number Diff line number Diff line change
@@ -2350,17 +2350,20 @@ int autocmd_delete_event(int group, event_T event, char_u *pat)
2350
2350
/// Deletes an autocmd by ID.
2351
2351
/// Only autocmds created via the API have IDs associated with them. There
2352
2352
/// is no way to delete a specific autocmd created via :autocmd
2353
-
void autocmd_delete_id(int64_t id)
2353
+
bool autocmd_delete_id(int64_t id)
2354
2354
{
2355
+
assert(id > 0);
2355
2356
FOR_ALL_AUEVENTS(event) {
2356
2357
FOR_ALL_AUPATS_IN_EVENT(event, ap) {
2357
2358
for (AutoCmd *ac = ap->cmds; ac != NULL; ac = ac->next) {
2358
2359
if (ac->id == id) {
2359
2360
aucmd_del(ac);
2361
+
return true;
2360
2362
}
2361
2363
}
2362
2364
}
2363
2365
}
2366
+
return false;
2364
2367
}
2365
2368
2366
2369
// ===========================================================================
Original file line number Diff line number Diff line change
@@ -809,6 +809,14 @@ describe('autocmd api', function()
809
809
eq(2, get_executed_count(), "No additional counts")
810
810
end)
811
811
812
+
it('can delete non-existent groups with pcall', function()
813
+
eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_name, 'noexist')]])
814
+
eq('Vim:E367: No such group: "noexist"', pcall_err(meths.del_augroup_by_name, 'noexist'))
815
+
816
+
eq(false, exec_lua[[return pcall(vim.api.nvim_del_augroup_by_id, -12342)]])
817
+
eq('Vim:E367: No such group: "--Deleted--"', pcall_err(meths.del_augroup_by_id, -12312))
818
+
end)
819
+
812
820
it('groups work with once', function()
813
821
local augroup = "TestGroup"
814
822
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4