Problem: :argedit does not reuse an empty unnamed buffer.
Solution: Add the BLN_CURBUF flag and fix all the side effects. (Christian
Brabandt, closes #2713)
static int top_file_num = 1; /* highest file number */
+/*
+ * Return TRUE if the current buffer is empty, unnamed, unmodified and used in
+ * only one window. That means it can be re-used.
+ */
+ int
+curbuf_reusable(void)
+{
+ return (curbuf != NULL
+ && curbuf->b_ffname == NULL
+ && curbuf->b_nwindows <= 1
+ && (curbuf->b_ml.ml_mfp == NULL || BUFEMPTY())
+ && !curbufIsChanged());
+}
+
/*
* Add a file name to the buffer list. Return a pointer to the buffer.
* If the same file name already exists return a pointer to that buffer.
* buffer.)
*/
buf = NULL;
- if ((flags & BLN_CURBUF)
- && curbuf != NULL
- && curbuf->b_ffname == NULL
- && curbuf->b_nwindows <= 1
- && (curbuf->b_ml.ml_mfp == NULL || BUFEMPTY()))
+ if ((flags & BLN_CURBUF) && curbuf_reusable())
{
buf = curbuf;
/* It's like this buffer is deleted. Watch out for autocommands that
ex_argedit(exarg_T *eap)
{
int i = eap->addr_count ? (int)eap->line2 : curwin->w_arg_idx + 1;
+ // Whether curbuf will be reused, curbuf->b_ffname will be set.
+ int curbuf_is_reusable = curbuf_reusable();
if (do_arglist(eap->arg, AL_ADD, i) == FAIL)
return;
maketitle();
#endif
- if (curwin->w_arg_idx == 0 && (curbuf->b_ml.ml_flags & ML_EMPTY)
- && curbuf->b_ffname == NULL)
+ if (curwin->w_arg_idx == 0
+ && (curbuf->b_ml.ml_flags & ML_EMPTY)
+ && (curbuf->b_ffname == NULL || curbuf_is_reusable))
i = 0;
/* Edit the argument. */
if (i < ARGCOUNT)
for (i = 0; i < count; ++i)
{
ARGLIST[after + i].ae_fname = files[i];
- ARGLIST[after + i].ae_fnum = buflist_add(files[i], BLN_LISTED);
+ ARGLIST[after + i].ae_fnum =
+ buflist_add(files[i], BLN_LISTED | BLN_CURBUF);
}
ALIST(curwin)->al_ga.ga_len += count;
if (old_argcount > 0 && curwin->w_arg_idx >= after)
void do_autochdir(void);
void no_write_message(void);
void no_write_message_nobang(buf_T *buf);
+int curbuf_reusable(void);
buf_T *buflist_new(char_u *ffname, char_u *sfname, linenr_T lnum, int flags);
void free_buf_options(buf_T *buf, int free_p_ff);
int buflist_getfile(int n, linenr_T lnum, int options, int forceit);
%argd
bwipe! C
bwipe! D
+
+ " :argedit reuses the current buffer if it is empty
+ %argd
+ " make sure to use a new buffer number for x when it is loaded
+ bw! x
+ new
+ let a = bufnr('')
+ argedit x
+ call assert_equal(a, bufnr(''))
+ call assert_equal('x', bufname(''))
+ %argd
+ bw! x
endfunc
" Test for the :argdelete command
only!
exe bufnr . 'buf'
- bnext
let bufnr = bufnr('%')
let buffers = []
.,$-bufdo call add(buffers, bufnr('%'))
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1763,
/**/
1762,
/**/