Skip to content

Commit f06523a

Browse files
brammooldouglasdrumond
authored andcommitted
patch 7.4.709 Problem: ":tabmove" does not work as documented. Solution: Make it work consistently. Update documentation and add tests. (Hirohito Higashi)
1 parent 2c5576e commit f06523a

File tree

6 files changed

+93
-38
lines changed

6 files changed

+93
-38
lines changed

runtime/doc/tabpage.txt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,23 +202,29 @@ REORDERING TAB PAGES:
202202
Move the current tab page to after tab page N. Use zero to
203203
make the current tab page the first one. Without N the tab
204204
page is made the last one. >
205+
:.tabmove " do nothing
205206
:-tabmove " move the tab page to the left
206-
:tabmove " move the tab page to the right
207-
:.tabmove " as above
208-
:+tabmove " as above
207+
:+tabmove " move the tab page to the right
209208
:0tabmove " move the tab page to the beginning of the tab
210209
" list
211-
:$tabmove " move the tab page to the end of the tab list
212-
<
210+
:tabmove 0 " as above
211+
:tabmove " move the tab page to the last
212+
:$tabmove " as above
213+
:tabmove $ " as above
213214
214215
:tabm[ove] +[N]
215216
:tabm[ove] -[N]
216217
Move the current tab page N places to the right (with +) or to
217-
the left (with -).
218+
the left (with -). >
219+
:tabmove - " move the tab page to the left
220+
:tabmove -1 " as above
221+
:tabmove + " move the tab page to the right
222+
:tabmove +1 " as above
223+
218224
219225
Note that although it is possible to move a tab behind the N-th one by using
220-
:Ntabmove, it is impossible to move it by N places by using :+Ntabmove. For
221-
clarification what +N means in this context see |[range]|.
226+
:Ntabmove. And move it by N places by using :+Ntabmove. For clarification what
227+
+N means in this context see |[range]|.
222228

223229

224230
LOOPING OVER TAB PAGES:

src/ex_docmd.c

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8163,7 +8163,7 @@ ex_tabnext(eap)
81638163
ex_tabmove(eap)
81648164
exarg_T *eap;
81658165
{
8166-
int tab_number = 9999;
8166+
int tab_number;
81678167

81688168
if (eap->arg && *eap->arg != NUL)
81698169
{
@@ -8184,19 +8184,38 @@ ex_tabmove(eap)
81848184
else
81858185
p = eap->arg;
81868186

8187-
if (p == skipdigits(p))
8187+
if (relative == 0)
81888188
{
8189-
/* No numbers as argument. */
8190-
eap->errmsg = e_invarg;
8191-
return;
8189+
if (STRCMP(p, "$") == 0)
8190+
tab_number = LAST_TAB_NR;
8191+
else if (p == skipdigits(p))
8192+
{
8193+
/* No numbers as argument. */
8194+
eap->errmsg = e_invarg;
8195+
return;
8196+
}
8197+
else
8198+
tab_number = getdigits(&p);
8199+
}
8200+
else
8201+
{
8202+
if (*p != NUL)
8203+
tab_number = getdigits(&p);
8204+
else
8205+
tab_number = 1;
8206+
tab_number = tab_number * relative + tabpage_index(curtab);
8207+
if (relative == -1)
8208+
--tab_number;
81928209
}
8193-
8194-
tab_number = getdigits(&p);
8195-
if (relative != 0)
8196-
tab_number = tab_number * relative + tabpage_index(curtab) - 1;;
81978210
}
81988211
else if (eap->addr_count != 0)
8212+
{
81998213
tab_number = eap->line2;
8214+
if (**eap->cmdlinep == '-')
8215+
--tab_number;
8216+
}
8217+
else
8218+
tab_number = LAST_TAB_NR;
82008219

82018220
tabpage_move(tab_number);
82028221
}

src/testdir/test62.in

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,30 +96,44 @@ STARTTEST
9696
:"
9797
:for i in range(9) | tabnew | endfor
9898
1gt
99-
Go=tabpagenr()
99+
:$put =tabpagenr()
100100
:tabmove 5
101-
i=tabpagenr()
101+
:$put =tabpagenr()
102+
:.tabmove
103+
:$put =tabpagenr()
104+
:tabmove -
105+
:$put =tabpagenr()
106+
:tabmove +
107+
:$put =tabpagenr()
102108
:tabmove -2
103-
i=tabpagenr()
109+
:$put =tabpagenr()
104110
:tabmove +4
105-
i=tabpagenr()
111+
:$put =tabpagenr()
106112
:tabmove
107-
i=tabpagenr()
113+
:$put =tabpagenr()
108114
:tabmove -20
109-
i=tabpagenr()
115+
:$put =tabpagenr()
110116
:tabmove +20
111-
i=tabpagenr()
117+
:$put =tabpagenr()
118+
:0tabmove
119+
:$put =tabpagenr()
120+
:$tabmove
121+
:$put =tabpagenr()
122+
:tabmove 0
123+
:$put =tabpagenr()
124+
:tabmove $
125+
:$put =tabpagenr()
112126
:3tabmove
113-
i=tabpagenr()
127+
:$put =tabpagenr()
114128
:7tabmove 5
115-
i=tabpagenr()
129+
:$put =tabpagenr()
116130
:let a='No error caught.'
117131
:try
118132
:tabmove foo
119133
:catch E474
120134
:let a='E474 caught.'
121135
:endtry
122-
i=a
136+
:$put =a
123137
:"
124138
:" Test autocommands
125139
:tabonly!

src/testdir/test62.ok

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@ tab drop 1: pass
99
tab drop 2: pass
1010
tab drop 3: pass
1111
1
12-
6
12+
5
13+
5
1314
4
14-
8
15+
5
16+
3
17+
7
18+
10
19+
1
20+
10
21+
1
1522
10
1623
1
1724
10
1825
4
19-
6
26+
5
2027
E474 caught.
2128
=== tab split ===
2229
WinLeave

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,8 @@ static char *(features[]) =
756756

757757
static int included_patches[] =
758758
{ /* Add new patch number below this line */
759+
/**/
760+
709,
759761
/**/
760762
708,
761763
/**/

src/window.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4125,18 +4125,27 @@ goto_tabpage_win(tp, wp)
41254125
}
41264126

41274127
/*
4128-
* Move the current tab page to before tab page "nr".
4128+
* Move the current tab page to after tab page "nr".
41294129
*/
41304130
void
41314131
tabpage_move(nr)
41324132
int nr;
41334133
{
4134-
int n = nr;
4135-
tabpage_T *tp;
4134+
int n = 1;
4135+
tabpage_T *tp, *tp_dst;
41364136

41374137
if (first_tabpage->tp_next == NULL)
41384138
return;
41394139

4140+
for (tp = first_tabpage; tp->tp_next != NULL && n < nr; tp = tp->tp_next)
4141+
++n;
4142+
4143+
if (tp == curtab || (nr > 0 && tp->tp_next != NULL
4144+
&& tp->tp_next == curtab))
4145+
return;
4146+
4147+
tp_dst = tp;
4148+
41404149
/* Remove the current tab page from the list of tab pages. */
41414150
if (curtab == first_tabpage)
41424151
first_tabpage = curtab->tp_next;
@@ -4151,17 +4160,15 @@ tabpage_move(nr)
41514160
}
41524161

41534162
/* Re-insert it at the specified position. */
4154-
if (n <= 0)
4163+
if (nr <= 0)
41554164
{
41564165
curtab->tp_next = first_tabpage;
41574166
first_tabpage = curtab;
41584167
}
41594168
else
41604169
{
4161-
for (tp = first_tabpage; tp->tp_next != NULL && n > 1; tp = tp->tp_next)
4162-
--n;
4163-
curtab->tp_next = tp->tp_next;
4164-
tp->tp_next = curtab;
4170+
curtab->tp_next = tp_dst->tp_next;
4171+
tp_dst->tp_next = curtab;
41654172
}
41664173

41674174
/* Need to redraw the tabline. Tab page contents doesn't change. */

0 commit comments

Comments
 (0)