Skip to content

Commit ad6dc49

Browse files
committed
patch 8.1.1221: filtering does not work when listing marks
Problem: Filtering does not work when listing marks. Solution: Implement filtering marks. (Marcin Szamotulski, closes #3895)
1 parent 0ee1bdf commit ad6dc49

4 files changed

Lines changed: 55 additions & 32 deletions

File tree

runtime/doc/various.txt

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -571,17 +571,19 @@ N *+X11* Unix only: can restore window title |X11|
571571
the output, not necessarily the whole line. Only some
572572
commands support filtering, try it out to check if it
573573
works. Some of the commands that support filtering:
574-
|:#| - filter whole line
575-
|:command| - filter by command name
576-
|:files| - filter by file name
577-
|:highlight| - filter by highlight group
578-
|:jumps| - filter by file name
579-
|:let| - filter by variable name
580-
|:list| - filter whole line
581-
|:llist| - filter by file name or module name
582-
|:oldfiles| - filter by file name
583-
|:clist| - filter by file name or module name
584-
|:set| - filter by variable name
574+
|:#| - filter whole line
575+
|:clist| - filter by file name or module name
576+
|:command| - filter by command name
577+
|:files| - filter by file name
578+
|:highlight| - filter by highlight group
579+
|:jumps| - filter by file name
580+
|:let| - filter by variable name
581+
|:list| - filter whole line
582+
|:llist| - filter by file name or module name
583+
|:marks| - filter by text in the current file,
584+
or file name for other files
585+
|:oldfiles| - filter by file name
586+
|:set| - filter by variable name
585587

586588
Only normal messages are filtered, error messages are
587589
not.

src/mark.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -744,11 +744,12 @@ show_one_mark(
744744
int c,
745745
char_u *arg,
746746
pos_T *p,
747-
char_u *name,
747+
char_u *name_arg,
748748
int current) /* in current file */
749749
{
750750
static int did_title = FALSE;
751751
int mustfree = FALSE;
752+
char_u *name = name_arg;
752753

753754
if (c == -1) /* finish up */
754755
{
@@ -762,35 +763,38 @@ show_one_mark(
762763
semsg(_("E283: No marks matching \"%s\""), arg);
763764
}
764765
}
765-
/* don't output anything if 'q' typed at --more-- prompt */
766+
// don't output anything if 'q' typed at --more-- prompt
766767
else if (!got_int
767768
&& (arg == NULL || vim_strchr(arg, c) != NULL)
768769
&& p->lnum != 0)
769770
{
770-
if (!did_title)
771+
if (name == NULL && current)
771772
{
772-
/* Highlight title */
773-
msg_puts_title(_("\nmark line col file/text"));
774-
did_title = TRUE;
773+
name = mark_line(p, 15);
774+
mustfree = TRUE;
775775
}
776-
msg_putchar('\n');
777-
if (!got_int)
776+
if (!message_filtered(name))
778777
{
779-
sprintf((char *)IObuff, " %c %6ld %4d ", c, p->lnum, p->col);
780-
msg_outtrans(IObuff);
781-
if (name == NULL && current)
778+
if (!did_title)
782779
{
783-
name = mark_line(p, 15);
784-
mustfree = TRUE;
780+
// Highlight title
781+
msg_puts_title(_("\nmark line col file/text"));
782+
did_title = TRUE;
785783
}
786-
if (name != NULL)
784+
msg_putchar('\n');
785+
if (!got_int)
787786
{
788-
msg_outtrans_attr(name, current ? HL_ATTR(HLF_D) : 0);
789-
if (mustfree)
790-
vim_free(name);
787+
sprintf((char *)IObuff, " %c %6ld %4d ", c, p->lnum, p->col);
788+
msg_outtrans(IObuff);
789+
if (name != NULL)
790+
{
791+
msg_outtrans_attr(name, current ? HL_ATTR(HLF_D) : 0);
792+
}
791793
}
794+
out_flush(); // show one line at a time
792795
}
793-
out_flush(); /* show one line at a time */
796+
if (mustfree)
797+
vim_free(name);
794798
}
795799
}
796800

src/testdir/test_filter_cmd.vim

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,22 @@ func Test_filter_commands()
126126
let res = split(execute("filter /\.c$/ jumps"), "\n")[1:]
127127
call assert_equal([" 2 1 0 file.c", ">"], res)
128128

129-
bwipe file.c
130-
bwipe file.h
131-
bwipe file.hs
129+
" Test filtering :marks command
130+
b file.c
131+
mark A
132+
b file.h
133+
mark B
134+
let res = split(execute("filter /\.c$/ marks"), "\n")[1:]
135+
call assert_equal([" A 1 0 file.c"], res)
136+
137+
call setline(1, ['one', 'two', 'three'])
138+
1mark a
139+
2mark b
140+
3mark c
141+
let res = split(execute("filter /two/ marks abc"), "\n")[1:]
142+
call assert_equal([" b 2 0 two"], res)
143+
144+
bwipe! file.c
145+
bwipe! file.h
146+
bwipe! file.hs
132147
endfunc

src/version.c

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

768768
static int included_patches[] =
769769
{ /* Add new patch number below this line */
770+
/**/
771+
1221,
770772
/**/
771773
1220,
772774
/**/

0 commit comments

Comments
 (0)