Skip to content

Commit 077b9dd

Browse files
committed
patch 8.1.2312: "line:" field in tags file not used
Problem: "line:" field in tags file not used. Solution: Recognize the field and use the value. (Andy Massimino, Daniel Hahler, closes #5232, closes #2546, closes #1057)
1 parent 09c6f26 commit 077b9dd

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/tag.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ typedef struct tag_pointers
3535
char_u *tagkind_end; // end of tagkind
3636
char_u *user_data; // user_data string
3737
char_u *user_data_end; // end of user_data
38+
linenr_T tagline; // "line:" value
3839
} tagptrs_T;
3940

4041
/*
@@ -3217,6 +3218,7 @@ parse_match(
32173218

32183219
tagp->tagkind = NULL;
32193220
tagp->user_data = NULL;
3221+
tagp->tagline = 0;
32203222
tagp->command_end = NULL;
32213223

32223224
if (retval == OK)
@@ -3237,6 +3239,8 @@ parse_match(
32373239
tagp->tagkind = p + 5;
32383240
else if (STRNCMP(p, "user_data:", 10) == 0)
32393241
tagp->user_data = p + 10;
3242+
else if (STRNCMP(p, "line:", 5) == 0)
3243+
tagp->tagline = atoi((char *)p + 5);
32403244
if (tagp->tagkind != NULL && tagp->user_data != NULL)
32413245
break;
32423246
pc = vim_strchr(p, ':');
@@ -3537,7 +3541,12 @@ jumpto_tag(
35373541
p_ic = FALSE; /* don't ignore case now */
35383542
p_scs = FALSE;
35393543
save_lnum = curwin->w_cursor.lnum;
3540-
curwin->w_cursor.lnum = 0; /* start search before first line */
3544+
if (tagp.tagline > 0)
3545+
// start search before line from "line:" field
3546+
curwin->w_cursor.lnum = tagp.tagline - 1;
3547+
else
3548+
// start search before first line
3549+
curwin->w_cursor.lnum = 0;
35413550
if (do_search(NULL, pbuf[0], pbuf + 1, (long)1,
35423551
search_options, NULL))
35433552
retval = OK;

src/testdir/test_tagjump.vim

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,4 +526,28 @@ func Test_tselect()
526526
call delete('XTest_tselect')
527527
endfunc
528528

529+
func Test_tagline()
530+
call writefile([
531+
\ 'provision Xtest.py /^ def provision(self, **kwargs):$/;" m line:1 language:Python class:Foo',
532+
\ 'provision Xtest.py /^ def provision(self, **kwargs):$/;" m line:3 language:Python class:Bar',
533+
\], 'Xtags')
534+
call writefile([
535+
\ ' def provision(self, **kwargs):',
536+
\ ' pass',
537+
\ ' def provision(self, **kwargs):',
538+
\ ' pass',
539+
\], 'Xtest.py')
540+
541+
set tags=Xtags
542+
543+
1tag provision
544+
call assert_equal(line('.'), 1)
545+
2tag provision
546+
call assert_equal(line('.'), 3)
547+
548+
call delete('Xtags')
549+
call delete('Xtest.py')
550+
set tags&
551+
endfunc
552+
529553
" vim: shiftwidth=2 sts=2 expandtab

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+
2312,
744746
/**/
745747
2311,
746748
/**/

0 commit comments

Comments
 (0)