diff src/ex_getln.c @ 12656:0a9dacb8826a v8.0.1206

patch 8.0.1206: no autocmd for entering or leaving the command line commit https://github.com/vim/vim/commit/fafcf0dd59fd9c4ef743bb333ae40d1d322b6079 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Oct 19 18:35:51 2017 +0200 patch 8.0.1206: no autocmd for entering or leaving the command line Problem: No autocmd for entering or leaving the command line. Solution: Add CmdlineEnter and CmdlineLeave.
author Christian Brabandt <cb@256bit.org>
date Thu, 19 Oct 2017 18:45:05 +0200
parents 158917d728b4
children 42cd1f315e8b
line wrap: on
line diff
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -145,6 +145,19 @@ sort_func_compare(const void *s1, const 
 static void set_search_match(pos_T *t);
 #endif
 
+
+#ifdef FEAT_AUTOCMD
+    static void
+trigger_cmd_autocmd(int typechar, int evt)
+{
+    char_u	typestr[2];
+
+    typestr[0] = typechar;
+    typestr[1] = NUL;
+    apply_autocmds(evt, typestr, typestr, FALSE, curbuf);
+}
+#endif
+
 /*
  * getcmdline() - accept a command line starting with firstc.
  *
@@ -222,6 +235,9 @@ getcmdline(
      * custom status line may invoke ":normal". */
     struct cmdline_info save_ccline;
 #endif
+#ifdef FEAT_AUTOCMD
+    int		cmdline_type;
+#endif
 
 #ifdef FEAT_EVAL
     if (firstc == -1)
@@ -349,6 +365,12 @@ getcmdline(
      * terminal mode set to cooked.  Need to set raw mode here then. */
     settmode(TMODE_RAW);
 
+#ifdef FEAT_AUTOCMD
+    /* Trigger CmdlineEnter autocommands. */
+    cmdline_type = firstc == NUL ? '-' : firstc;
+    trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINEENTER);
+#endif
+
 #ifdef FEAT_CMDHIST
     init_history();
     hiscnt = hislen;		/* set hiscnt to impossible history value */
@@ -2085,6 +2107,11 @@ returncmd:
     if (some_key_typed)
 	need_wait_return = FALSE;
 
+#ifdef FEAT_AUTOCMD
+    /* Trigger CmdlineLeave autocommands. */
+    trigger_cmd_autocmd(cmdline_type, EVENT_CMDLINELEAVE);
+#endif
+
     State = save_State;
 #ifdef USE_IM_CONTROL
     if (b_im_ptr != NULL && *b_im_ptr != B_IMODE_LMAP)
@@ -6834,9 +6861,6 @@ open_cmdwin(void)
     linenr_T		lnum;
     int			histtype;
     garray_T		winsizes;
-#ifdef FEAT_AUTOCMD
-    char_u		typestr[2];
-#endif
     int			save_restart_edit = restart_edit;
     int			save_State = State;
     int			save_exmode = exmode_active;
@@ -6965,9 +6989,7 @@ open_cmdwin(void)
 
 # ifdef FEAT_AUTOCMD
     /* Trigger CmdwinEnter autocommands. */
-    typestr[0] = cmdwin_type;
-    typestr[1] = NUL;
-    apply_autocmds(EVENT_CMDWINENTER, typestr, typestr, FALSE, curbuf);
+    trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER);
     if (restart_edit != 0)	/* autocmd with ":startinsert" */
 	stuffcharReadbuff(K_NOP);
 # endif
@@ -6990,7 +7012,7 @@ open_cmdwin(void)
 #  endif
 
     /* Trigger CmdwinLeave autocommands. */
-    apply_autocmds(EVENT_CMDWINLEAVE, typestr, typestr, FALSE, curbuf);
+    trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE);
 
 #  ifdef FEAT_FOLDING
     /* Restore KeyTyped in case it is modified by autocommands */