mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.1.0341: :argadd in empty buffer changes the buffer name
Problem: :argadd in empty buffer changes the buffer name. (Pavol Juhas) Solution: Don't re-use the current buffer when not going to edit the file. (closes #3397) Do re-use the current buffer for :next.
This commit is contained in:
parent
9049b68612
commit
32bbd00949
@ -2445,10 +2445,10 @@ buf_write_all(buf_T *buf, int forceit)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static char_u *do_one_arg(char_u *str);
|
static char_u *do_one_arg(char_u *str);
|
||||||
static int do_arglist(char_u *str, int what, int after);
|
static int do_arglist(char_u *str, int what, int after, int will_edit);
|
||||||
static void alist_check_arg_idx(void);
|
static void alist_check_arg_idx(void);
|
||||||
static int editing_arg_idx(win_T *win);
|
static int editing_arg_idx(win_T *win);
|
||||||
static int alist_add_list(int count, char_u **files, int after);
|
static void alist_add_list(int count, char_u **files, int after, int will_edit);
|
||||||
#define AL_SET 1
|
#define AL_SET 1
|
||||||
#define AL_ADD 2
|
#define AL_ADD 2
|
||||||
#define AL_DEL 3
|
#define AL_DEL 3
|
||||||
@ -2553,7 +2553,7 @@ get_arglist_exp(
|
|||||||
void
|
void
|
||||||
set_arglist(char_u *str)
|
set_arglist(char_u *str)
|
||||||
{
|
{
|
||||||
do_arglist(str, AL_SET, 0);
|
do_arglist(str, AL_SET, 0, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2567,7 +2567,8 @@ set_arglist(char_u *str)
|
|||||||
do_arglist(
|
do_arglist(
|
||||||
char_u *str,
|
char_u *str,
|
||||||
int what,
|
int what,
|
||||||
int after UNUSED) /* 0 means before first one */
|
int after UNUSED, // 0 means before first one
|
||||||
|
int will_edit) // will edit added argument
|
||||||
{
|
{
|
||||||
garray_T new_ga;
|
garray_T new_ga;
|
||||||
int exp_count;
|
int exp_count;
|
||||||
@ -2652,11 +2653,11 @@ do_arglist(
|
|||||||
|
|
||||||
if (what == AL_ADD)
|
if (what == AL_ADD)
|
||||||
{
|
{
|
||||||
(void)alist_add_list(exp_count, exp_files, after);
|
alist_add_list(exp_count, exp_files, after, will_edit);
|
||||||
vim_free(exp_files);
|
vim_free(exp_files);
|
||||||
}
|
}
|
||||||
else /* what == AL_SET */
|
else /* what == AL_SET */
|
||||||
alist_set(ALIST(curwin), exp_count, exp_files, FALSE, NULL, 0);
|
alist_set(ALIST(curwin), exp_count, exp_files, will_edit, NULL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
alist_check_arg_idx();
|
alist_check_arg_idx();
|
||||||
@ -2932,7 +2933,7 @@ ex_next(exarg_T *eap)
|
|||||||
{
|
{
|
||||||
if (*eap->arg != NUL) /* redefine file list */
|
if (*eap->arg != NUL) /* redefine file list */
|
||||||
{
|
{
|
||||||
if (do_arglist(eap->arg, AL_SET, 0) == FAIL)
|
if (do_arglist(eap->arg, AL_SET, 0, TRUE) == FAIL)
|
||||||
return;
|
return;
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
@ -2952,7 +2953,7 @@ ex_argedit(exarg_T *eap)
|
|||||||
// Whether curbuf will be reused, curbuf->b_ffname will be set.
|
// Whether curbuf will be reused, curbuf->b_ffname will be set.
|
||||||
int curbuf_is_reusable = curbuf_reusable();
|
int curbuf_is_reusable = curbuf_reusable();
|
||||||
|
|
||||||
if (do_arglist(eap->arg, AL_ADD, i) == FAIL)
|
if (do_arglist(eap->arg, AL_ADD, i, TRUE) == FAIL)
|
||||||
return;
|
return;
|
||||||
#ifdef FEAT_TITLE
|
#ifdef FEAT_TITLE
|
||||||
maketitle();
|
maketitle();
|
||||||
@ -2974,7 +2975,8 @@ ex_argedit(exarg_T *eap)
|
|||||||
ex_argadd(exarg_T *eap)
|
ex_argadd(exarg_T *eap)
|
||||||
{
|
{
|
||||||
do_arglist(eap->arg, AL_ADD,
|
do_arglist(eap->arg, AL_ADD,
|
||||||
eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1);
|
eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1,
|
||||||
|
FALSE);
|
||||||
#ifdef FEAT_TITLE
|
#ifdef FEAT_TITLE
|
||||||
maketitle();
|
maketitle();
|
||||||
#endif
|
#endif
|
||||||
@ -3024,7 +3026,7 @@ ex_argdelete(exarg_T *eap)
|
|||||||
else if (*eap->arg == NUL)
|
else if (*eap->arg == NUL)
|
||||||
EMSG(_(e_argreq));
|
EMSG(_(e_argreq));
|
||||||
else
|
else
|
||||||
do_arglist(eap->arg, AL_DEL, 0);
|
do_arglist(eap->arg, AL_DEL, 0, FALSE);
|
||||||
#ifdef FEAT_TITLE
|
#ifdef FEAT_TITLE
|
||||||
maketitle();
|
maketitle();
|
||||||
#endif
|
#endif
|
||||||
@ -3269,13 +3271,13 @@ ex_listdo(exarg_T *eap)
|
|||||||
* Add files[count] to the arglist of the current window after arg "after".
|
* Add files[count] to the arglist of the current window after arg "after".
|
||||||
* The file names in files[count] must have been allocated and are taken over.
|
* The file names in files[count] must have been allocated and are taken over.
|
||||||
* Files[] itself is not taken over.
|
* Files[] itself is not taken over.
|
||||||
* Returns index of first added argument. Returns -1 when failed (out of mem).
|
|
||||||
*/
|
*/
|
||||||
static int
|
static void
|
||||||
alist_add_list(
|
alist_add_list(
|
||||||
int count,
|
int count,
|
||||||
char_u **files,
|
char_u **files,
|
||||||
int after) /* where to add: 0 = before first one */
|
int after, // where to add: 0 = before first one
|
||||||
|
int will_edit) // will edit adding argument
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int old_argcount = ARGCOUNT;
|
int old_argcount = ARGCOUNT;
|
||||||
@ -3291,19 +3293,19 @@ alist_add_list(
|
|||||||
(ARGCOUNT - after) * sizeof(aentry_T));
|
(ARGCOUNT - after) * sizeof(aentry_T));
|
||||||
for (i = 0; i < count; ++i)
|
for (i = 0; i < count; ++i)
|
||||||
{
|
{
|
||||||
|
int flags = BLN_LISTED | (will_edit ? BLN_CURBUF : 0);
|
||||||
|
|
||||||
ARGLIST[after + i].ae_fname = files[i];
|
ARGLIST[after + i].ae_fname = files[i];
|
||||||
ARGLIST[after + i].ae_fnum =
|
ARGLIST[after + i].ae_fnum = buflist_add(files[i], flags);
|
||||||
buflist_add(files[i], BLN_LISTED | BLN_CURBUF);
|
|
||||||
}
|
}
|
||||||
ALIST(curwin)->al_ga.ga_len += count;
|
ALIST(curwin)->al_ga.ga_len += count;
|
||||||
if (old_argcount > 0 && curwin->w_arg_idx >= after)
|
if (old_argcount > 0 && curwin->w_arg_idx >= after)
|
||||||
curwin->w_arg_idx += count;
|
curwin->w_arg_idx += count;
|
||||||
return after;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < count; ++i)
|
for (i = 0; i < count; ++i)
|
||||||
vim_free(files[i]);
|
vim_free(files[i]);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
|
#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
|
||||||
|
@ -80,6 +80,24 @@ func Test_argadd()
|
|||||||
call assert_equal(0, len(argv()))
|
call assert_equal(0, len(argv()))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_argadd_empty_curbuf()
|
||||||
|
new
|
||||||
|
let curbuf = bufnr('%')
|
||||||
|
call writefile(['test', 'Xargadd'], 'Xargadd')
|
||||||
|
" must not re-use the current buffer.
|
||||||
|
argadd Xargadd
|
||||||
|
call assert_equal(curbuf, bufnr('%'))
|
||||||
|
call assert_equal('', bufname('%'))
|
||||||
|
call assert_equal(1, line('$'))
|
||||||
|
rew
|
||||||
|
call assert_notequal(curbuf, bufnr('%'))
|
||||||
|
call assert_equal('Xargadd', bufname('%'))
|
||||||
|
call assert_equal(2, line('$'))
|
||||||
|
|
||||||
|
%argd
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Init_abc()
|
func Init_abc()
|
||||||
args a b c
|
args a b c
|
||||||
next
|
next
|
||||||
|
@ -158,7 +158,9 @@ endfunc
|
|||||||
func Test_command_count_4()
|
func Test_command_count_4()
|
||||||
%argd
|
%argd
|
||||||
let bufnr = bufnr('$')
|
let bufnr = bufnr('$')
|
||||||
arga aa bb cc dd ee ff
|
next aa bb cc dd ee ff
|
||||||
|
call assert_equal(bufnr, bufnr('%'))
|
||||||
|
|
||||||
3argu
|
3argu
|
||||||
let args = []
|
let args = []
|
||||||
.,$-argdo call add(args, expand('%'))
|
.,$-argdo call add(args, expand('%'))
|
||||||
|
@ -794,6 +794,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
341,
|
||||||
/**/
|
/**/
|
||||||
340,
|
340,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user