mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 06:28:35 +00:00
vim-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 vim/vim#3397) Do re-use the current buffer for :next.
32bbd00949
This commit is contained in:
@@ -1657,9 +1657,11 @@ int get_arglist_exp(char_u *str, int *fcountp, char_u ***fnamesp, bool wig)
|
|||||||
/// AL_DEL: remove files in 'str' from the argument list.
|
/// AL_DEL: remove files in 'str' from the argument list.
|
||||||
/// @param after
|
/// @param after
|
||||||
/// 0 means before first one
|
/// 0 means before first one
|
||||||
|
/// @param will_edit will edit added argument
|
||||||
///
|
///
|
||||||
/// @return FAIL for failure, OK otherwise.
|
/// @return FAIL for failure, OK otherwise.
|
||||||
static int do_arglist(char_u *str, int what, int after)
|
static int do_arglist(char_u *str, int what, int after, bool will_edit)
|
||||||
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
garray_T new_ga;
|
garray_T new_ga;
|
||||||
int exp_count;
|
int exp_count;
|
||||||
@@ -1733,10 +1735,11 @@ static int do_arglist(char_u *str, int what, int after)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
xfree(exp_files);
|
xfree(exp_files);
|
||||||
} else { // what == AL_SET
|
} else {
|
||||||
alist_set(ALIST(curwin), exp_count, exp_files, false, NULL, 0);
|
assert(what == AL_SET);
|
||||||
|
alist_set(ALIST(curwin), exp_count, exp_files, will_edit, NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1956,7 +1959,7 @@ void ex_next(exarg_T *eap)
|
|||||||
| (eap->forceit ? CCGD_FORCEIT : 0)
|
| (eap->forceit ? CCGD_FORCEIT : 0)
|
||||||
| CCGD_EXCMD)) {
|
| CCGD_EXCMD)) {
|
||||||
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;
|
||||||
@@ -1974,7 +1977,7 @@ void 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.
|
||||||
bool curbuf_is_reusable = curbuf_reusable();
|
bool 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;
|
||||||
}
|
}
|
||||||
maketitle();
|
maketitle();
|
||||||
@@ -1994,7 +1997,8 @@ void ex_argedit(exarg_T *eap)
|
|||||||
void ex_argadd(exarg_T *eap)
|
void 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);
|
||||||
maketitle();
|
maketitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2041,7 +2045,7 @@ void ex_argdelete(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
do_arglist(eap->arg, AL_DEL, 0);
|
do_arglist(eap->arg, AL_DEL, 0, false);
|
||||||
}
|
}
|
||||||
maketitle();
|
maketitle();
|
||||||
}
|
}
|
||||||
@@ -2292,9 +2296,9 @@ void ex_listdo(exarg_T *eap)
|
|||||||
/// Files[] itself is not taken over.
|
/// Files[] itself is not taken over.
|
||||||
///
|
///
|
||||||
/// @param after: where to add: 0 = before first one
|
/// @param after: where to add: 0 = before first one
|
||||||
///
|
/// @param will_edit will edit adding argument
|
||||||
/// @return index of first added argument
|
static void alist_add_list(int count, char_u **files, int after, bool will_edit)
|
||||||
static int alist_add_list(int count, char_u **files, int after)
|
FUNC_ATTR_NONNULL_ALL
|
||||||
{
|
{
|
||||||
int old_argcount = ARGCOUNT;
|
int old_argcount = ARGCOUNT;
|
||||||
ga_grow(&ALIST(curwin)->al_ga, count);
|
ga_grow(&ALIST(curwin)->al_ga, count);
|
||||||
@@ -2310,15 +2314,15 @@ static int alist_add_list(int count, char_u **files, int after)
|
|||||||
(size_t)(ARGCOUNT - after) * sizeof(aentry_T));
|
(size_t)(ARGCOUNT - after) * sizeof(aentry_T));
|
||||||
}
|
}
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
|
const 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 = buflist_add(files[i],
|
ARGLIST[after + i].ae_fnum = buflist_add(files[i], flags);
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3766,7 +3770,7 @@ void ex_drop(exarg_T *eap)
|
|||||||
// and mostly only one file is dropped.
|
// and mostly only one file is dropped.
|
||||||
// This also ignores wildcards, since it is very unlikely the user is
|
// This also ignores wildcards, since it is very unlikely the user is
|
||||||
// editing a file name with a wildcard character.
|
// editing a file name with a wildcard character.
|
||||||
do_arglist(eap->arg, AL_SET, 0);
|
do_arglist(eap->arg, AL_SET, 0, false);
|
||||||
|
|
||||||
// Expanding wildcards may result in an empty argument list. E.g. when
|
// Expanding wildcards may result in an empty argument list. E.g. when
|
||||||
// editing "foo.pyc" and ".pyc" is in 'wildignore'. Assume that we
|
// editing "foo.pyc" and ".pyc" is in 'wildignore'. Assume that we
|
||||||
|
@@ -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('%'))
|
||||||
|
Reference in New Issue
Block a user