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
No known key found for this signature in database
GPG Key ID: DFE691AE331BA3DB
8 changed files with 105 additions and 30 deletions

View File

@ -518,7 +518,8 @@ accordingly. Vim proceeds in this order:
The |v:vim_did_enter| variable is set to 1.
The |VimEnter| autocommands are executed.
Some hints on using initializations:
Some hints on using initializations ~
Standard setup:
Create a vimrc file to set the default settings and mappings for all your edit
@ -540,17 +541,23 @@ the ":version" command. NOTE: System vimrc file needs specific compilation
options (one needs to define SYS_VIMRC_FILE macros). If :version command does
not show anything like this, consider contacting the nvim package maintainer.
Saving the current state of Vim to a file:
Saving the current state of Vim to a file ~
Whenever you have changed values of options or when you have created a
mapping, then you may want to save them in a vimrc file for later use. See
|save-settings| about saving the current state of settings to a file.
Avoiding setup problems for Vi users:
Avoiding setup problems for Vi users ~
Vi uses the variable EXINIT and the file "~/.exrc". So if you do not want to
interfere with Vi, then use the variable VIMINIT and the file init.vim
instead.
MS-DOS line separators:
MS-DOS line separators: ~
On Windows systems Vim assumes that all the vimrc files have <CR> <NL> pairs
as line separators. This will give problems if you have a file with only
<NL>s and have a line like ":map xx yy^M". The trailing ^M will be ignored.
@ -558,8 +565,10 @@ as line separators. This will give problems if you have a file with only
The $MYVIMRC or $MYGVIMRC file will be set to the first found vimrc and/or
gvimrc file.
Avoiding trojan horses: *trojan-horse*
While reading the vimrc or the exrc file in the current directory, some
Avoiding trojan horses ~
*trojan-horse*
While reading the "vimrc" or the "exrc" file in the current directory, some
commands can be disabled for security reasons by setting the 'secure' option.
This is always done when executing the command from a tags file. Otherwise it
would be possible that you accidentally use a vimrc or tags file that somebody
@ -581,6 +590,8 @@ Be careful!
part of the line in the tags file) is always done in secure mode. This works
just like executing a command from a vimrc/exrc in the current directory.
If Vim startup is slow ~
*slow-start*
If Vim takes a long time to start up, use the |--startuptime| argument to find
out what happens.
@ -590,6 +601,8 @@ while. You can find out if this is the problem by disabling ShaDa for a
moment (use the Vim argument "-i NONE", |-i|). Try reducing the number of
lines stored in a register with ":set shada='20,<50,s10". |shada-file|.
Intro message ~
*:intro*
When Vim starts without a file name, an introductory message is displayed (for
those who don't know what Vim is). It is removed as soon as the display is
@ -1188,15 +1201,6 @@ running) you have additional options:
filter /\.vim/ oldfiles
< The filtering happens on the file name.
:ol[dfiles] {pat}
:ol[dfiles] /{pat}/
Like `:oldfiles` but only files matching {pat} will
be included. {pat} is a Vim search pattern. Instead
of enclosing it in / any non-ID character (see
|'isident'|) can be used, so long as it does not
appear in {pat}. Without the enclosing character the
pattern cannot include the bar character.
:bro[wse] o[ldfiles][!]
List file names as with |:oldfiles|, and then prompt
for a number. When the number is valid that file from

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,