Skip to content

Instantly share code, notes, and snippets.

@mattn
Last active December 11, 2015 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattn/4582948 to your computer and use it in GitHub Desktop.
Save mattn/4582948 to your computer and use it in GitHub Desktop.
diff -r 5cf390d4fbe1 src/eval.c
--- a/src/eval.c Thu Jan 17 18:34:06 2013 +0100
+++ b/src/eval.c Mon Jan 21 10:15:14 2013 +0900
@@ -360,6 +360,7 @@
{VV_NAME("searchforward", VAR_NUMBER), 0},
{VV_NAME("oldfiles", VAR_LIST), 0},
{VV_NAME("windowid", VAR_NUMBER), VV_RO},
+ {VV_NAME("command", VAR_STRING), VV_RO},
};
/* shorthand */
diff -r 5cf390d4fbe1 src/ex_docmd.c
--- a/src/ex_docmd.c Thu Jan 17 18:34:06 2013 +0100
+++ b/src/ex_docmd.c Mon Jan 21 10:15:14 2013 +0900
@@ -2145,6 +2145,16 @@
{
if (!ea.skip)
{
+#ifdef FEAT_AUTOCMD
+ if (has_commandnotfound())
+ {
+ set_vim_var_string(VV_COMMAND, *cmdlinep, -1);
+ int ret = apply_autocmds(EVENT_COMMANDNOTFOUND, NULL, NULL, FALSE, curbuf);
+ set_vim_var_string(VV_COMMAND, NULL, -1);
+ if (ret)
+ goto doend;
+ }
+#endif
STRCPY(IObuff, _("E492: Not an editor command"));
if (!sourcing)
append_command(*cmdlinep);
diff -r 5cf390d4fbe1 src/fileio.c
--- a/src/fileio.c Thu Jan 17 18:34:06 2013 +0100
+++ b/src/fileio.c Mon Jan 21 10:15:14 2013 +0900
@@ -7658,6 +7658,7 @@
{"CmdwinEnter", EVENT_CMDWINENTER},
{"CmdwinLeave", EVENT_CMDWINLEAVE},
{"ColorScheme", EVENT_COLORSCHEME},
+ {"CommandNotFound", EVENT_COMMANDNOTFOUND},
{"CompleteDone", EVENT_COMPLETEDONE},
{"CursorHold", EVENT_CURSORHOLD},
{"CursorHoldI", EVENT_CURSORHOLDI},
@@ -9143,6 +9144,16 @@
return (first_autopat[(int)EVENT_INSERTCHARPRE] != NULL);
}
+/*
+ * Return TRUE when there is an CommandNotFound autocommand defined.
+ */
+ int
+has_commandnotfound()
+{
+ return (first_autopat[(int)EVENT_COMMANDNOTFOUND] != NULL);
+}
+
+
static int
apply_autocmds_group(event, fname, fname_io, force, group, buf, eap)
event_T event;
diff -r 5cf390d4fbe1 src/proto/fileio.pro
--- a/src/proto/fileio.pro Thu Jan 17 18:34:06 2013 +0100
+++ b/src/proto/fileio.pro Mon Jan 21 10:15:14 2013 +0900
@@ -45,6 +45,7 @@
int has_cursormoved __ARGS((void));
int has_cursormovedI __ARGS((void));
int has_insertcharpre __ARGS((void));
+int has_commandnotfound __ARGS((void));
void block_autocmds __ARGS((void));
void unblock_autocmds __ARGS((void));
char_u *getnextac __ARGS((int c, void *cookie, int indent));
diff -r 5cf390d4fbe1 src/vim.h
--- a/src/vim.h Thu Jan 17 18:34:06 2013 +0100
+++ b/src/vim.h Mon Jan 21 10:15:14 2013 +0900
@@ -1300,6 +1300,7 @@
EVENT_TABENTER, /* after entering a tab page */
EVENT_SHELLCMDPOST, /* after ":!cmd" */
EVENT_SHELLFILTERPOST, /* after ":1,2!cmd", ":w !cmd", ":r !cmd". */
+ EVENT_COMMANDNOTFOUND, /* command not found */
NUM_EVENTS /* MUST be the last one */
};
@@ -1870,7 +1871,8 @@
#define VV_SEARCHFORWARD 53
#define VV_OLDFILES 54
#define VV_WINDOWID 55
-#define VV_LEN 56 /* number of v: vars */
+#define VV_COMMAND 56
+#define VV_LEN 57 /* number of v: vars */
#ifdef FEAT_CLIPBOARD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment