diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 1f2f400f6d..068736e619 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -2356,6 +2356,11 @@ 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 "#{|&/\." diff --git a/src/option.h b/src/option.h index 740f6eed56..6599652c21 100644 --- a/src/option.h +++ b/src/option.h @@ -422,6 +422,7 @@ 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 diff --git a/src/optiondefs.h b/src/optiondefs.h index 5d9f388aa2..f1d32d88c6 100644 --- a/src/optiondefs.h +++ b/src/optiondefs.h @@ -727,6 +727,9 @@ 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} diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak index ef86a7d6be..f808d1594c 100644 --- a/src/testdir/Make_all.mak +++ b/src/testdir/Make_all.mak @@ -114,6 +114,7 @@ NEW_TESTS = \ test_compiler \ test_conceal \ test_const \ + test_copytagstack \ test_cpoptions \ test_crash \ test_crypt \ @@ -398,6 +399,7 @@ 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 new file mode 100644 index 0000000000..191c3eadf1 --- /dev/null +++ b/src/testdir/test_copytagstack.vim @@ -0,0 +1,46 @@ +" 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/window.c b/src/window.c index 3d2528fa6d..d01af8187e 100644 --- a/src/window.c +++ b/src/window.c @@ -1559,17 +1559,20 @@ win_init(win_T *newp, win_T *oldp, int flags UNUSED) } // copy tagstack and folds - for (i = 0; i < oldp->w_tagstacklen; i++) + if (p_cptgst) { - taggy_T *tag = &newp->w_tagstack[i]; - *tag = oldp->w_tagstack[i]; - if (tag->tagname != NULL) - tag->tagname = vim_strsave(tag->tagname); - if (tag->user_data != NULL) - tag->user_data = vim_strsave(tag->user_data); + for (i = 0; i < oldp->w_tagstacklen; i++) + { + taggy_T *tag = &newp->w_tagstack[i]; + *tag = oldp->w_tagstack[i]; + if (tag->tagname != NULL) + tag->tagname = vim_strsave(tag->tagname); + if (tag->user_data != NULL) + tag->user_data = vim_strsave(tag->user_data); + } + newp->w_tagstackidx = oldp->w_tagstackidx; + newp->w_tagstacklen = oldp->w_tagstacklen; } - newp->w_tagstackidx = oldp->w_tagstackidx; - newp->w_tagstacklen = oldp->w_tagstacklen; // Keep same changelist position in new window. newp->w_changelistidx = oldp->w_changelistidx;