patch 9.1.1423: :tag command not working correctly using Vim9 Script Commit: https://github.com/vim/vim/commit/cba66cf894645e1a16e926be75c5ab12cbf3b35a Author: Christian Brabandt <c...@256bit.org> Date: Sun Jun 1 19:47:03 2025 +0200
patch 9.1.1423: :tag command not working correctly using Vim9 Script Problem: :tag command not working correctly using Vim9 Script Solution: inject a ':' before the numeric address, to make the command valid in Vim9 context fixes: #17415 closes: #17418 Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/src/tag.c b/src/tag.c index b36415c96..6912e8743 100644 --- a/src/tag.c +++ b/src/tag.c @@ -3714,6 +3714,7 @@ jumpto_tag( #endif size_t len; char_u *lbuf; + int isdigit = FALSE; if (postponed_split == 0 && !check_can_set_curbuf_forceit(forceit)) return FAIL; @@ -3725,7 +3726,7 @@ jumpto_tag( if (lbuf != NULL) mch_memmove(lbuf, lbuf_arg, len); - pbuf = alloc(LSIZE); + pbuf = alloc_clear(LSIZE); // parse the match line into the tagp structure if (pbuf == NULL || lbuf == NULL || parse_match(lbuf, &tagp) == FAIL) @@ -3740,14 +3741,21 @@ jumpto_tag( // copy the command to pbuf[], remove trailing CR/NL str = tagp.command; - for (pbuf_end = pbuf; *str && *str != ' ' && *str != ' '; ) + if (VIM_ISDIGIT(*str)) + { + // need to inject a ':' for a proper Vim9 :nr command + isdigit = TRUE; + pbuf[0] = ':'; + } + for (pbuf_end = pbuf + isdigit; + *str && *str != ' ' && *str != ' '; ) { #ifdef FEAT_EMACS_TAGS if (tagp.is_etag && *str == ',')// stop at ',' after line number break; #endif *pbuf_end++ = *str++; - if (pbuf_end - pbuf + 1 >= LSIZE) + if (pbuf_end - pbuf + 1 + isdigit >= LSIZE) break; } *pbuf_end = NUL; @@ -3760,6 +3768,9 @@ jumpto_tag( * Remove the "<Tab>fieldname:value" stuff; we don't need it here. */ str = pbuf; + // skip over the ':' + if (isdigit) + str++; if (find_extra(&str) == OK) { pbuf_end = str; diff --git a/src/testdir/test_tagjump.vim b/src/testdir/test_tagjump.vim index e4b258c57..f53d9b88f 100644 --- a/src/testdir/test_tagjump.vim +++ b/src/testdir/test_tagjump.vim @@ -1650,4 +1650,25 @@ func Test_tag_excmd_with_nostartofline() set startofline& endfunc +func Test_tag_excmd_with_number_vim9script() + call writefile(["1#1 Xfile 2;\" i"], 'Xtags', 'D') + call writefile(['f', 'foobar'], 'Xfile', 'D') + let list =<< trim END + vim9script + command! Tag call Tag() + def Tag(): void + exe "tag 1#1" + enddef + END + call writefile(list, 'Xtags.vim', 'D') + + setlocal tags=Xtags + so Xtags.vim + :Tag + call assert_equal('Xfile', bufname('%')) + call assert_equal(2, line('.')) + + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/version.c b/src/version.c index 01c3050d1..e7cabf84a 100644 --- a/src/version.c +++ b/src/version.c @@ -709,6 +709,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1423, /**/ 1422, /**/ -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1uLmyb-00BYLH-Ir%40256bit.org.