summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-10-20 21:58:42 +0100
committerBram Moolenaar <Bram@vim.org>2021-10-20 21:58:42 +0100
commit1d30fde3c989a962e0e1af4cbcf90e1ea483f1f4 (patch)
tree138c81443921e31b93299222af015755ed61404e
parent09f7723d5a8694889350b13e3f6b4a9c3ed4c41f (diff)
downloadvim-git-8.2.3547.tar.gz
patch 8.2.3547: opening the quickfix window triggers BufWinEnter twicev8.2.3547
Problem: Opening the quickfix window triggers BufWinEnter twice. (Yorick Peterse) Solution: Only trigger BufWinEnter with "quickfix". (closes #9022)
-rw-r--r--src/buffer.c7
-rw-r--r--src/ex_cmds.c12
-rw-r--r--src/quickfix.c5
-rw-r--r--src/testdir/test_quickfix.vim17
-rw-r--r--src/version.c2
-rw-r--r--src/vim.h2
6 files changed, 36 insertions, 9 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 808249908..31f902d77 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -360,11 +360,12 @@ open_buffer(
do_modelines(0);
curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED);
+ if ((flags & READ_NOWINENTER) == 0)
#ifdef FEAT_EVAL
- apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf,
- &retval);
+ apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE,
+ curbuf, &retval);
#else
- apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf);
+ apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf);
#endif
// restore curwin/curbuf and a few other things
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index ff915173f..079dcf10e 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -2473,6 +2473,7 @@ theend:
* ECMD_FORCEIT: ! used for Ex command
* ECMD_ADDBUF: don't edit, just add to buffer list
* ECMD_ALTBUF: like ECMD_ADDBUF and also set the alternate file
+ * ECMD_NOWINENTER: Do not trigger BufWinEnter
* oldwin: Should be "curwin" when editing a new buffer in the current
* window, NULL when splitting the window first. When not NULL info
* of the previous buffer for "oldwin" is stored.
@@ -3030,6 +3031,8 @@ do_ecmd(
/*
* Open the buffer and read the file.
*/
+ if (flags & ECMD_NOWINENTER)
+ readfile_flags |= READ_NOWINENTER;
#if defined(FEAT_EVAL)
if (should_abort(open_buffer(FALSE, eap, readfile_flags)))
retval = FAIL;
@@ -3051,10 +3054,11 @@ do_ecmd(
// changed by the user.
do_modelines(OPT_WINONLY);
- apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf,
- &retval);
- apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf,
- &retval);
+ apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE,
+ curbuf, &retval);
+ if ((flags & ECMD_NOWINENTER) == 0)
+ apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE,
+ curbuf, &retval);
}
check_arg_idx(curwin);
diff --git a/src/quickfix.c b/src/quickfix.c
index 7cc83e3ed..3fb921ff2 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -4199,13 +4199,14 @@ qf_open_new_cwindow(qf_info_T *qi, int height)
{
// Use the existing quickfix buffer
if (do_ecmd(qf_buf->b_fnum, NULL, NULL, NULL, ECMD_ONE,
- ECMD_HIDE + ECMD_OLDBUF, oldwin) == FAIL)
+ ECMD_HIDE + ECMD_OLDBUF + ECMD_NOWINENTER, oldwin) == FAIL)
return FAIL;
}
else
{
// Create a new quickfix buffer
- if (do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, oldwin) == FAIL)
+ if (do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE + ECMD_NOWINENTER,
+ oldwin) == FAIL)
return FAIL;
// save the number of the new buffer
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index e22f6b28d..3b7a4ecb9 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -786,6 +786,23 @@ func Test_vimgreptitle()
augroup! QfBufWinEnter
endfunc
+func Test_bufwinenter_once()
+ augroup QfBufWinEnter
+ au!
+ au BufWinEnter * let g:got_afile ..= 'got ' .. expand('<afile>')
+ augroup END
+ let g:got_afile = ''
+ copen
+ call assert_equal('got quickfix', g:got_afile)
+
+ cclose
+ unlet g:got_afile
+ augroup QfBufWinEnter
+ au!
+ augroup END
+ augroup! QfBufWinEnter
+endfunc
+
func XqfTitleTests(cchar)
call s:setup_commands(a:cchar)
diff --git a/src/version.c b/src/version.c
index d1f550e01..3f80877da 100644
--- a/src/version.c
+++ b/src/version.c
@@ -758,6 +758,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3547,
+/**/
3546,
/**/
3545,
diff --git a/src/vim.h b/src/vim.h
index d2e0d9be3..0ce0e964e 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -977,6 +977,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
#define READ_DUMMY 0x10 // reading into a dummy buffer
#define READ_KEEP_UNDO 0x20 // keep undo info
#define READ_FIFO 0x40 // read from fifo or socket
+#define READ_NOWINENTER 0x80 // do not trigger BufWinEnter
// Values for change_indent()
#define INDENT_SET 1 // set indent
@@ -1043,6 +1044,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
#define ECMD_FORCEIT 0x08 // ! used in Ex command
#define ECMD_ADDBUF 0x10 // don't edit, just add to buffer list
#define ECMD_ALTBUF 0x20 // like ECMD_ADDBUF and set the alternate file
+#define ECMD_NOWINENTER 0x40 // do not trigger BufWinEnter
// for lnum argument in do_ecmd()
#define ECMD_LASTL (linenr_T)0 // use last position in loaded file