vim-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.

7b668e83d0
This commit is contained in:
James McCoy
2017-04-29 07:58:49 -04:00
parent 059c3fc2f9
commit 7bd97127b4
8 changed files with 105 additions and 30 deletions

View File

@@ -930,6 +930,12 @@ return {
addr_type=ADDR_LINES,
func='ex_filetype',
},
{
command='filter',
flags=bit.bor(NEEDARG, EXTRA, NOTRLCOM),
addr_type=ADDR_LINES,
func='ex_wrongmodifier',
},
{
command='find',
flags=bit.bor(RANGE, NOTADR, BANG, FILE1, EDITCMD, ARGOPT, TRLBAR),
@@ -1810,7 +1816,7 @@ return {
},
{
command='oldfiles',
flags=bit.bor(BANG, TRLBAR, NOTADR, EXTRA, SBOXOK, CMDWIN),
flags=bit.bor(BANG, TRLBAR, SBOXOK, CMDWIN),
addr_type=ADDR_LINES,
func='ex_oldfiles',
},

View File

@@ -6,6 +6,7 @@
#include "nvim/pos.h" // for linenr_T
#include "nvim/normal.h"
#include "nvim/regexp_defs.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "ex_cmds_enum.generated.h"
@@ -163,18 +164,19 @@ struct expand {
/// flag. This needs to be saved for recursive commands, put them in a
/// structure for easy manipulation.
typedef struct {
int split; ///< flags for win_split()
int tab; ///< > 0 when ":tab" was used
bool browse; ///< true to invoke file dialog
bool confirm; ///< true to invoke yes/no dialog
bool hide; ///< true when ":hide" was used
bool keepalt; ///< true when ":keepalt" was used
bool keepjumps; ///< true when ":keepjumps" was used
bool keepmarks; ///< true when ":keepmarks" was used
bool keeppatterns; ///< true when ":keeppatterns" was used
bool lockmarks; ///< true when ":lockmarks" was used
bool noswapfile; ///< true when ":noswapfile" was used
char_u *save_ei; ///< saved value of 'eventignore'
int split; ///< flags for win_split()
int tab; ///< > 0 when ":tab" was used
bool browse; ///< true to invoke file dialog
bool confirm; ///< true to invoke yes/no dialog
bool hide; ///< true when ":hide" was used
bool keepalt; ///< true when ":keepalt" was used
bool keepjumps; ///< true when ":keepjumps" was used
bool keepmarks; ///< true when ":keepmarks" was used
bool keeppatterns; ///< true when ":keeppatterns" was used
bool lockmarks; ///< true when ":lockmarks" was used
bool noswapfile; ///< true when ":noswapfile" was used
char_u *save_ei; ///< saved value of 'eventignore'
regmatch_T filter_regmatch; ///< set by :filter /pat/
} cmdmod_T;
#endif // NVIM_EX_CMDS_DEFS_H

View File

@@ -1350,6 +1350,24 @@ 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;
}
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 +1470,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 +1753,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 +2129,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 +2281,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) {
@@ -2545,6 +2575,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},
@@ -3007,6 +3038,7 @@ const char * 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:

View File

@@ -31,6 +31,7 @@
#include "nvim/ops.h"
#include "nvim/option.h"
#include "nvim/normal.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/strings.h"
#include "nvim/ui.h"
@@ -148,6 +149,12 @@ msg_attr_keep (
int retval;
char_u *buf = NULL;
// Skip messages not match ":filter pattern".
// Don't filter when there is an error.
if (!emsg_on_display && message_filtered(s)) {
return true;
}
if (attr == 0) {
set_vim_var_string(VV_STATUSMSG, (char *) s, -1);
}
@@ -1783,6 +1790,14 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr,
msg_check();
}
/// Return true when ":filter pattern" was used and "msg" does not match
/// "pattern".
bool message_filtered(char_u *msg)
{
return cmdmod.filter_regmatch.regprog != NULL
&& !vim_regexec(&cmdmod.filter_regmatch, msg, (colnr_T)0);
}
/*
* Scroll the screen up one line for displaying the next message line.
*/

View File

@@ -8,6 +8,7 @@ source test_ex_undo.vim
source test_expr.vim
source test_expr_utf8.vim
source test_feedkeys.vim
source test_filter_cmd.vim
source test_filter_map.vim
source test_goto.vim
source test_jumps.vim

View File

@@ -0,0 +1,15 @@
" Test the :filter command modifier
func Test_filter()
edit Xdoesnotmatch
edit Xwillmatch
call assert_equal('"Xwillmatch"', substitute(execute('filter willma ls'), '[^"]*\(".*"\)[^"]*', '\1', ''))
endfunc
func Test_filter_fails()
call assert_fails('filter', 'E471:')
call assert_fails('filter pat', 'E476:')
call assert_fails('filter /pat', 'E476:')
call assert_fails('filter /pat/', 'E476:')
call assert_fails('filter /pat/ asdf', 'E492:')
endfunc

View File

@@ -200,7 +200,7 @@ static const int included_patches[] = {
// 2247 NA
// 2246,
// 2245,
// 2244,
2244,
// 2243 NA
2242,
2241,