Skip to content

Commit c6aafba

Browse files
committed
patch 8.0.0499: taglist() does not prioritize tags for a buffer
Problem: taglist() does not prioritize tags for a buffer. Solution: Add an optional buffer argument. (Duncan McDougall, closes #1194)
1 parent e94260f commit c6aafba

8 files changed

Lines changed: 44 additions & 10 deletions

File tree

runtime/doc/eval.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2363,7 +2363,7 @@ systemlist({expr} [, {input}]) List output of shell command/filter {expr}
23632363
tabpagebuflist([{arg}]) List list of buffer numbers in tab page
23642364
tabpagenr([{arg}]) Number number of current or last tab page
23652365
tabpagewinnr({tabarg}[, {arg}]) Number number of current window in tab page
2366-
taglist({expr}) List list of tags matching {expr}
2366+
taglist({expr}[, {filename}]) List list of tags matching {expr}
23672367
tagfiles() List tags files used
23682368
tan({expr}) Float tangent of {expr}
23692369
tanh({expr}) Float hyperbolic tangent of {expr}
@@ -7741,8 +7741,13 @@ tagfiles() Returns a |List| with the file names used to search for tags
77417741
for the current buffer. This is the 'tags' option expanded.
77427742

77437743

7744-
taglist({expr}) *taglist()*
7744+
taglist({expr}[, {filename}]) *taglist()*
77457745
Returns a list of tags matching the regular expression {expr}.
7746+
7747+
If {filename} is passed it is used to prioritize the results
7748+
in the same way that |:tselect| does. See |tag-priority|.
7749+
{filename} should be the full path of the file.
7750+
77467751
Each list item is a dictionary with at least the following
77477752
entries:
77487753
name Name of the tag.

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,7 @@ test_arglist \
22132213
test_tabpage \
22142214
test_tagcase \
22152215
test_tagjump \
2216+
test_taglist \
22162217
test_tcl \
22172218
test_textobjects \
22182219
test_timers \

src/evalfunc.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ static struct fst
824824
{"tabpagenr", 0, 1, f_tabpagenr},
825825
{"tabpagewinnr", 1, 2, f_tabpagewinnr},
826826
{"tagfiles", 0, 0, f_tagfiles},
827-
{"taglist", 1, 1, f_taglist},
827+
{"taglist", 1, 2, f_taglist},
828828
#ifdef FEAT_FLOAT
829829
{"tan", 1, 1, f_tan},
830830
{"tanh", 1, 1, f_tanh},
@@ -3589,7 +3589,8 @@ f_foldtextresult(typval_T *argvars UNUSED, typval_T *rettv)
35893589
fold_count = foldedCount(curwin, lnum, &foldinfo);
35903590
if (fold_count > 0)
35913591
{
3592-
text = get_foldtext(curwin, lnum, lnum + fold_count - 1, &foldinfo, buf);
3592+
text = get_foldtext(curwin, lnum, lnum + fold_count - 1,
3593+
&foldinfo, buf);
35933594
if (text == buf)
35943595
text = vim_strsave(text);
35953596
rettv->vval.v_string = text;
@@ -12267,6 +12268,7 @@ f_tagfiles(typval_T *argvars UNUSED, typval_T *rettv)
1226712268
static void
1226812269
f_taglist(typval_T *argvars, typval_T *rettv)
1226912270
{
12271+
char_u *fname = NULL;
1227012272
char_u *tag_pattern;
1227112273

1227212274
tag_pattern = get_tv_string(&argvars[0]);
@@ -12275,8 +12277,10 @@ f_taglist(typval_T *argvars, typval_T *rettv)
1227512277
if (*tag_pattern == NUL)
1227612278
return;
1227712279

12280+
if (argvars[1].v_type != VAR_UNKNOWN)
12281+
fname = get_tv_string(&argvars[1]);
1227812282
if (rettv_list_alloc(rettv) == OK)
12279-
(void)get_tags(rettv->vval.v_list, tag_pattern);
12283+
(void)get_tags(rettv->vval.v_list, tag_pattern, fname);
1228012284
}
1228112285

1228212286
/*

src/proto/tag.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ int get_tagfname(tagname_T *tnp, int first, char_u *buf);
88
void tagname_free(tagname_T *tnp);
99
void simplify_filename(char_u *filename);
1010
int expand_tags(int tagnames, char_u *pat, int *num_file, char_u ***file);
11-
int get_tags(list_T *list, char_u *pat);
11+
int get_tags(list_T *list, char_u *pat, char_u *buf_fname);
1212
/* vim: set ft=c : */

src/tag.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3876,11 +3876,11 @@ add_tag_field(
38763876
}
38773877

38783878
/*
3879-
* Add the tags matching the specified pattern to the list "list"
3880-
* as a dictionary
3879+
* Add the tags matching the specified pattern "pat" to the list "list"
3880+
* as a dictionary. Use "buf_fname" for priority, unless NULL.
38813881
*/
38823882
int
3883-
get_tags(list_T *list, char_u *pat)
3883+
get_tags(list_T *list, char_u *pat, char_u *buf_fname)
38843884
{
38853885
int num_matches, i, ret;
38863886
char_u **matches, *p;
@@ -3890,7 +3890,7 @@ get_tags(list_T *list, char_u *pat)
38903890
long is_static;
38913891

38923892
ret = find_tags(pat, &num_matches, &matches,
3893-
TAG_REGEXP | TAG_NOIC, (int)MAXCOL, NULL);
3893+
TAG_REGEXP | TAG_NOIC, (int)MAXCOL, buf_fname);
38943894
if (ret == OK && num_matches > 0)
38953895
{
38963896
for (i = 0; i < num_matches; ++i)

src/testdir/test_alot.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ source test_tabline.vim
4747
source test_tabpage.vim
4848
source test_tagcase.vim
4949
source test_tagjump.vim
50+
source test_taglist.vim
5051
source test_timers.vim
5152
source test_true_false.vim
5253
source test_unlet.vim

src/testdir/test_taglist.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
" test 'taglist' function
2+
3+
func Test_taglist()
4+
call writefile([
5+
\ "FFoo\tXfoo\t1",
6+
\ "FBar\tXfoo\t2",
7+
\ "BFoo\tXbar\t1",
8+
\ "BBar\tXbar\t2"
9+
\ ], 'Xtags')
10+
set tags=Xtags
11+
split Xtext
12+
13+
call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo"), {i, v -> v.name}))
14+
call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo", "Xtext"), {i, v -> v.name}))
15+
call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo", "Xfoo"), {i, v -> v.name}))
16+
call assert_equal(['BFoo', 'FFoo'], map(taglist("Foo", "Xbar"), {i, v -> v.name}))
17+
18+
call delete('Xtags')
19+
bwipe
20+
endfunc
21+

src/version.c

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

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
499,
767769
/**/
768770
498,
769771
/**/

0 commit comments

Comments
 (0)