vim-patch:8.2.1413: previous tab page not usable from an Ex command

Problem:    Previous tab page not usable from an Ex command.
Solution:   Add the "#" argument for :tabnext et al. (Yegappan Lakshmanan,
            closes vim/vim#6677)
94f4ffa770

Do not rename old_curtab to prev_tp in win_new_tabpage, this can be confused
with the previous tabpage (`:tabprevious`).

Cherry-pick ex_errmsg from v8.2.1280.
8930caaa1a
This commit is contained in:
Sean Dewar 2022-03-14 12:16:12 +00:00
parent c5f190e0c2
commit 365a9b074f
No known key found for this signature in database
GPG Key ID: 08CC2C83AD41B581
2 changed files with 49 additions and 6 deletions

View File

@ -2036,6 +2036,18 @@ doend:
return ea.nextcmd; return ea.nextcmd;
} }
static char ex_error_buf[MSG_BUF_LEN];
/// @return an error message with argument included.
/// Uses a static buffer, only the last error will be kept.
/// "msg" will be translated, caller should use N_().
char *ex_errmsg(const char *const msg, const char_u *const arg)
FUNC_ATTR_NONNULL_ALL
{
vim_snprintf(ex_error_buf, MSG_BUF_LEN, _(msg), arg);
return ex_error_buf;
}
// Parse and skip over command modifiers: // Parse and skip over command modifiers:
// - update eap->cmd // - update eap->cmd
// - store flags in "cmdmod". // - store flags in "cmdmod".
@ -4861,7 +4873,13 @@ static int get_tabpage_arg(exarg_T *eap)
if (STRCMP(p, "$") == 0) { if (STRCMP(p, "$") == 0) {
tab_number = LAST_TAB_NR; tab_number = LAST_TAB_NR;
} else if (STRCMP(p, "#") == 0) { } else if (STRCMP(p, "#") == 0) {
if (valid_tabpage(lastused_tabpage)) {
tab_number = tabpage_index(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 } else if (p == p_save || *p_save == '-' || *p != NUL
|| tab_number > LAST_TAB_NR) { || tab_number > LAST_TAB_NR) {
// No numbers as argument. // No numbers as argument.

View File

@ -692,6 +692,7 @@ func Test_lastused_tabpage()
call assert_beeps('call feedkeys("g\<Tab>", "xt")') call assert_beeps('call feedkeys("g\<Tab>", "xt")')
call assert_beeps('call feedkeys("\<C-Tab>", "xt")') call assert_beeps('call feedkeys("\<C-Tab>", "xt")')
call assert_beeps('call feedkeys("\<C-W>g\<Tab>", "xt")') call assert_beeps('call feedkeys("\<C-W>g\<Tab>", "xt")')
call assert_fails('tabnext #', 'E475:')
" open four tab pages " open four tab pages
tabnew tabnew
@ -716,17 +717,41 @@ func Test_lastused_tabpage()
call assert_equal(4, tabpagenr()) call assert_equal(4, tabpagenr())
call assert_equal(2, 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 " Try to jump to a closed tab page
tabclose 2 tabclose #
call assert_equal(0, tabpagenr('#')) call assert_equal(0, tabpagenr('#'))
call feedkeys("g\<Tab>", "xt") call feedkeys("g\<Tab>", "xt")
call assert_equal(3, tabpagenr()) call assert_equal(2, tabpagenr())
call feedkeys("\<C-Tab>", "xt") call feedkeys("\<C-Tab>", "xt")
call assert_equal(3, tabpagenr()) call assert_equal(2, tabpagenr())
call feedkeys("\<C-W>g\<Tab>", "xt") 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 endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab