]> granicus.if.org Git - vim/commitdiff
updated for version 7.4.414 v7.4.414
authorBram Moolenaar <Bram@vim.org>
Fri, 22 Aug 2014 21:05:54 +0000 (23:05 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 22 Aug 2014 21:05:54 +0000 (23:05 +0200)
Problem:    Cannot define a command only when it's used.
Solution:   Add the CmdUndefined autocommand event. (partly by Yasuhiro
            Matsumoto)

runtime/doc/autocmd.txt
src/ex_docmd.c
src/fileio.c
src/proto/fileio.pro
src/version.c

index 2a8becebff0a2dd4663064ad78e220483425e7f5..079b9167708fe90f4274f445cf766b6021dfcb05 100644 (file)
@@ -278,6 +278,7 @@ Name                        triggered by ~
 |ShellCmdPost|         after executing a shell command
 |ShellFilterPost|      after filtering with a shell command
 
+|CmdUndefined|         a user command is used but it isn't defined
 |FuncUndefined|                a user function is used but it isn't defined
 |SpellFileMissing|     a spell file is used but it can't be found
 |SourcePre|            before sourcing a Vim script
@@ -465,6 +466,16 @@ BufWriteCmd                        Before writing the whole buffer to a file.
                                                        *BufWritePost*
 BufWritePost                   After writing the whole buffer to a file
                                (should undo the commands for BufWritePre).
+                                                       *CmdUndefined*
+CmdUndefined                   When a user command is used but it isn't
+                               defined.  Useful for defining a command only
+                               when it's used.  The pattern is matched
+                               against the command name.  Both <amatch> and
+                               <afile> are set to the name of the command.
+                               NOTE: Autocompletion won't work until the
+                               command is defined.  An alternative is to
+                               always define the user command and have it
+                               invoke an autoloaded function.  See |autoload|.
                                                        *CmdwinEnter*
 CmdwinEnter                    After entering the command-line window.
                                Useful for setting options specifically for
@@ -670,6 +681,8 @@ FuncUndefined                       When a user function is used but it isn't
                                when it's used.  The pattern is matched
                                against the function name.  Both <amatch> and
                                <afile> are set to the name of the function.
+                               NOTE: When writing Vim scripts a better
+                               alternative is to use an autoloaded function.
                                See |autoload-functions|.
                                                        *GUIEnter*
 GUIEnter                       After starting the GUI successfully, and after
index fecb653b54856c23c56af67d4c87ca3ebca3d8a2..68269517374188a9be4aad25c86742638bf4ab82 100644 (file)
@@ -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)
     {
index 17490ac21a22c73fe467e25d585127fea2625315..f2d204078670371119d100fb1d985b220783342f 100644 (file)
@@ -7641,6 +7641,7 @@ static struct event_name
     {"BufWriteCmd",    EVENT_BUFWRITECMD},
     {"CmdwinEnter",    EVENT_CMDWINENTER},
     {"CmdwinLeave",    EVENT_CMDWINLEAVE},
+    {"CmdUndefined",   EVENT_CMDUNDEFINED},
     {"ColorScheme",    EVENT_COLORSCHEME},
     {"CompleteDone",   EVENT_COMPLETEDONE},
     {"CursorHold",     EVENT_CURSORHOLD},
@@ -9159,6 +9160,24 @@ has_insertcharpre()
     return (first_autopat[(int)EVENT_INSERTCHARPRE] != NULL);
 }
 
+/*
+ * Return TRUE when there is an CmdUndefined autocommand defined.
+ */
+    int
+has_cmdundefined()
+{
+    return (first_autopat[(int)EVENT_CMDUNDEFINED] != NULL);
+}
+
+/*
+ * Return TRUE when there is an FuncUndefined autocommand defined.
+ */
+    int
+has_funcundefined()
+{
+    return (first_autopat[(int)EVENT_FUNCUNDEFINED] != NULL);
+}
+
     static int
 apply_autocmds_group(event, fname, fname_io, force, group, buf, eap)
     event_T    event;
index 0d532f4ce20dadee3fe7023e91d70343db92cf87..5b71d0aadc8178898f248237434154c3ea5524cf 100644 (file)
@@ -47,6 +47,8 @@ int has_cursormovedI __ARGS((void));
 int has_textchanged __ARGS((void));
 int has_textchangedI __ARGS((void));
 int has_insertcharpre __ARGS((void));
+int has_cmdundefined __ARGS((void));
+int has_funcundefined __ARGS((void));
 void block_autocmds __ARGS((void));
 void unblock_autocmds __ARGS((void));
 int is_autocmd_blocked __ARGS((void));
index e742d187c14ec0e88c0e6eb55d42292340863dee..ae87bb5a042128687c7a0a82a245a9e1ee2858df 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    414,
 /**/
     413,
 /**/