diff src/ex_docmd.c @ 6154:67edf731a240 v7.4.414

updated for version 7.4.414 Problem: Cannot define a command only when it's used. Solution: Add the CmdUndefined autocommand event. (partly by Yasuhiro Matsumoto)
author Bram Moolenaar <bram@vim.org>
date Fri, 22 Aug 2014 23:05:54 +0200
parents 18ac55444b37
children 20dbceb6f471
line wrap: on
line diff
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -2143,6 +2143,26 @@ do_one_cmd(cmdlinep, sourcing,
     /* Find the command and let "p" point to after it. */
     p = find_command(&ea, NULL);
 
+#ifdef FEAT_AUTOCMD
+    /* If this looks like an undefined user command and there are CmdUndefined
+     * autocommands defined, trigger the matching autocommands. */
+    if (p != NULL && ea.cmdidx == CMD_SIZE && !ea.skip
+	    && ASCII_ISUPPER(*ea.cmd)
+	    && has_cmdundefined())
+    {
+	char_u *p = ea.cmd;
+	int ret;
+
+	while (ASCII_ISALNUM(*p))
+	    ++p;
+	p = vim_strnsave(ea.cmd, p - ea.cmd);
+	ret = apply_autocmds(EVENT_CMDUNDEFINED, p, p, TRUE, NULL);
+	vim_free(p);
+	if (ret && !aborting())
+	    p = find_command(&ea, NULL);
+    }
+#endif
+
 #ifdef FEAT_USR_CMDS
     if (p == NULL)
     {