aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_docmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/ex_docmd.c')
-rw-r--r--src/nvim/ex_docmd.c101
1 files changed, 76 insertions, 25 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 7568d71ac0..72b2e0f29b 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -1350,6 +1350,31 @@ static char_u * do_one_cmd(char_u **cmdlinep,
cmdmod.keepjumps = true;
continue;
+ case 'f': { // only accept ":filter {pat} cmd"
+ char_u *reg_pat;
+
+ if (!checkforcmd(&p, "filter", 4) || *p == NUL || ends_excmd(*p)) {
+ break;
+ }
+ if (*p == '!') {
+ cmdmod.filter_force = true;
+ p = skipwhite(p + 1);
+ if (*p == NUL || ends_excmd(*p)) {
+ break;
+ }
+ }
+ p = skip_vimgrep_pat(p, &reg_pat, NULL);
+ if (p == NULL || *p == NUL) {
+ break;
+ }
+ cmdmod.filter_regmatch.regprog = vim_regcomp(reg_pat, RE_MAGIC);
+ if (cmdmod.filter_regmatch.regprog == NULL) {
+ break;
+ }
+ ea.cmd = p;
+ continue;
+ }
+
/* ":hide" and ":hide | cmd" are not modifiers */
case 'h': if (p != ea.cmd || !checkforcmd(&p, "hide", 3)
|| *p == NUL || ends_excmd(*p))
@@ -1452,6 +1477,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
}
break;
}
+ char_u *after_modifier = ea.cmd;
ea.skip = did_emsg || got_int || did_throw || (cstack->cs_idx >= 0
&& !(cstack->cs_flags[cstack->
@@ -1734,7 +1760,13 @@ static char_u * do_one_cmd(char_u **cmdlinep,
if (!ea.skip) {
STRCPY(IObuff, _("E492: Not an editor command"));
if (!(flags & DOCMD_VERBOSE)) {
- append_command(*cmdlinep);
+ // If the modifier was parsed OK the error must be in the following
+ // command
+ if (after_modifier != NULL) {
+ append_command(after_modifier);
+ } else {
+ append_command(*cmdlinep);
+ }
}
errormsg = IObuff;
did_emsg_syntax = TRUE;
@@ -2104,6 +2136,7 @@ static char_u * do_one_cmd(char_u **cmdlinep,
case CMD_echomsg:
case CMD_echon:
case CMD_execute:
+ case CMD_filter:
case CMD_help:
case CMD_hide:
case CMD_ijump:
@@ -2255,6 +2288,10 @@ doend:
free_string_option(cmdmod.save_ei);
}
+ if (cmdmod.filter_regmatch.regprog != NULL) {
+ vim_regfree(cmdmod.filter_regmatch.regprog);
+ }
+
cmdmod = save_cmdmod;
if (save_msg_silent != -1) {
@@ -2540,28 +2577,29 @@ static struct cmdmod {
int minlen;
int has_count; /* :123verbose :3tab */
} cmdmods[] = {
- {"aboveleft", 3, FALSE},
- {"belowright", 3, FALSE},
- {"botright", 2, FALSE},
- {"browse", 3, FALSE},
- {"confirm", 4, FALSE},
- {"hide", 3, FALSE},
- {"keepalt", 5, FALSE},
- {"keepjumps", 5, FALSE},
- {"keepmarks", 3, FALSE},
- {"keeppatterns", 5, FALSE},
- {"leftabove", 5, FALSE},
- {"lockmarks", 3, FALSE},
- {"noautocmd", 3, FALSE},
- {"noswapfile", 3, FALSE},
- {"rightbelow", 6, FALSE},
- {"sandbox", 3, FALSE},
- {"silent", 3, FALSE},
- {"tab", 3, TRUE},
- {"topleft", 2, FALSE},
- {"unsilent", 3, FALSE},
- {"verbose", 4, TRUE},
- {"vertical", 4, FALSE},
+ { "aboveleft", 3, false },
+ { "belowright", 3, false },
+ { "botright", 2, false },
+ { "browse", 3, false },
+ { "confirm", 4, false },
+ { "filter", 4, false },
+ { "hide", 3, false },
+ { "keepalt", 5, false },
+ { "keepjumps", 5, false },
+ { "keepmarks", 3, false },
+ { "keeppatterns", 5, false },
+ { "leftabove", 5, false },
+ { "lockmarks", 3, false },
+ { "noautocmd", 3, false },
+ { "noswapfile", 3, false },
+ { "rightbelow", 6, false },
+ { "sandbox", 3, false },
+ { "silent", 3, false },
+ { "tab", 3, true },
+ { "topleft", 2, false },
+ { "unsilent", 3, false },
+ { "verbose", 4, true },
+ { "vertical", 4, false },
};
/*
@@ -3031,6 +3069,16 @@ const char * set_one_cmd_context(
case CMD_windo:
return arg;
+ case CMD_filter:
+ if (*arg != NUL) {
+ arg = (const char *)skip_vimgrep_pat((char_u *)arg, NULL, NULL);
+ }
+ if (arg == NULL || *arg == NUL) {
+ xp->xp_context = EXPAND_NOTHING;
+ return NULL;
+ }
+ return (const char *)skipwhite((const char_u *)arg);
+
case CMD_match:
if (*arg == NUL || !ends_excmd(*arg)) {
/* also complete "None" */
@@ -4851,9 +4899,12 @@ static void uc_list(char_u *name, size_t name_len)
cmd = USER_CMD_GA(gap, i);
a = cmd->uc_argt;
- /* Skip commands which don't match the requested prefix */
- if (STRNCMP(name, cmd->uc_name, name_len) != 0)
+ // Skip commands which don't match the requested prefix and
+ // commands filtered out.
+ if (STRNCMP(name, cmd->uc_name, name_len) != 0
+ || message_filtered(cmd->uc_name)) {
continue;
+ }
/* Put out the title first time */
if (!found)