Skip to content

Commit f90c855

Browse files
committed
patch 8.2.2634: 'tagfunc' does not indicate using a pattern
Problem: 'tagfunc' does not indicate using a pattern. Solution: Add the "r" flag. (Andy Massimino, closes #7982)
1 parent 196a1f7 commit f90c855

4 files changed

Lines changed: 29 additions & 8 deletions

File tree

runtime/doc/tagsrch.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -888,19 +888,25 @@ like |CTRL-]|.
888888

889889
The function used for generating the taglist is specified by setting the
890890
'tagfunc' option. The function will be called with three arguments:
891-
a:pattern The tag identifier used during the tag search.
892-
a:flags List of flags to control the function behavior.
891+
a:pattern The tag identifier or pattern used during the tag search.
892+
a:flags String containing flags to control the function behavior.
893893
a:info Dict containing the following entries:
894894
buf_ffname Full filename which can be used for priority.
895895
user_data Custom data String, if stored in the tag
896896
stack previously by tagfunc.
897897

898-
Currently two flags may be passed to the tag function:
898+
Currently up to three flags may be passed to the tag function:
899899
'c' The function was invoked by a normal command being processed
900900
(mnemonic: the tag function may use the context around the
901901
cursor to perform a better job of generating the tag list.)
902902
'i' In Insert mode, the user was completing a tag (with
903-
|i_CTRL-X_CTRL-]|).
903+
|i_CTRL-X_CTRL-]| or 'completeopt' contains `t`).
904+
'r' The first argument to tagfunc should be interpreted as a
905+
|pattern| (see |tag-regexp|), such as when using: >
906+
:tag /pat
907+
< It is also given when completing in insert mode.
908+
If this flag is not present, the argument is usually taken
909+
literally as the full tag name.
904910

905911
Note that when 'tagfunc' is set, the priority of the tags described in
906912
|tag-priority| does not apply. Instead, the priority is exactly as the

src/tag.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ find_tagfunc_tags(
13081308
int result = FAIL;
13091309
typval_T args[4];
13101310
typval_T rettv;
1311-
char_u flagString[3];
1311+
char_u flagString[4];
13121312
dict_T *d;
13131313
taggy_T *tag = &curwin->w_tagstack[curwin->w_tagstackidx];
13141314

@@ -1335,9 +1335,10 @@ find_tagfunc_tags(
13351335
args[3].v_type = VAR_UNKNOWN;
13361336

13371337
vim_snprintf((char *)flagString, sizeof(flagString),
1338-
"%s%s",
1338+
"%s%s%s",
13391339
g_tag_at_cursor ? "c": "",
1340-
flags & TAG_INS_COMP ? "i": "");
1340+
flags & TAG_INS_COMP ? "i": "",
1341+
flags & TAG_REGEXP ? "r": "");
13411342

13421343
save_pos = curwin->w_cursor;
13431344
result = call_vim_function(curbuf->b_p_tfu, 3, args, &rettv);

src/testdir/test_tagfunc.vim

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,24 @@ func Test_tagfunc()
4343
call assert_equal('one', g:tagfunc_args[0])
4444
call assert_equal('c', g:tagfunc_args[1])
4545

46+
let g:tagfunc_args=[]
47+
execute "tag /foo$"
48+
call assert_equal('foo$', g:tagfunc_args[0])
49+
call assert_equal('r', g:tagfunc_args[1])
50+
4651
set cpt=t
4752
let g:tagfunc_args=[]
4853
execute "normal! i\<c-n>\<c-y>"
49-
call assert_equal('ci', g:tagfunc_args[1])
54+
call assert_equal('\<\k\k', g:tagfunc_args[0])
55+
call assert_equal('cir', g:tagfunc_args[1])
5056
call assert_equal('nothing1', getline('.')[0:7])
5157

58+
let g:tagfunc_args=[]
59+
execute "normal! ono\<c-n>\<c-n>\<c-y>"
60+
call assert_equal('\<no', g:tagfunc_args[0])
61+
call assert_equal('cir', g:tagfunc_args[1])
62+
call assert_equal('nothing2', getline('.')[0:7])
63+
5264
func BadTagFunc1(...)
5365
return 0
5466
endfunc

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2634,
753755
/**/
754756
2633,
755757
/**/

0 commit comments

Comments
 (0)