diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-04-24 21:58:51 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-04-24 21:58:51 +0200 |
commit | 46a53dfc29689c6a0d80e3820e8b0a48dba6b6ec (patch) | |
tree | 5ad1a9ee29f54608ea20a0a77581bf21f760d770 | |
parent | b255b90503a986931904c23dafb5b6d4e512a17e (diff) |
patch 8.0.1763: :argedit does not reuse an empty unnamed bufferv8.0.1763
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)
-rw-r--r-- | src/buffer.c | 20 | ||||
-rw-r--r-- | src/ex_cmds2.c | 10 | ||||
-rw-r--r-- | src/proto/buffer.pro | 1 | ||||
-rw-r--r-- | src/testdir/test_arglist.vim | 12 | ||||
-rw-r--r-- | src/testdir/test_command_count.vim | 1 | ||||
-rw-r--r-- | src/version.c | 2 |
6 files changed, 37 insertions, 9 deletions
diff --git a/src/buffer.c b/src/buffer.c index c3d3d77b0f..dd618337ef 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1842,6 +1842,20 @@ no_write_message_nobang(buf_T *buf UNUSED) 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. * If it does not exist, or if fname == NULL, a new entry is created. @@ -1921,11 +1935,7 @@ buflist_new( * 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 diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index 3e369a8a4f..69283d693c 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -2941,6 +2941,8 @@ ex_next(exarg_T *eap) 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; @@ -2948,8 +2950,9 @@ ex_argedit(exarg_T *eap) 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) @@ -3281,7 +3284,8 @@ alist_add_list( 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) diff --git a/src/proto/buffer.pro b/src/proto/buffer.pro index 8b98843547..59bb2c2012 100644 --- a/src/proto/buffer.pro +++ b/src/proto/buffer.pro @@ -15,6 +15,7 @@ void enter_buffer(buf_T *buf); 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); diff --git a/src/testdir/test_arglist.vim b/src/testdir/test_arglist.vim index 4b8d762e97..87bda700d1 100644 --- a/src/testdir/test_arglist.vim +++ b/src/testdir/test_arglist.vim @@ -308,6 +308,18 @@ func Test_argedit() %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 diff --git a/src/testdir/test_command_count.vim b/src/testdir/test_command_count.vim index 2d793ed88f..7262789ab4 100644 --- a/src/testdir/test_command_count.vim +++ b/src/testdir/test_command_count.vim @@ -173,7 +173,6 @@ func Test_command_count_4() only! exe bufnr . 'buf' - bnext let bufnr = bufnr('%') let buffers = [] .,$-bufdo call add(buffers, bufnr('%')) diff --git a/src/version.c b/src/version.c index 778419ce5e..f5d4c5a289 100644 --- a/src/version.c +++ b/src/version.c @@ -762,6 +762,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1763, +/**/ 1762, /**/ 1761, |