aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/autocmd.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2025-03-10 08:27:30 +0800
committerGitHub <noreply@github.com>2025-03-10 00:27:30 +0000
commitc53e00889d38d19ec5e40f97e77280c8d4e33802 (patch)
tree8fe0677788952c210020fcc436b6f53467ffcd79 /src/nvim/autocmd.c
parentb90f649ca2e240c1bfb22fe91247bc90314af1e1 (diff)
downloadrneovim-c53e00889d38d19ec5e40f97e77280c8d4e33802.tar.gz
rneovim-c53e00889d38d19ec5e40f97e77280c8d4e33802.tar.bz2
rneovim-c53e00889d38d19ec5e40f97e77280c8d4e33802.zip
refactor(gen_events): sort enums case-insensitively (#32811)
This actually only affects the order in which Cmdline* and Cmdwin* autocommands are listed, and it appears that the names of Cmdwin* were changed to CmdWin* in 8ed2dbf6e2802516501c11e72e5d6d977e6a07f3 without explanation. Also, remove the final NULL element from the names table.
Diffstat (limited to 'src/nvim/autocmd.c')
-rw-r--r--src/nvim/autocmd.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/nvim/autocmd.c b/src/nvim/autocmd.c
index 28c3906ce3..c00a5814b1 100644
--- a/src/nvim/autocmd.c
+++ b/src/nvim/autocmd.c
@@ -2267,7 +2267,7 @@ char *set_context_in_autocmd(expand_T *xp, char *arg, bool doautocmd)
return NULL;
}
-// Function given to ExpandGeneric() to obtain the list of event names.
+/// Function given to ExpandGeneric() to obtain the list of event names.
char *expand_get_event_name(expand_T *xp, int idx)
{
(void)xp; // xp is a required parameter to be used with ExpandGeneric
@@ -2283,14 +2283,23 @@ char *expand_get_event_name(expand_T *xp, int idx)
return name;
}
+ int i = idx - next_augroup_id;
+ if (i < 0 || i >= NUM_EVENTS) {
+ return NULL;
+ }
+
// List event names
- return event_names[idx - next_augroup_id].name;
+ return event_names[i].name;
}
/// Function given to ExpandGeneric() to obtain the list of event names. Don't
/// include groups.
char *get_event_name_no_group(expand_T *xp FUNC_ATTR_UNUSED, int idx, bool win)
{
+ if (idx < 0 || idx >= NUM_EVENTS) {
+ return NULL;
+ }
+
if (!win) {
return event_names[idx].name;
}