Skip to content

Commit 8fc4296

Browse files
committed
patch 8.1.2221: cannot filter :disp output
Problem: Cannot filter :disp output. Solution: Support filtereing :disp output. (Andi Massimino, closes #5117)
1 parent 6a0cc91 commit 8fc4296

4 files changed

Lines changed: 77 additions & 33 deletions

File tree

runtime/doc/various.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,8 @@ N *+X11* Unix only: can restore window title |X11|
575575
|:marks| - filter by text in the current file,
576576
or file name for other files
577577
|:oldfiles| - filter by file name
578+
|:registers| - filter by register contents
579+
(does not work multi-line)
578580
|:set| - filter by variable name
579581

580582
Only normal messages are filtered, error messages are

src/register.c

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,7 @@ ex_display(exarg_T *eap)
21612161
int attr;
21622162
char_u *arg = eap->arg;
21632163
int clen;
2164-
char_u type[2];
2164+
int type;
21652165

21662166
if (arg != NULL && *arg == NUL)
21672167
arg = NULL;
@@ -2174,9 +2174,9 @@ ex_display(exarg_T *eap)
21742174
name = get_register_name(i);
21752175
switch (get_reg_type(name, NULL))
21762176
{
2177-
case MLINE: type[0] = 'l'; break;
2178-
case MCHAR: type[0] = 'c'; break;
2179-
default: type[0] = 'b'; break;
2177+
case MLINE: type = 'l'; break;
2178+
case MCHAR: type = 'c'; break;
2179+
default: type = 'b'; break;
21802180
}
21812181
if (arg != NULL && vim_strchr(arg, name) == NULL
21822182
#ifdef ONE_CLIPBOARD
@@ -2213,55 +2213,66 @@ ex_display(exarg_T *eap)
22132213

22142214
if (yb->y_array != NULL)
22152215
{
2216-
msg_putchar('\n');
2217-
msg_puts(" ");
2218-
msg_putchar(type[0]);
2219-
msg_puts(" ");
2220-
msg_putchar('"');
2221-
msg_putchar(name);
2222-
msg_puts(" ");
2223-
2224-
n = (int)Columns - 11;
2225-
for (j = 0; j < yb->y_size && n > 1; ++j)
2216+
int do_show = FALSE;
2217+
2218+
for (j = 0; !do_show && j < yb->y_size; ++j)
2219+
do_show = !message_filtered(yb->y_array[j]);
2220+
2221+
if (do_show || yb->y_size == 0)
22262222
{
2227-
if (j)
2228-
{
2229-
msg_puts_attr("^J", attr);
2230-
n -= 2;
2231-
}
2232-
for (p = yb->y_array[j]; *p && (n -= ptr2cells(p)) >= 0; ++p)
2223+
msg_putchar('\n');
2224+
msg_puts(" ");
2225+
msg_putchar(type);
2226+
msg_puts(" ");
2227+
msg_putchar('"');
2228+
msg_putchar(name);
2229+
msg_puts(" ");
2230+
2231+
n = (int)Columns - 11;
2232+
for (j = 0; j < yb->y_size && n > 1; ++j)
22332233
{
2234-
clen = (*mb_ptr2len)(p);
2235-
msg_outtrans_len(p, clen);
2236-
p += clen - 1;
2234+
if (j)
2235+
{
2236+
msg_puts_attr("^J", attr);
2237+
n -= 2;
2238+
}
2239+
for (p = yb->y_array[j]; *p && (n -= ptr2cells(p)) >= 0;
2240+
++p)
2241+
{
2242+
clen = (*mb_ptr2len)(p);
2243+
msg_outtrans_len(p, clen);
2244+
p += clen - 1;
2245+
}
22372246
}
2247+
if (n > 1 && yb->y_type == MLINE)
2248+
msg_puts_attr("^J", attr);
2249+
out_flush(); // show one line at a time
22382250
}
2239-
if (n > 1 && yb->y_type == MLINE)
2240-
msg_puts_attr("^J", attr);
2241-
out_flush(); // show one line at a time
2251+
ui_breakcheck();
22422252
}
2243-
ui_breakcheck();
22442253
}
22452254

22462255
// display last inserted text
22472256
if ((p = get_last_insert()) != NULL
2248-
&& (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int)
2257+
&& (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int
2258+
&& !message_filtered(p))
22492259
{
22502260
msg_puts("\n c \". ");
22512261
dis_msg(p, TRUE);
22522262
}
22532263

22542264
// display last command line
22552265
if (last_cmdline != NULL && (arg == NULL || vim_strchr(arg, ':') != NULL)
2256-
&& !got_int)
2266+
&& !got_int && !message_filtered(last_cmdline))
22572267
{
22582268
msg_puts("\n c \": ");
22592269
dis_msg(last_cmdline, FALSE);
22602270
}
22612271

22622272
// display current file name
22632273
if (curbuf->b_fname != NULL
2264-
&& (arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int)
2274+
&& (arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int
2275+
&& !message_filtered(curbuf->b_fname))
22652276
{
22662277
msg_puts("\n c \"% ");
22672278
dis_msg(curbuf->b_fname, FALSE);
@@ -2273,7 +2284,8 @@ ex_display(exarg_T *eap)
22732284
char_u *fname;
22742285
linenr_T dummy;
22752286

2276-
if (buflist_name_nr(0, &fname, &dummy) != FAIL)
2287+
if (buflist_name_nr(0, &fname, &dummy) != FAIL
2288+
&& !message_filtered(fname))
22772289
{
22782290
msg_puts("\n c \"# ");
22792291
dis_msg(fname, FALSE);
@@ -2282,7 +2294,8 @@ ex_display(exarg_T *eap)
22822294

22832295
// display last search pattern
22842296
if (last_search_pat() != NULL
2285-
&& (arg == NULL || vim_strchr(arg, '/') != NULL) && !got_int)
2297+
&& (arg == NULL || vim_strchr(arg, '/') != NULL) && !got_int
2298+
&& !message_filtered(last_search_pat()))
22862299
{
22872300
msg_puts("\n c \"/ ");
22882301
dis_msg(last_search_pat(), FALSE);
@@ -2291,7 +2304,7 @@ ex_display(exarg_T *eap)
22912304
#ifdef FEAT_EVAL
22922305
// display last used expression
22932306
if (expr_line != NULL && (arg == NULL || vim_strchr(arg, '=') != NULL)
2294-
&& !got_int)
2307+
&& !got_int && !message_filtered(expr_line))
22952308
{
22962309
msg_puts("\n c \"= ");
22972310
dis_msg(expr_line, FALSE);

src/testdir/test_filter_cmd.vim

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,30 @@ func Test_filter_commands()
145145
bwipe! file.h
146146
bwipe! file.hs
147147
endfunc
148+
149+
func Test_filter_display()
150+
edit Xdoesnotmatch
151+
let @a = '!!willmatch'
152+
let @b = '!!doesnotmatch'
153+
let @c = "oneline\ntwoline\nwillmatch\n"
154+
let @/ = '!!doesnotmatch'
155+
call feedkeys(":echo '!!doesnotmatch:'\<CR>", 'ntx')
156+
let lines = map(split(execute('filter /willmatch/ display'), "\n"), 'v:val[5:6]')
157+
158+
call assert_true(index(lines, '"a') >= 0)
159+
call assert_false(index(lines, '"b') >= 0)
160+
call assert_true(index(lines, '"c') >= 0)
161+
call assert_false(index(lines, '"/') >= 0)
162+
call assert_false(index(lines, '":') >= 0)
163+
call assert_false(index(lines, '"%') >= 0)
164+
165+
let lines = map(split(execute('filter /doesnotmatch/ display'), "\n"), 'v:val[5:6]')
166+
call assert_true(index(lines, '"a') < 0)
167+
call assert_false(index(lines, '"b') < 0)
168+
call assert_true(index(lines, '"c') < 0)
169+
call assert_false(index(lines, '"/') < 0)
170+
call assert_false(index(lines, '":') < 0)
171+
call assert_false(index(lines, '"%') < 0)
172+
173+
bwipe!
174+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,8 @@ static char *(features[]) =
741741

742742
static int included_patches[] =
743743
{ /* Add new patch number below this line */
744+
/**/
745+
2221,
744746
/**/
745747
2220,
746748
/**/

0 commit comments

Comments
 (0)