]> granicus.if.org Git - vim/commitdiff
patch 8.2.1413: previous tab page not usable from an Ex command v8.2.1413
authorBram Moolenaar <Bram@vim.org>
Mon, 10 Aug 2020 17:21:15 +0000 (19:21 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 10 Aug 2020 17:21:15 +0000 (19:21 +0200)
Problem:    Previous tab page not usable from an Ex command.
Solution:   Add the "#" argument for :tabnext et al. (Yegappan Lakshmanan,
            closes #6677)

runtime/doc/tabpage.txt
src/ex_docmd.c
src/testdir/test_tabpage.vim
src/version.c
src/window.c

index 1d8c2082f26772148f2d5a93448273826b5e1c96..65ae599967a96a3a51cb9f92584d5bf11fefbae5 100644 (file)
@@ -142,6 +142,7 @@ something else.
                    :tabclose +     " close the next tab page
                    :tabclose 3     " close the third tab page
                    :tabclose $     " close the last tab page
+                   :tabclose #     " close the last accessed tab page
 <
                                                        *:tabo* *:tabonly*
 :tabo[nly][!]  Close all other tab pages.
@@ -170,6 +171,8 @@ something else.
                                    " one
                    :tabonly 1      " close all tab pages except the first one
                    :tabonly $      " close all tab pages except the last one
+                   :tabonly #      " close all tab pages except the last
+                                   " accessed one
 
 
 SWITCHING TO ANOTHER TAB PAGE:
@@ -192,6 +195,7 @@ gt                                  *i_CTRL-<PageDown>* *i_<C-PageDown>*
                    :+2tabnext  " go to the two next tab page
                    :1tabnext   " go to the first tab page
                    :$tabnext   " go to the last tab page
+                   :tabnext #  " go to the last accessed tab page
                    :tabnext $  " as above
                    :tabnext -  " go to the previous tab page
                    :tabnext -1 " as above
@@ -255,6 +259,8 @@ REORDERING TAB PAGES:
                    :tabmove    " move the tab page to the last
                    :$tabmove   " as above
                    :tabmove $  " as above
+                   :tabmove #  " move the tab page after the last accessed
+                               " tab page
 
 :tabm[ove] +[N]
 :tabm[ove] -[N]
index 96eac7fbe489b06df97117c4d59caca43ed87468..502f33e2a50ab3d4940189cdd7f081ddcc965769 100644 (file)
@@ -5412,6 +5412,15 @@ get_tabpage_arg(exarg_T *eap)
        {
            if (STRCMP(p, "$") == 0)
                tab_number = LAST_TAB_NR;
+           else if (STRCMP(p, "#") == 0)
+               if (valid_tabpage(lastused_tabpage))
+                   tab_number = tabpage_index(lastused_tabpage);
+               else
+               {
+                   eap->errmsg = ex_errmsg(e_invargval, eap->arg);
+                   tab_number = 0;
+                   goto theend;
+               }
            else if (p == p_save || *p_save == '-' || *p != NUL
                    || tab_number > LAST_TAB_NR)
            {
index 67469718f2bb5808532ddaf6ee30415f6edbe996..e561064ebc1aeb11b774d582e06d1f0fec90f847 100644 (file)
@@ -784,6 +784,7 @@ func Test_lastused_tabpage()
   call assert_beeps('call feedkeys("g\<Tab>", "xt")')
   call assert_beeps('call feedkeys("\<C-Tab>", "xt")')
   call assert_beeps('call feedkeys("\<C-W>g\<Tab>", "xt")')
+  call assert_fails('tabnext #', 'E475:')
 
   " open four tab pages
   tabnew
@@ -808,17 +809,41 @@ func Test_lastused_tabpage()
   call assert_equal(4, tabpagenr())
   call assert_equal(2, tabpagenr('#'))
 
+  " Test for :tabnext #
+  tabnext #
+  call assert_equal(2, tabpagenr())
+  call assert_equal(4, tabpagenr('#'))
+
   " Try to jump to a closed tab page
-  tabclose 2
+  tabclose #
   call assert_equal(0, tabpagenr('#'))
   call feedkeys("g\<Tab>", "xt")
-  call assert_equal(3, tabpagenr())
+  call assert_equal(2, tabpagenr())
   call feedkeys("\<C-Tab>", "xt")
-  call assert_equal(3, tabpagenr())
+  call assert_equal(2, tabpagenr())
   call feedkeys("\<C-W>g\<Tab>", "xt")
-  call assert_equal(3, tabpagenr())
+  call assert_equal(2, tabpagenr())
+  call assert_fails('tabnext #', 'E475:')
+  call assert_equal(2, tabpagenr())
 
-  tabclose!
+  " Test for :tabonly #
+  let wnum = win_getid()
+  $tabnew
+  tabonly #
+  call assert_equal(wnum, win_getid())
+  call assert_equal(1, tabpagenr('$'))
+
+  " Test for :tabmove #
+  tabnew
+  let wnum = win_getid()
+  tabnew
+  tabnew
+  tabnext 2
+  tabmove #
+  call assert_equal(4, tabpagenr())
+  call assert_equal(wnum, win_getid())
+
+  tabonly!
 endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index 4d86275a8dcab641ab0de7a726decceede51e558..a08b5d7b02342e2f07cce1401f3ecde45b0d6eba 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1413,
 /**/
     1412,
 /**/
index d2e5c5c2af4e6f7fcdac86be764fe990b3d1a3a0..75e049562be527e75430014d0e73e1ef67422168 100644 (file)
@@ -3844,6 +3844,7 @@ free_tabpage(tabpage_T *tp)
 win_new_tabpage(int after)
 {
     tabpage_T  *tp = curtab;
+    tabpage_T  *prev_tp = curtab;
     tabpage_T  *newtp;
     int                n;
 
@@ -3893,7 +3894,7 @@ win_new_tabpage(int after)
        newtp->tp_topframe = topframe;
        last_status(FALSE);
 
-       lastused_tabpage = tp;
+       lastused_tabpage = prev_tp;
 
 #if defined(FEAT_GUI)
        // When 'guioptions' includes 'L' or 'R' may have to remove or add