aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/window.c54
1 files changed, 31 insertions, 23 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 75ecf90b14..b68f128875 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -64,6 +64,14 @@
# define ROWS_AVAIL (Rows - p_ch - tabline_height())
+/// flags for win_enter_ext()
+typedef enum {
+ WEE_UNDO_SYNC = 0x01,
+ WEE_CURWIN_INVALID = 0x02,
+ WEE_TRIGGER_NEW_AUTOCMDS = 0x04,
+ WEE_TRIGGER_ENTER_AUTOCMDS = 0x08,
+ WEE_TRIGGER_LEAVE_AUTOCMDS = 0x10,
+} wee_flags_T;
static char *m_onlyone = N_("Already only one window");
@@ -1397,10 +1405,9 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
// Keep same changelist position in new window.
wp->w_changelistidx = oldwin->w_changelistidx;
- /*
- * make the new window the current window
- */
- win_enter_ext(wp, false, false, true, true, true);
+ // make the new window the current window
+ win_enter_ext(wp, WEE_TRIGGER_NEW_AUTOCMDS | WEE_TRIGGER_ENTER_AUTOCMDS
+ | WEE_TRIGGER_LEAVE_AUTOCMDS);
if (flags & WSP_VERT) {
p_wiw = i;
} else {
@@ -2620,7 +2627,8 @@ int win_close(win_T *win, bool free_buf)
}
if (close_curwin) {
- win_enter_ext(wp, false, true, false, true, true);
+ win_enter_ext(wp, WEE_CURWIN_INVALID | WEE_TRIGGER_ENTER_AUTOCMDS
+ | WEE_TRIGGER_LEAVE_AUTOCMDS);
if (other_buffer) {
// careful: after this wp and win may be invalid!
apply_autocmds(EVENT_BUFENTER, NULL, NULL, false, curbuf);
@@ -4005,11 +4013,12 @@ static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, bool trigger_enter_a
tabpage_check_windows(old_curtab);
}
- /* We would like doing the TabEnter event first, but we don't have a
- * valid current window yet, which may break some commands.
- * This triggers autocommands, thus may make "tp" invalid. */
- win_enter_ext(tp->tp_curwin, false, true, false,
- trigger_enter_autocmds, trigger_leave_autocmds);
+ // We would like doing the TabEnter event first, but we don't have a
+ // valid current window yet, which may break some commands.
+ // This triggers autocommands, thus may make "tp" invalid.
+ win_enter_ext(tp->tp_curwin, WEE_CURWIN_INVALID
+ | (trigger_enter_autocmds ? WEE_TRIGGER_ENTER_AUTOCMDS : 0)
+ | (trigger_leave_autocmds ? WEE_TRIGGER_LEAVE_AUTOCMDS : 0));
prevwin = next_prevwin;
last_status(false); // status line may appear or disappear
@@ -4462,26 +4471,25 @@ static void win_goto_hor(bool left, long count)
/// win_valid(wp).
void win_enter(win_T *wp, bool undo_sync)
{
- win_enter_ext(wp, undo_sync, false, false, true, true);
+ win_enter_ext(wp, (undo_sync ? WEE_UNDO_SYNC : 0)
+ | WEE_TRIGGER_ENTER_AUTOCMDS | WEE_TRIGGER_LEAVE_AUTOCMDS);
}
-/// Make window wp the current window.
+/// Make window "wp" the current window.
///
-/// @param curwin_invalid curwin has just been closed and
-/// isn't valid when true.
-static void win_enter_ext(win_T *wp, bool undo_sync, bool curwin_invalid, bool trigger_new_autocmds,
- bool trigger_enter_autocmds, bool trigger_leave_autocmds)
+/// @param flags if contains WEE_CURWIN_INVALID, it means curwin has just been
+/// closed and isn't valid.
+static void win_enter_ext(win_T *const wp, const int flags)
{
bool other_buffer = false;
+ const bool curwin_invalid = (flags & WEE_CURWIN_INVALID);
if (wp == curwin && !curwin_invalid) { // nothing to do
return;
}
- if (!curwin_invalid && trigger_leave_autocmds) {
- /*
- * Be careful: If autocommands delete the window, return now.
- */
+ if (!curwin_invalid && (flags & WEE_TRIGGER_LEAVE_AUTOCMDS)) {
+ // Be careful: If autocommands delete the window, return now.
if (wp->w_buffer != curbuf) {
apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, false, curbuf);
other_buffer = true;
@@ -4500,7 +4508,7 @@ static void win_enter_ext(win_T *wp, bool undo_sync, bool curwin_invalid, bool t
}
// sync undo before leaving the current buffer
- if (undo_sync && curbuf != wp->w_buffer) {
+ if ((flags & WEE_UNDO_SYNC) && curbuf != wp->w_buffer) {
u_sync(false);
}
@@ -4561,10 +4569,10 @@ static void win_enter_ext(win_T *wp, bool undo_sync, bool curwin_invalid, bool t
shorten_fnames(true);
}
- if (trigger_new_autocmds) {
+ if (flags & WEE_TRIGGER_NEW_AUTOCMDS) {
apply_autocmds(EVENT_WINNEW, NULL, NULL, false, curbuf);
}
- if (trigger_enter_autocmds) {
+ if (flags & WEE_TRIGGER_ENTER_AUTOCMDS) {
apply_autocmds(EVENT_WINENTER, NULL, NULL, false, curbuf);
if (other_buffer) {
apply_autocmds(EVENT_BUFENTER, NULL, NULL, false, curbuf);