Mercurial > vim
diff src/ex_docmd.c @ 9941:e975914c17e9 v7.4.2244
commit https://github.com/vim/vim/commit/7b668e83d0635d082b7ec90d7d2aa30a9d7d8928
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 23 23:51:21 2016 +0200
patch 7.4.2244
Problem: Adding pattern to ":oldfiles" is not a generic solution.
Solution: Add the ":filter /pat/ cmd" command modifier. Only works for some
commands right now.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 24 Aug 2016 00:00:08 +0200 |
parents | e1a8b2601fe0 |
children | b222552cf0c4 |
line wrap: on
line diff
--- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -1781,6 +1781,7 @@ do_one_cmd( linenr_T lnum; long n; char_u *errormsg = NULL; /* error message */ + char_u *after_modifier = NULL; exarg_T ea; /* Ex command arguments */ long verbose_save = -1; int save_msg_scroll = msg_scroll; @@ -1917,6 +1918,24 @@ do_one_cmd( 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; + p = skip_vimgrep_pat(p, ®_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)) @@ -2041,6 +2060,7 @@ do_one_cmd( } break; } + after_modifier = ea.cmd; #ifdef FEAT_EVAL ea.skip = did_emsg || got_int || did_throw || (cstack->cs_idx >= 0 @@ -2374,7 +2394,14 @@ do_one_cmd( { STRCPY(IObuff, _("E492: Not an editor command")); if (!sourcing) - 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; } @@ -2818,6 +2845,7 @@ do_one_cmd( case CMD_echomsg: case CMD_echon: case CMD_execute: + case CMD_filter: case CMD_help: case CMD_hide: case CMD_ijump: @@ -2989,6 +3017,8 @@ doend: free_string_option(cmdmod.save_ei); } #endif + if (cmdmod.filter_regmatch.regprog != NULL) + vim_regfree(cmdmod.filter_regmatch.regprog); cmdmod = save_cmdmod; @@ -3323,6 +3353,7 @@ static struct cmdmod {"botright", 2, FALSE}, {"browse", 3, FALSE}, {"confirm", 4, FALSE}, + {"filter", 4, FALSE}, {"hide", 3, FALSE}, {"keepalt", 5, FALSE}, {"keepjumps", 5, FALSE}, @@ -3833,6 +3864,7 @@ set_one_cmd_context( case CMD_cfdo: case CMD_confirm: case CMD_debug: + case CMD_filter: case CMD_folddoclosed: case CMD_folddoopen: case CMD_hide: