patch 8.0.0499: taglist() does not prioritize tags for a buffer v8.0.0499
authorBram Moolenaar <Bram@vim.org>
Tue, 21 Mar 2017 16:09:10 +0000 (17:09 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 21 Mar 2017 16:09:10 +0000 (17:09 +0100)
Problem:    taglist() does not prioritize tags for a buffer.
Solution:   Add an optional buffer argument. (Duncan McDougall, closes #1194)

runtime/doc/eval.txt
src/Makefile
src/evalfunc.c
src/proto/tag.pro
src/tag.c
src/testdir/test_alot.vim
src/testdir/test_taglist.vim [new file with mode: 0644]
src/version.c

index 5fa31a2e73f16cf353d4ede451d30e6a9771a017..ff1b71feebdb7c6e55d9e2627a0b2d0251dcd6e9 100644 (file)
@@ -2363,7 +2363,7 @@ systemlist({expr} [, {input}])    List    output of shell command/filter {expr}
 tabpagebuflist([{arg}])                List    list of buffer numbers in tab page
 tabpagenr([{arg}])             Number  number of current or last tab page
 tabpagewinnr({tabarg}[, {arg}]) Number number of current window in tab page
-taglist({expr})                        List    list of tags matching {expr}
+taglist({expr}[, {filename}])  List    list of tags matching {expr}
 tagfiles()                     List    tags files used
 tan({expr})                    Float   tangent of {expr}
 tanh({expr})                   Float   hyperbolic tangent of {expr}
@@ -7741,8 +7741,13 @@ tagfiles()       Returns a |List| with the file names used to search for tags
                for the current buffer.  This is the 'tags' option expanded.
 
 
-taglist({expr})                                                        *taglist()*
+taglist({expr}[, {filename}])                          *taglist()*
                Returns a list of tags matching the regular expression {expr}.
+
+               If {filename} is passed it is used to prioritize the results
+               in the same way that |:tselect| does. See |tag-priority|.
+               {filename} should be the full path of the file.
+
                Each list item is a dictionary with at least the following
                entries:
                        name            Name of the tag.
index 3d13b85e53d08de1e2a1d75cc394584ec8952b73..1309a636d6d8d080c2439f1de2886e30515be0a3 100644 (file)
@@ -2213,6 +2213,7 @@ test_arglist \
        test_tabpage \
        test_tagcase \
        test_tagjump \
+       test_taglist \
        test_tcl \
        test_textobjects \
        test_timers \
index 5dc7f827300f60f4b0de5a051ae106b4ed748ec4..8869810dfac50f81353e5cba086bac39c76f2338 100644 (file)
@@ -824,7 +824,7 @@ static struct fst
     {"tabpagenr",      0, 1, f_tabpagenr},
     {"tabpagewinnr",   1, 2, f_tabpagewinnr},
     {"tagfiles",       0, 0, f_tagfiles},
-    {"taglist",                1, 1, f_taglist},
+    {"taglist",                1, 2, f_taglist},
 #ifdef FEAT_FLOAT
     {"tan",            1, 1, f_tan},
     {"tanh",           1, 1, f_tanh},
@@ -3589,7 +3589,8 @@ f_foldtextresult(typval_T *argvars UNUSED, typval_T *rettv)
     fold_count = foldedCount(curwin, lnum, &foldinfo);
     if (fold_count > 0)
     {
-       text = get_foldtext(curwin, lnum, lnum + fold_count - 1, &foldinfo, buf);
+       text = get_foldtext(curwin, lnum, lnum + fold_count - 1,
+                                                              &foldinfo, buf);
        if (text == buf)
            text = vim_strsave(text);
        rettv->vval.v_string = text;
@@ -12267,6 +12268,7 @@ f_tagfiles(typval_T *argvars UNUSED, typval_T *rettv)
     static void
 f_taglist(typval_T *argvars, typval_T *rettv)
 {
+    char_u  *fname = NULL;
     char_u  *tag_pattern;
 
     tag_pattern = get_tv_string(&argvars[0]);
@@ -12275,8 +12277,10 @@ f_taglist(typval_T *argvars, typval_T *rettv)
     if (*tag_pattern == NUL)
        return;
 
+    if (argvars[1].v_type != VAR_UNKNOWN)
+       fname = get_tv_string(&argvars[1]);
     if (rettv_list_alloc(rettv) == OK)
-       (void)get_tags(rettv->vval.v_list, tag_pattern);
+       (void)get_tags(rettv->vval.v_list, tag_pattern, fname);
 }
 
 /*
index 55f579da62613816413ba4d45b4b0ab1cd4314a2..497a76e38be53795f89d514feff0fb17885174b0 100644 (file)
@@ -8,5 +8,5 @@ int get_tagfname(tagname_T *tnp, int first, char_u *buf);
 void tagname_free(tagname_T *tnp);
 void simplify_filename(char_u *filename);
 int expand_tags(int tagnames, char_u *pat, int *num_file, char_u ***file);
-int get_tags(list_T *list, char_u *pat);
+int get_tags(list_T *list, char_u *pat, char_u *buf_fname);
 /* vim: set ft=c : */
index 68d09c54556466779f0e36795d0834ef84fc30ee..7710135fa3b8dbeebafe993b1eb4512aa9b051d0 100644 (file)
--- a/src/tag.c
+++ b/src/tag.c
@@ -3876,11 +3876,11 @@ add_tag_field(
 }
 
 /*
- * Add the tags matching the specified pattern to the list "list"
- * as a dictionary
+ * Add the tags matching the specified pattern "pat" to the list "list"
+ * as a dictionary. Use "buf_fname" for priority, unless NULL.
  */
     int
-get_tags(list_T *list, char_u *pat)
+get_tags(list_T *list, char_u *pat, char_u *buf_fname)
 {
     int                num_matches, i, ret;
     char_u     **matches, *p;
@@ -3890,7 +3890,7 @@ get_tags(list_T *list, char_u *pat)
     long       is_static;
 
     ret = find_tags(pat, &num_matches, &matches,
-                                   TAG_REGEXP | TAG_NOIC, (int)MAXCOL, NULL);
+                               TAG_REGEXP | TAG_NOIC, (int)MAXCOL, buf_fname);
     if (ret == OK && num_matches > 0)
     {
        for (i = 0; i < num_matches; ++i)
index 314a5b7f5a1205743e5dc8fb9ce041e0897c249e..7b31575ae9f3088fc361ed6d77aba83717949309 100644 (file)
@@ -47,6 +47,7 @@ source test_tabline.vim
 source test_tabpage.vim
 source test_tagcase.vim
 source test_tagjump.vim
+source test_taglist.vim
 source test_timers.vim
 source test_true_false.vim
 source test_unlet.vim
diff --git a/src/testdir/test_taglist.vim b/src/testdir/test_taglist.vim
new file mode 100644 (file)
index 0000000..b89b25e
--- /dev/null
@@ -0,0 +1,21 @@
+" test 'taglist' function
+
+func Test_taglist()
+  call writefile([
+       \ "FFoo\tXfoo\t1",
+       \ "FBar\tXfoo\t2",
+       \ "BFoo\tXbar\t1",
+       \ "BBar\tXbar\t2"
+       \ ], 'Xtags')
+  set tags=Xtags
+  split Xtext
+
+  call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo"), {i, v -> v.name}))
+  call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo", "Xtext"), {i, v -> v.name}))
+  call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo", "Xfoo"), {i, v -> v.name}))
+  call assert_equal(['BFoo', 'FFoo'], map(taglist("Foo", "Xbar"), {i, v -> v.name}))
+
+  call delete('Xtags')
+  bwipe
+endfunc
+
index ba8ff84d181642808f5252c7b4471fdb9b4ae806..3b651ccaeae8a7aa7d90575df96a96b3bb36d093 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    499,
 /**/
     498,
 /**/