From 8390accde7e37f1531b250ec2144b8d16cdee198 Mon Sep 17 00:00:00 2001 From: Scott Prager Date: Fri, 10 Oct 2014 21:54:10 -0400 Subject: [PATCH 1/3] Fix fileio.c's diagram. --- src/nvim/fileio.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 05a0a59874..4486d43578 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -72,25 +72,25 @@ * The result is an array of Autopat lists, which point to AutoCmd lists: * * first_autopat[0] --> Autopat.next --> Autopat.next --> NULL - * Autopat.cmds Autopat.cmds - * | | - * V V - * AutoCmd.next AutoCmd.next - * | | - * V V - * AutoCmd.next NULL - * | - * V - * NULL + * Autopat.cmds Autopat.cmds + * | | + * V V + * AutoCmd.next AutoCmd.next + * | | + * V V + * AutoCmd.next NULL + * | + * V + * NULL * * first_autopat[1] --> Autopat.next --> NULL - * Autopat.cmds - * | - * V - * AutoCmd.next - * | - * V - * NULL + * Autopat.cmds + * | + * V + * AutoCmd.next + * | + * V + * NULL * etc. * * The order of AutoCmds is important, this is the order in which they were From 0051a7cb259f2b88e01b9efe92580aafc970fbe4 Mon Sep 17 00:00:00 2001 From: Scott Prager Date: Fri, 10 Oct 2014 21:51:25 -0400 Subject: [PATCH 2/3] vim-patch:7.4.414 Problem: Cannot define a command only when it's used. Solution: Add the CmdUndefined autocommand event. (partly by Yasuhiro Matsumoto) https://code.google.com/p/vim/source/detail?r=v7-4-414 --- runtime/doc/autocmd.txt | 13 +++++++++++++ src/nvim/ex_docmd.c | 18 ++++++++++++++++++ src/nvim/fileio.c | 13 +++++++++++++ src/nvim/version.c | 2 +- 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 451e60514c..55bd508109 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -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 @@ -466,6 +467,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 and + 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 @@ -671,6 +682,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 and 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 diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 67c346237c..7e0122acd2 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1459,6 +1459,24 @@ static char_u * do_one_cmd(char_u **cmdlinep, /* Find the command and let "p" point to after it. */ p = find_command(&ea, NULL); + // 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; + + while (ASCII_ISALNUM(*p)) { + ++p; + } + p = vim_strnsave(ea.cmd, p - ea.cmd); + int ret = apply_autocmds(EVENT_CMDUNDEFINED, p, p, TRUE, NULL); + free(p); + if (ret && !aborting()) { + p = find_command(&ea, NULL); + } + } + if (p == NULL) { if (!ea.skip) errormsg = (char_u *)_("E464: Ambiguous use of user-defined command"); diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 4486d43578..b20150b2c9 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -5198,6 +5198,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}, @@ -6462,6 +6463,18 @@ int has_insertcharpre(void) return first_autopat[(int)EVENT_INSERTCHARPRE] != NULL; } +/// @returns true when there is an CmdUndefined autocommand defined. +int has_cmdundefined(void) +{ + return first_autopat[(int)EVENT_CMDUNDEFINED] != NULL; +} + +/// @returns true when there is an FuncUndefined autocommand defined. +int has_funcundefined(void) +{ + return first_autopat[(int)EVENT_FUNCUNDEFINED] != NULL; +} + static int apply_autocmds_group ( event_T event, diff --git a/src/nvim/version.c b/src/nvim/version.c index 137f85bb2b..7f80c57242 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -251,7 +251,7 @@ static int included_patches[] = { //417, //416, //415, - //414, + 414, //413 NA //412 NA 411, From bffea01c89bfe2c93169f65b50653d63dcb8e035 Mon Sep 17 00:00:00 2001 From: Scott Prager Date: Fri, 10 Oct 2014 22:05:42 -0400 Subject: [PATCH 3/3] vim-patch:7.4.415 Problem: Cannot build. Warning for shadowed variable. (John Little) Solution: Add missing change. Remove declaration. https://code.google.com/p/vim/source/detail?name=v7-4-414&r=20dbceb6f4713ccd01be45dc531abc269fbb7579 --- src/nvim/ex_docmd.c | 3 +-- src/nvim/fileio.h | 1 + src/nvim/version.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 7e0122acd2..134def0c2c 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1464,8 +1464,7 @@ static char_u * do_one_cmd(char_u **cmdlinep, if (p != NULL && ea.cmdidx == CMD_SIZE && !ea.skip && ASCII_ISUPPER(*ea.cmd) && has_cmdundefined()) { - char_u *p = ea.cmd; - + p = ea.cmd; while (ASCII_ISALNUM(*p)) { ++p; } diff --git a/src/nvim/fileio.h b/src/nvim/fileio.h index 7e4ced554d..29bd1307f6 100644 --- a/src/nvim/fileio.h +++ b/src/nvim/fileio.h @@ -99,6 +99,7 @@ typedef enum auto_event { EVENT_SHELLFILTERPOST, /* after ":1,2!cmd", ":w !cmd", ":r !cmd". */ EVENT_TEXTCHANGED, /* text was modified */ EVENT_TEXTCHANGEDI, /* text was modified in Insert mode*/ + EVENT_CMDUNDEFINED, ///< command undefined NUM_EVENTS /* MUST be the last one */ } event_T; diff --git a/src/nvim/version.c b/src/nvim/version.c index 7f80c57242..9b5b995801 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -250,7 +250,7 @@ static int included_patches[] = { 418, //417, //416, - //415, + 415, 414, //413 NA //412 NA