From 4726231a850ce8d04cc0734fd2bf7f723c00ed3f Mon Sep 17 00:00:00 2001 From: Yuri Gribov Date: Fri, 27 Jun 2025 02:49:18 +0000 Subject: [PATCH] Address review comments. --- runtime/doc/options.txt | 11 ++++---- runtime/doc/tags | 4 +++ runtime/doc/tagsrch.txt | 12 ++++++++ src/option.h | 2 +- src/optiondefs.h | 6 ++-- src/testdir/Make_all.mak | 2 -- src/testdir/test_copytagstack.vim | 46 ------------------------------- src/testdir/test_tagjump.vim | 40 +++++++++++++++++++++++++++ src/window.c | 2 +- 9 files changed, 67 insertions(+), 58 deletions(-) delete mode 100644 src/testdir/test_copytagstack.vim diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 068736e619..d22007df65 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -2356,11 +2356,6 @@ A jump table for the options with a short description can be found at |Q_op|. NOTE: This option is reset when 'compatible' is set. Also see 'preserveindent'. - *'copytagstack'* *'cptgst'* *'nocopytagstack'* *'nocptgst'* -'copytagstack' 'cptgst' boolean (default: on) - global - Copy tag stack when splitting window. - *'cpoptions'* *'cpo'* *cpo* 'cpoptions' 'cpo' string (Vim default: "aABceFsz", Vi default: all flags, except "#{|&/\." @@ -8709,6 +8704,12 @@ A jump table for the options with a short description can be found at |Q_op|. Resetting this option is useful when using a ":tag" command in a mapping which should not change the tagstack. + *'tagstackcopy'* *'tgstcp'* *'notagstackcopy'* *'notgstcp'* +'tagstackcopy' 'tgstcp' boolean (default: on) + global + If on, the tagstack is copied from original windows when creating a + new one (e.g. via :split). When off, new windows start afresh. + *'tcldll'* 'tcldll' string (default depends on the build) global diff --git a/runtime/doc/tags b/runtime/doc/tags index afa4a058f4..ee0f5029cb 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -765,6 +765,7 @@ $quote eval.txt /*$quote* 'notagbsearch' options.txt /*'notagbsearch'* 'notagrelative' options.txt /*'notagrelative'* 'notagstack' options.txt /*'notagstack'* +'notagstackcopy' options.txt /*'notagstackcopy'* 'notbi' options.txt /*'notbi'* 'notbidi' options.txt /*'notbidi'* 'notbs' options.txt /*'notbs'* @@ -776,6 +777,7 @@ $quote eval.txt /*$quote* 'notf' options.txt /*'notf'* 'notgc' options.txt /*'notgc'* 'notgst' options.txt /*'notgst'* +'notgstcp' options.txt /*'notgstcp'* 'notildeop' options.txt /*'notildeop'* 'notimeout' options.txt /*'notimeout'* 'notitle' options.txt /*'notitle'* @@ -1196,6 +1198,7 @@ $quote eval.txt /*$quote* 'tagrelative' options.txt /*'tagrelative'* 'tags' options.txt /*'tags'* 'tagstack' options.txt /*'tagstack'* +'tagstackcopy' options.txt /*'tagstackcopy'* 'tal' options.txt /*'tal'* 'tb' options.txt /*'tb'* 'tbi' options.txt /*'tbi'* @@ -1222,6 +1225,7 @@ $quote eval.txt /*$quote* 'tfu' options.txt /*'tfu'* 'tgc' options.txt /*'tgc'* 'tgst' options.txt /*'tgst'* +'tgstcp' options.txt /*'tgstcp'* 'thesaurus' options.txt /*'thesaurus'* 'thesaurusfunc' options.txt /*'thesaurusfunc'* 'tildeop' options.txt /*'tildeop'* diff --git a/runtime/doc/tagsrch.txt b/runtime/doc/tagsrch.txt index 0717f2ffd6..5b75474636 100644 --- a/runtime/doc/tagsrch.txt +++ b/runtime/doc/tagsrch.txt @@ -185,6 +185,18 @@ commands explained above the tag stack will look like this: The |gettagstack()| function returns the tag stack of a specified window. The |settagstack()| function modifies the tag stack of a window. +In Vim, the tag stack is local to each window. When a new tab or window is +opened (e.g., via |:split| or |:tabnew|), the tag stack is copied from the +original window. This allows you to continue tag navigation seamlessly in the +new window. + +If you prefer not to copy the tag stack when splitting windows, set the +'tagstackcopy' option to off. + +Tag navigation commands (such as :tag, :pop, and CTRL-]) affect only the tag +stack of the current window. Each window maintains its own independent tag +stack. + *tagstack-examples* Write to the tag stack just like `:tag` but with a user-defined jumper#jump_to_tag function: > diff --git a/src/option.h b/src/option.h index 6599652c21..9cdbd06761 100644 --- a/src/option.h +++ b/src/option.h @@ -422,7 +422,6 @@ EXTERN char_u *p_ofu; // 'omnifunc' EXTERN char_u *p_tsrfu; // 'thesaurusfunc' #endif EXTERN int p_ci; // 'copyindent' -EXTERN int p_cptgst; // 'copytagstack' #if defined(FEAT_GUI) && defined(MACOS_X) EXTERN int *p_antialias; // 'antialias' #endif @@ -1014,6 +1013,7 @@ EXTERN long p_tl; // 'taglength' EXTERN int p_tr; // 'tagrelative' EXTERN char_u *p_tags; // 'tags' EXTERN int p_tgst; // 'tagstack' +EXTERN int p_tgstcp; // 'tagstackcopy' #if defined(DYNAMIC_TCL) EXTERN char_u *p_tcldll; // 'tcldll' #endif diff --git a/src/optiondefs.h b/src/optiondefs.h index f1d32d88c6..a87fe1bc97 100644 --- a/src/optiondefs.h +++ b/src/optiondefs.h @@ -727,9 +727,6 @@ static struct vimoption options[] = {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM, (char_u *)&p_ci, PV_CI, NULL, NULL, {(char_u *)FALSE, (char_u *)0L} SCTX_INIT}, - {"copytagstack", "cptgst", P_BOOL|P_VIM, - (char_u *)&p_cptgst, PV_NONE, NULL, NULL, - {(char_u *)TRUE, (char_u *)TRUE} SCTX_INIT}, {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST, (char_u *)&p_cpo, PV_NONE, did_set_cpoptions, expand_set_cpoptions, {(char_u *)CPO_VI, (char_u *)CPO_VIM} @@ -2589,6 +2586,9 @@ static struct vimoption options[] = {"tagstack", "tgst", P_BOOL|P_VI_DEF, (char_u *)&p_tgst, PV_NONE, NULL, NULL, {(char_u *)TRUE, (char_u *)0L} SCTX_INIT}, + {"tagstackcopy", "tgstcp", P_BOOL|P_VIM, + (char_u *)&p_tgstcp, PV_NONE, NULL, NULL, + {(char_u *)TRUE, (char_u *)TRUE} SCTX_INIT}, {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE, #if defined(DYNAMIC_TCL) (char_u *)&p_tcldll, PV_NONE, NULL, NULL, diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak index f808d1594c..ef86a7d6be 100644 --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -114,7 +114,6 @@ NEW_TESTS = \ test_compiler \ test_conceal \ test_const \ - test_copytagstack \ test_cpoptions \ test_crash \ test_crypt \ @@ -399,7 +398,6 @@ NEW_TESTS_RES = \ test_comparators.res \ test_conceal.res \ test_const.res \ - test_copytagstack.res \ test_cpoptions.res \ test_crash.res \ test_crypt.res \ diff --git a/src/testdir/test_copytagstack.vim b/src/testdir/test_copytagstack.vim deleted file mode 100644 index 191c3eadf1..0000000000 --- a/src/testdir/test_copytagstack.vim +++ /dev/null @@ -1,46 +0,0 @@ -" test 'copytagstack' option - -source check.vim -source view_util.vim - -func Test_copytagstack() - call writefile(["int Foo;"], 'file.c', 'D') - call writefile(["Foo\tfile.c\t1"], 'Xtags', 'D') - set tags=Xtags - - tag Foo - - let nr0 = winnr() - call assert_equal(1, gettagstack(nr0)['length']) - - split Xtext - - let nr1 = winnr() - call assert_equal(1, gettagstack(nr1)['length']) - - set tags& - bwipe -endfunc - -func Test_nocopytagstack() - call writefile(["int Foo;"], 'file.c', 'D') - call writefile(["Foo\tfile.c\t1"], 'Xtags', 'D') - set tags=Xtags - set nocopytagstack - - tag Foo - - let nr0 = winnr() - call assert_equal(1, gettagstack(nr0)['length']) - - split Xtext - - let nr1 = winnr() - call assert_equal(0, gettagstack(nr1)['length']) - - set tags& - set copytagstack& - bwipe -endfunc - -" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_tagjump.vim b/src/testdir/test_tagjump.vim index f53d9b88f7..1eaa900530 100644 --- a/src/testdir/test_tagjump.vim +++ b/src/testdir/test_tagjump.vim @@ -1671,4 +1671,44 @@ func Test_tag_excmd_with_number_vim9script() bwipe! endfunc +func Test_tagstackcopy() + call writefile(["int Foo;"], 'file.c', 'D') + call writefile(["Foo\tfile.c\t1"], 'Xtags', 'D') + set tags=Xtags + + tag Foo + + let nr0 = winnr() + call assert_equal(1, gettagstack(nr0)['length']) + + split Xtext + + let nr1 = winnr() + call assert_equal(1, gettagstack(nr1)['length']) + + set tags& + bwipe +endfunc + +func Test_notagstackcopy() + call writefile(["int Foo;"], 'file.c', 'D') + call writefile(["Foo\tfile.c\t1"], 'Xtags', 'D') + set tags=Xtags + set notagstackcopy + + tag Foo + + let nr0 = winnr() + call assert_equal(1, gettagstack(nr0)['length']) + + split Xtext + + let nr1 = winnr() + call assert_equal(0, gettagstack(nr1)['length']) + + set tags& + set tagstackcopy& + bwipe +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/window.c b/src/window.c index d01af8187e..2c96e5f933 100644 --- a/src/window.c +++ b/src/window.c @@ -1559,7 +1559,7 @@ win_init(win_T *newp, win_T *oldp, int flags UNUSED) } // copy tagstack and folds - if (p_cptgst) + if (p_tgstcp) { for (i = 0; i < oldp->w_tagstacklen; i++) {