Skip to content

Commit a9d23c2

Browse files
committed
patch 8.0.0195: fail to jump to static tag in current file
Problem: Jumping to a tag that is a static item in the current file fails. (Kazunobu Kuriyama) Solution: Make sure the first byte of the tag key is not NUL. (Suggested by James McCoy, closes #1387)
1 parent e32bbde commit a9d23c2

3 files changed

Lines changed: 33 additions & 10 deletions

File tree

src/tag.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ typedef struct tag_pointers
4444
#define MT_GL_CUR 1 /* global match in current file */
4545
#define MT_GL_OTH 2 /* global match in other file */
4646
#define MT_ST_OTH 3 /* static match in other file */
47-
#define MT_IC_ST_CUR 4 /* icase static match in current file */
48-
#define MT_IC_GL_CUR 5 /* icase global match in current file */
49-
#define MT_IC_GL_OTH 6 /* icase global match in other file */
50-
#define MT_IC_ST_OTH 7 /* icase static match in other file */
5147
#define MT_IC_OFF 4 /* add for icase match */
5248
#define MT_RE_OFF 8 /* add for regexp match */
5349
#define MT_MASK 7 /* mask for printing priority */
@@ -2317,7 +2313,7 @@ find_tags(
23172313
if (tagp.command + 2 < temp_end)
23182314
{
23192315
len = (int)(temp_end - tagp.command - 2);
2320-
mfp = (char_u *)alloc((int)sizeof(char_u) + len + 1);
2316+
mfp = (char_u *)alloc(len + 2);
23212317
if (mfp != NULL)
23222318
vim_strncpy(mfp, tagp.command + 2, len);
23232319
}
@@ -2351,6 +2347,7 @@ find_tags(
23512347
* Emacs tag: <mtt><tag_fname><0x01><ebuf><0x01><lbuf><NUL>
23522348
* other tag: <mtt><tag_fname><0x01><0x01><lbuf><NUL>
23532349
* without Emacs tags: <mtt><tag_fname><0x01><lbuf><NUL>
2350+
* Here <mtt> is the "mtt" value plus 1 to avoid NUL.
23542351
*/
23552352
len = (int)tag_fname_len + (int)STRLEN(lbuf) + 3;
23562353
#ifdef FEAT_EMACS_TAGS
@@ -2366,7 +2363,7 @@ find_tags(
23662363
if (mfp != NULL)
23672364
{
23682365
p = mfp;
2369-
p[0] = mtt;
2366+
p[0] = mtt + 1;
23702367
STRCPY(p + 1, tag_fname);
23712368
#ifdef BACKSLASH_IN_FILENAME
23722369
/* Ignore differences in slashes, avoid adding
@@ -2548,10 +2545,16 @@ find_tags(
25482545
vim_free(mfp);
25492546
else
25502547
{
2551-
/* now change the TAG_SEP back to NUL */
2552-
for (p = mfp; *p != NUL; ++p)
2553-
if (*p == TAG_SEP)
2554-
*p = NUL;
2548+
if (!name_only)
2549+
{
2550+
/* Change mtt back to zero-based. */
2551+
*mfp = *mfp - 1;
2552+
2553+
/* change the TAG_SEP back to NUL */
2554+
for (p = mfp + 1; *p != NUL; ++p)
2555+
if (*p == TAG_SEP)
2556+
*p = NUL;
2557+
}
25552558
matches[match_count++] = (char_u *)mfp;
25562559
}
25572560
todo--;

src/testdir/test_tagjump.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ func Test_cancel_ptjump()
2323
quit
2424
endfunc
2525

26+
func Test_static_tagjump()
27+
set tags=Xtags
28+
call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
29+
\ "one\tXfile1\t/^one/;\"\tf\tfile:\tsignature:(void)",
30+
\ "word\tXfile2\tcmd2"],
31+
\ 'Xtags')
32+
new Xfile1
33+
call setline(1, ['empty', 'one()', 'empty'])
34+
write
35+
tag one
36+
call assert_equal(2, line('.'))
37+
38+
set tags&
39+
call delete('Xtags')
40+
call delete('Xfile1')
41+
bwipe!
42+
endfunc
43+
2644
" Tests for [ CTRL-I and CTRL-W CTRL-I commands
2745
function Test_keyword_jump()
2846
call writefile(["#include Xinclude", "",

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+
195,
767769
/**/
768770
194,
769771
/**/

0 commit comments

Comments
 (0)