@@ -145,6 +145,19 @@ sort_func_compare(const void *s1, const void *s2);
145145static void set_search_match (pos_T * t );
146146#endif
147147
148+
149+ #ifdef FEAT_AUTOCMD
150+ static void
151+ trigger_cmd_autocmd (int typechar , int evt )
152+ {
153+ char_u typestr [2 ];
154+
155+ typestr [0 ] = typechar ;
156+ typestr [1 ] = NUL ;
157+ apply_autocmds (evt , typestr , typestr , FALSE, curbuf );
158+ }
159+ #endif
160+
148161/*
149162 * getcmdline() - accept a command line starting with firstc.
150163 *
@@ -222,6 +235,9 @@ getcmdline(
222235 * custom status line may invoke ":normal". */
223236 struct cmdline_info save_ccline ;
224237#endif
238+ #ifdef FEAT_AUTOCMD
239+ int cmdline_type ;
240+ #endif
225241
226242#ifdef FEAT_EVAL
227243 if (firstc == -1 )
@@ -349,6 +365,12 @@ getcmdline(
349365 * terminal mode set to cooked. Need to set raw mode here then. */
350366 settmode (TMODE_RAW );
351367
368+ #ifdef FEAT_AUTOCMD
369+ /* Trigger CmdlineEnter autocommands. */
370+ cmdline_type = firstc == NUL ? '-' : firstc ;
371+ trigger_cmd_autocmd (cmdline_type , EVENT_CMDLINEENTER );
372+ #endif
373+
352374#ifdef FEAT_CMDHIST
353375 init_history ();
354376 hiscnt = hislen ; /* set hiscnt to impossible history value */
@@ -2085,6 +2107,11 @@ getcmdline(
20852107 if (some_key_typed )
20862108 need_wait_return = FALSE;
20872109
2110+ #ifdef FEAT_AUTOCMD
2111+ /* Trigger CmdlineLeave autocommands. */
2112+ trigger_cmd_autocmd (cmdline_type , EVENT_CMDLINELEAVE );
2113+ #endif
2114+
20882115 State = save_State ;
20892116#ifdef USE_IM_CONTROL
20902117 if (b_im_ptr != NULL && * b_im_ptr != B_IMODE_LMAP )
@@ -6834,9 +6861,6 @@ open_cmdwin(void)
68346861 linenr_T lnum ;
68356862 int histtype ;
68366863 garray_T winsizes ;
6837- #ifdef FEAT_AUTOCMD
6838- char_u typestr [2 ];
6839- #endif
68406864 int save_restart_edit = restart_edit ;
68416865 int save_State = State ;
68426866 int save_exmode = exmode_active ;
@@ -6965,9 +6989,7 @@ open_cmdwin(void)
69656989
69666990# ifdef FEAT_AUTOCMD
69676991 /* Trigger CmdwinEnter autocommands. */
6968- typestr [0 ] = cmdwin_type ;
6969- typestr [1 ] = NUL ;
6970- apply_autocmds (EVENT_CMDWINENTER , typestr , typestr , FALSE, curbuf );
6992+ trigger_cmd_autocmd (cmdwin_type , EVENT_CMDWINENTER );
69716993 if (restart_edit != 0 ) /* autocmd with ":startinsert" */
69726994 stuffcharReadbuff (K_NOP );
69736995# endif
@@ -6990,7 +7012,7 @@ open_cmdwin(void)
69907012# endif
69917013
69927014 /* Trigger CmdwinLeave autocommands. */
6993- apply_autocmds ( EVENT_CMDWINLEAVE , typestr , typestr , FALSE, curbuf );
7015+ trigger_cmd_autocmd ( cmdwin_type , EVENT_CMDWINLEAVE );
69947016
69957017# ifdef FEAT_FOLDING
69967018 /* Restore KeyTyped in case it is modified by autocommands */
0 commit comments