diff options
author | Marco Hinz <mh.codebro@gmail.com> | 2019-04-08 19:50:36 +0200 |
---|---|---|
committer | Marco Hinz <mh.codebro@gmail.com> | 2019-04-08 19:59:57 +0200 |
commit | a8d0062c67953d9e024a09d3d6daf062aefca887 (patch) | |
tree | 1bf1717640e5d7f8daab15343d5325ad73b7bee2 | |
parent | 5a81561e7afa9c26d2190677750e341694e17c91 (diff) | |
download | rneovim-a8d0062c67953d9e024a09d3d6daf062aefca887.tar.gz rneovim-a8d0062c67953d9e024a09d3d6daf062aefca887.tar.bz2 rneovim-a8d0062c67953d9e024a09d3d6daf062aefca887.zip |
vim-patch:8.0.1763: :argedit does not reuse an empty unnamed buffer
Problem: :argedit does not reuse an empty unnamed buffer.
Solution: Add the BLN_CURBUF flag and fix all the side effects. (Christian Brabandt)
https://github.com/vim/vim/commit/46a53dfc29689c6a0d80e3820e8b0a48dba6b6ec
-rw-r--r-- | src/nvim/buffer.c | 17 | ||||
-rw-r--r-- | src/nvim/ex_cmds2.c | 10 | ||||
-rw-r--r-- | src/nvim/testdir/test_arglist.vim | 12 | ||||
-rw-r--r-- | src/nvim/testdir/test_command_count.vim | 1 |
4 files changed, 31 insertions, 9 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 8d075dfeae..9a58529736 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1717,11 +1717,7 @@ buf_T * buflist_new(char_u *ffname, char_u *sfname, linenr_T lnum, int flags) * 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 * change curbuf! If that happens, allocate a new buffer anyway. */ @@ -1864,6 +1860,17 @@ buf_T * buflist_new(char_u *ffname, char_u *sfname, linenr_T lnum, int flags) return buf; } +/// Return true if the current buffer is empty, unnamed, unmodified and used in +/// only one window. That means it can be reused. +bool curbuf_reusable(void) +{ + return (curbuf != NULL + && curbuf->b_ffname == NULL + && curbuf->b_nwindows <= 1 + && (curbuf->b_ml.ml_mfp == NULL || BUFEMPTY()) + && !curbufIsChanged()); +} + /* * Free the memory for the options of a buffer. * If "free_p_ff" is true also free 'fileformat', 'buftype' and diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c index 4684a1b31d..15b735dc9e 100644 --- a/src/nvim/ex_cmds2.c +++ b/src/nvim/ex_cmds2.c @@ -1952,14 +1952,17 @@ void ex_next(exarg_T *eap) void 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. + bool curbuf_is_reusable = curbuf_reusable(); if (do_arglist(eap->arg, AL_ADD, i) == FAIL) { return; } maketitle(); - 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. @@ -2257,7 +2260,8 @@ static int alist_add_list(int count, char_u **files, int after) } for (int 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/nvim/testdir/test_arglist.vim b/src/nvim/testdir/test_arglist.vim index ae975fe137..3a9ffbdbf3 100644 --- a/src/nvim/testdir/test_arglist.vim +++ b/src/nvim/testdir/test_arglist.vim @@ -329,6 +329,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/nvim/testdir/test_command_count.vim b/src/nvim/testdir/test_command_count.vim index 2d793ed88f..7262789ab4 100644 --- a/src/nvim/testdir/test_command_count.vim +++ b/src/nvim/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('%')) |