Skip to content

Commit 7b668e8

Browse files
committed
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.
1 parent 1b58cdd commit 7b668e8

12 files changed

Lines changed: 125 additions & 22 deletions

File tree

runtime/doc/starting.txt

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*starting.txt* For Vim version 7.4. Last change: 2016 Aug 06
1+
*starting.txt* For Vim version 7.4. Last change: 2016 Aug 23
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -923,7 +923,8 @@ accordingly. Vim proceeds in this order:
923923
The $MYVIMRC or $MYGVIMRC file will be set to the first found vimrc and/or
924924
gvimrc file.
925925

926-
Some hints on using initializations:
926+
927+
Some hints on using initializations ~
927928

928929
Standard setup:
929930
Create a vimrc file to set the default settings and mappings for all your edit
@@ -946,27 +947,37 @@ want to set the defaults for all users. Create a vimrc file with commands
946947
for default settings and mappings and put it in the place that is given with
947948
the ":version" command.
948949

949-
Saving the current state of Vim to a file:
950+
951+
Saving the current state of Vim to a file ~
952+
950953
Whenever you have changed values of options or when you have created a
951954
mapping, then you may want to save them in a vimrc file for later use. See
952955
|save-settings| about saving the current state of settings to a file.
953956

954-
Avoiding setup problems for Vi users:
957+
958+
Avoiding setup problems for Vi users ~
959+
955960
Vi uses the variable EXINIT and the file "~/.exrc". So if you do not want to
956961
interfere with Vi, then use the variable VIMINIT and the file "vimrc" instead.
957962

958-
Amiga environment variables:
963+
964+
Amiga environment variables ~
965+
959966
On the Amiga, two types of environment variables exist. The ones set with the
960967
DOS 1.3 (or later) setenv command are recognized. See the AmigaDos 1.3
961968
manual. The environment variables set with the old Manx Set command (before
962969
version 5.0) are not recognized.
963970

964-
MS-DOS line separators:
971+
972+
MS-DOS line separators ~
973+
965974
On MS-DOS-like systems (MS-DOS itself, Win32, and OS/2), Vim assumes that all
966975
the vimrc files have <CR> <NL> pairs as line separators. This will give
967976
problems if you have a file with only <NL>s and have a line like
968977
":map xx yy^M". The trailing ^M will be ignored.
969978

979+
980+
Vi compatible default value ~
970981
*compatible-default*
971982
When Vim starts, the 'compatible' option is on. This will be used when Vim
972983
starts its initializations. But as soon as:
@@ -999,6 +1010,8 @@ encountered. This makes a difference when using things like "<CR>". If the
9991010
mappings depend on a certain value of 'compatible', set or reset it before
10001011
giving the mapping.
10011012

1013+
1014+
Defaults without a .vimrc file ~
10021015
*defaults.vim*
10031016
If Vim is started normally and no user vimrc file is found, the
10041017
$VIMRUTIME/defaults.vim script is loaded. This will set 'compatible' off,
@@ -1018,7 +1031,8 @@ revert individual settings. See the defaults.vim file for hints on how to
10181031
revert each item.
10191032

10201033

1021-
Avoiding trojan horses: *trojan-horse*
1034+
Avoiding trojan horses ~
1035+
*trojan-horse*
10221036
While reading the "vimrc" or the "exrc" file in the current directory, some
10231037
commands can be disabled for security reasons by setting the 'secure' option.
10241038
This is always done when executing the command from a tags file. Otherwise it
@@ -1041,6 +1055,8 @@ Be careful!
10411055
part of the line in the tags file) is always done in secure mode. This works
10421056
just like executing a command from a vimrc/exrc in the current directory.
10431057

1058+
1059+
If Vim startup is slow ~
10441060
*slow-start*
10451061
If Vim takes a long time to start up, use the |--startuptime| argument to find
10461062
out what happens. There are a few common causes:
@@ -1055,6 +1071,8 @@ out what happens. There are a few common causes:
10551071
moment (use the Vim argument "-i NONE", |-i|). Try reducing the number of
10561072
lines stored in a register with ":set viminfo='20,<50,s10". |viminfo-file|.
10571073

1074+
1075+
Intro message ~
10581076
*:intro*
10591077
When Vim starts without a file name, an introductory message is displayed (for
10601078
those who don't know what Vim is). It is removed as soon as the display is
@@ -1613,18 +1631,12 @@ most of the information will be restored).
16131631
file. This list is read on startup and only changes
16141632
afterwards with `:rviminfo!`. Also see |v:oldfiles|.
16151633
The number can be used with |c_#<|.
1634+
The output can be filtered with |:filter|, e.g.: >
1635+
filter /\\.vim/ oldfiles
1636+
< The filtering happens on the file name.
16161637
{not in Vi, only when compiled with the |+eval|
16171638
feature}
16181639

1619-
:ol[dfiles] {pat}
1620-
:ol[dfiles] /{pat}/
1621-
Like `:oldfiles` but only files matching {pat} will
1622-
be included. {pat} is a Vim search pattern. Instead
1623-
of enclosing it in / any non-ID character (see
1624-
|'isident'|) can be used, so long as it does not
1625-
appear in {pat}. Without the enclosing character the
1626-
pattern cannot include the bar character.
1627-
16281640
:bro[wse] ol[dfiles][!]
16291641
List file names as with |:oldfiles|, and then prompt
16301642
for a number. When the number is valid that file from

runtime/doc/various.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*various.txt* For Vim version 7.4. Last change: 2016 Jul 29
1+
*various.txt* For Vim version 7.4. Last change: 2016 Aug 23
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -524,6 +524,25 @@ N *+X11* Unix only: can restore window title |X11|
524524

525525
:redi[r] END End redirecting messages. {not in Vi}
526526

527+
*:filt* *:filter*
528+
:filt[er] {pat} {command}
529+
:filt[er] /{pat}/ {command}
530+
Restrict the output of {command} to matches with {pat}.
531+
532+
{pat} is a Vim search pattern. Instead of enclosing
533+
it in / any non-ID character (see |'isident'|) can be
534+
used, so long as it does not appear in {pat}. Without
535+
the enclosing character the pattern cannot include the
536+
bar character.
537+
538+
The pattern is matched against the relevant part of
539+
the output, not necessarily the whole line. Only some
540+
commands support filtering, try it out to check if it
541+
works.
542+
543+
Only normal messages are filtered, error messages are
544+
not.
545+
527546
*:sil* *:silent* *:silent!*
528547
:sil[ent][!] {command} Execute {command} silently. Normal messages will not
529548
be given or added to the message history.

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,6 +2072,7 @@ test_arglist \
20722072
test_farsi \
20732073
test_feedkeys \
20742074
test_file_perm \
2075+
test_filter_cmd \
20752076
test_filter_map \
20762077
test_fnamemodify \
20772078
test_glob2regpat \

src/ex_cmds.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,9 @@ EX(CMD_files, "files", buflist_list,
544544
EX(CMD_filetype, "filetype", ex_filetype,
545545
EXTRA|TRLBAR|CMDWIN,
546546
ADDR_LINES),
547+
EX(CMD_filter, "filter", ex_wrongmodifier,
548+
NEEDARG|EXTRA|NOTRLCOM,
549+
ADDR_LINES),
547550
EX(CMD_find, "find", ex_find,
548551
RANGE|NOTADR|BANG|FILE1|EDITCMD|ARGOPT|TRLBAR,
549552
ADDR_LINES),
@@ -992,7 +995,7 @@ EX(CMD_open, "open", ex_open,
992995
RANGE|BANG|EXTRA,
993996
ADDR_LINES),
994997
EX(CMD_oldfiles, "oldfiles", ex_oldfiles,
995-
BANG|TRLBAR|NOTADR|EXTRA|SBOXOK|CMDWIN,
998+
BANG|TRLBAR|SBOXOK|CMDWIN,
996999
ADDR_LINES),
9971000
EX(CMD_omap, "omap", ex_map,
9981001
EXTRA|TRLBAR|NOTRLCOM|USECTRLV|CMDWIN,

src/ex_docmd.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1781,6 +1781,7 @@ do_one_cmd(
17811781
linenr_T lnum;
17821782
long n;
17831783
char_u *errormsg = NULL; /* error message */
1784+
char_u *after_modifier = NULL;
17841785
exarg_T ea; /* Ex command arguments */
17851786
long verbose_save = -1;
17861787
int save_msg_scroll = msg_scroll;
@@ -1917,6 +1918,24 @@ do_one_cmd(
19171918
cmdmod.keepjumps = TRUE;
19181919
continue;
19191920

1921+
case 'f': /* only accept ":filter {pat} cmd" */
1922+
{
1923+
char_u *reg_pat;
1924+
1925+
if (!checkforcmd(&p, "filter", 4)
1926+
|| *p == NUL || ends_excmd(*p))
1927+
break;
1928+
p = skip_vimgrep_pat(p, &reg_pat, NULL);
1929+
if (p == NULL || *p == NUL)
1930+
break;
1931+
cmdmod.filter_regmatch.regprog =
1932+
vim_regcomp(reg_pat, RE_MAGIC);
1933+
if (cmdmod.filter_regmatch.regprog == NULL)
1934+
break;
1935+
ea.cmd = p;
1936+
continue;
1937+
}
1938+
19201939
/* ":hide" and ":hide | cmd" are not modifiers */
19211940
case 'h': if (p != ea.cmd || !checkforcmd(&p, "hide", 3)
19221941
|| *p == NUL || ends_excmd(*p))
@@ -2041,6 +2060,7 @@ do_one_cmd(
20412060
}
20422061
break;
20432062
}
2063+
after_modifier = ea.cmd;
20442064

20452065
#ifdef FEAT_EVAL
20462066
ea.skip = did_emsg || got_int || did_throw || (cstack->cs_idx >= 0
@@ -2374,7 +2394,14 @@ do_one_cmd(
23742394
{
23752395
STRCPY(IObuff, _("E492: Not an editor command"));
23762396
if (!sourcing)
2377-
append_command(*cmdlinep);
2397+
{
2398+
/* If the modifier was parsed OK the error must be in the
2399+
* following command */
2400+
if (after_modifier != NULL)
2401+
append_command(after_modifier);
2402+
else
2403+
append_command(*cmdlinep);
2404+
}
23782405
errormsg = IObuff;
23792406
did_emsg_syntax = TRUE;
23802407
}
@@ -2818,6 +2845,7 @@ do_one_cmd(
28182845
case CMD_echomsg:
28192846
case CMD_echon:
28202847
case CMD_execute:
2848+
case CMD_filter:
28212849
case CMD_help:
28222850
case CMD_hide:
28232851
case CMD_ijump:
@@ -2989,6 +3017,8 @@ do_one_cmd(
29893017
free_string_option(cmdmod.save_ei);
29903018
}
29913019
#endif
3020+
if (cmdmod.filter_regmatch.regprog != NULL)
3021+
vim_regfree(cmdmod.filter_regmatch.regprog);
29923022

29933023
cmdmod = save_cmdmod;
29943024

@@ -3323,6 +3353,7 @@ static struct cmdmod
33233353
{"botright", 2, FALSE},
33243354
{"browse", 3, FALSE},
33253355
{"confirm", 4, FALSE},
3356+
{"filter", 4, FALSE},
33263357
{"hide", 3, FALSE},
33273358
{"keepalt", 5, FALSE},
33283359
{"keepjumps", 5, FALSE},
@@ -3833,6 +3864,7 @@ set_one_cmd_context(
38333864
case CMD_cfdo:
38343865
case CMD_confirm:
38353866
case CMD_debug:
3867+
case CMD_filter:
38363868
case CMD_folddoclosed:
38373869
case CMD_folddoopen:
38383870
case CMD_hide:

src/message.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ msg_attr_keep(
137137
int retval;
138138
char_u *buf = NULL;
139139

140+
/* Skip messages not matching ":filter pattern".
141+
* Don't filter when there is an error. */
142+
if (!emsg_on_display && message_filtered(s))
143+
return TRUE;
144+
140145
#ifdef FEAT_EVAL
141146
if (attr == 0)
142147
set_vim_var_string(VV_STATUSMSG, s, -1);
@@ -2149,6 +2154,17 @@ msg_puts_display(
21492154
msg_check();
21502155
}
21512156

2157+
/*
2158+
* Return TRUE when ":filter pattern" was used and "msg" does not match
2159+
* "pattern".
2160+
*/
2161+
int
2162+
message_filtered(char_u *msg)
2163+
{
2164+
return cmdmod.filter_regmatch.regprog != NULL
2165+
&& !vim_regexec(&cmdmod.filter_regmatch, msg, (colnr_T)0);
2166+
}
2167+
21522168
/*
21532169
* Scroll the screen up one line for displaying the next message line.
21542170
*/

src/proto/message.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void msg_puts_title(char_u *s);
4343
void msg_puts_long_attr(char_u *longstr, int attr);
4444
void msg_puts_long_len_attr(char_u *longstr, int len, int attr);
4545
void msg_puts_attr(char_u *s, int attr);
46+
int message_filtered(char_u *msg);
4647
void may_clear_sb_text(void);
4748
void clear_sb_text(void);
4849
void show_sb_text(void);

src/structs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ typedef struct
571571
# ifdef FEAT_AUTOCMD
572572
char_u *save_ei; /* saved value of 'eventignore' */
573573
# endif
574+
regmatch_T filter_regmatch; /* set by :filter /pat/ */
574575
} cmdmod_T;
575576

576577
#define MF_SEED_LEN 8

src/testdir/test_alot.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ source test_expand_dllpath.vim
1313
source test_feedkeys.vim
1414
source test_fnamemodify.vim
1515
source test_file_perm.vim
16+
source test_filter_cmd.vim
1617
source test_filter_map.vim
1718
source test_glob2regpat.vim
1819
source test_goto.vim

src/testdir/test_filter_cmd.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
" Test the :filter command modifier
2+
3+
func Test_filter()
4+
edit Xdoesnotmatch
5+
edit Xwillmatch
6+
call assert_equal('"Xwillmatch"', substitute(execute('filter willma ls'), '[^"]*\(".*"\)[^"]*', '\1', ''))
7+
endfunc
8+
9+
func Test_filter_fails()
10+
call assert_fails('filter', 'E471:')
11+
call assert_fails('filter pat', 'E476:')
12+
call assert_fails('filter /pat', 'E476:')
13+
call assert_fails('filter /pat/', 'E476:')
14+
call assert_fails('filter /pat/ asdf', 'E492:')
15+
endfunc

0 commit comments

Comments
 (0)