diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-04-08 21:51:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-08 21:51:05 +0200 |
commit | d48362fc8dcb88e4ded75a2d2726afff850c3cac (patch) | |
tree | 411b1ec230806dc6c154b5c90e733fae1f6ebc6f /src/nvim/buffer.c | |
parent | 5a81561e7afa9c26d2190677750e341694e17c91 (diff) | |
parent | 7381c93e2c0e7aa20d29cbc3c6c45de71e22a258 (diff) | |
download | rneovim-d48362fc8dcb88e4ded75a2d2726afff850c3cac.tar.gz rneovim-d48362fc8dcb88e4ded75a2d2726afff850c3cac.tar.bz2 rneovim-d48362fc8dcb88e4ded75a2d2726afff850c3cac.zip |
Merge pull request #9867 from mhinz/vim-8.1.1134
vim-patch:{8.0.1763,8.1.1134}
Diffstat (limited to 'src/nvim/buffer.c')
-rw-r--r-- | src/nvim/buffer.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 8d075dfeae..703a89d31f 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,18 @@ 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()) + && !bt_quickfix(curbuf) + && !curbufIsChanged()); +} + /* * Free the memory for the options of a buffer. * If "free_p_ff" is true also free 'fileformat', 'buftype' and |