summaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-04-24 21:58:51 +0200
committerBram Moolenaar <Bram@vim.org>2018-04-24 21:58:51 +0200
commit46a53dfc29689c6a0d80e3820e8b0a48dba6b6ec (patch)
tree5ad1a9ee29f54608ea20a0a77581bf21f760d770 /src/buffer.c
parentb255b90503a986931904c23dafb5b6d4e512a17e (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)
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c20
1 files changed, 15 insertions, 5 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