aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/window.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/window.c')
-rw-r--r--src/nvim/window.c2155
1 files changed, 1156 insertions, 999 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c
index d051e8e467..c0f537aab3 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -5,11 +5,8 @@
#include <inttypes.h>
#include <stdbool.h>
-#include "nvim/api/private/handle.h"
#include "nvim/api/private/helpers.h"
-#include "nvim/vim.h"
#include "nvim/ascii.h"
-#include "nvim/window.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
@@ -21,8 +18,10 @@
#include "nvim/ex_docmd.h"
#include "nvim/ex_eval.h"
#include "nvim/ex_getln.h"
+#include "nvim/file_search.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
+#include "nvim/garray.h"
#include "nvim/getchar.h"
#include "nvim/hashtab.h"
#include "nvim/main.h"
@@ -31,14 +30,14 @@
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
-#include "nvim/file_search.h"
-#include "nvim/garray.h"
-#include "nvim/move.h"
#include "nvim/mouse.h"
+#include "nvim/move.h"
#include "nvim/normal.h"
#include "nvim/option.h"
+#include "nvim/os/os.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
+#include "nvim/plines.h"
#include "nvim/quickfix.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
@@ -47,10 +46,11 @@
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/terminal.h"
-#include "nvim/undo.h"
#include "nvim/ui.h"
#include "nvim/ui_compositor.h"
-#include "nvim/os/os.h"
+#include "nvim/undo.h"
+#include "nvim/vim.h"
+#include "nvim/window.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -60,26 +60,29 @@
-#define NOWIN (win_T *)-1 /* non-existing window */
+#define NOWIN (win_T *)-1 // non-existing window
-# define ROWS_AVAIL (Rows - p_ch - tabline_height())
+#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");
-/*
- * all CTRL-W window commands are handled here, called from normal_cmd().
- */
-void
-do_window(
- int nchar,
- long Prenum,
- int xchar /* extra char from ":wincmd gx" or NUL */
-)
+/// all CTRL-W window commands are handled here, called from normal_cmd().
+///
+/// @param xchar extra char from ":wincmd gx" or NUL
+void do_window(int nchar, long Prenum, int xchar)
{
long Prenum1;
- win_T *wp;
- char_u *ptr;
+ win_T *wp;
+ char_u *ptr;
linenr_T lnum = -1;
int type = FIND_DEFINE;
size_t len;
@@ -87,7 +90,7 @@ do_window(
Prenum1 = Prenum == 0 ? 1 : Prenum;
-# define CHECK_CMDWIN \
+#define CHECK_CMDWIN \
do { \
if (cmdwin_type != 0) { \
EMSG(_(e_cmdwin)); \
@@ -96,7 +99,7 @@ do_window(
} while (0)
switch (nchar) {
- /* split current window in two parts, horizontally */
+ // split current window in two parts, horizontally
case 'S':
case Ctrl_S:
case 's':
@@ -110,7 +113,7 @@ do_window(
(void)win_split((int)Prenum, 0);
break;
- /* split current window in two parts, vertically */
+ // split current window in two parts, vertically
case Ctrl_V:
case 'v':
CHECK_CMDWIN;
@@ -123,7 +126,7 @@ do_window(
(void)win_split((int)Prenum, WSP_VERT);
break;
- /* split current window and edit alternate file */
+ // split current window and edit alternate file
case Ctrl_HAT:
case '^':
CHECK_CMDWIN;
@@ -144,17 +147,18 @@ do_window(
}
break;
- /* open new window */
+ // open new window
case Ctrl_N:
case 'n':
CHECK_CMDWIN;
reset_VIsual_and_resel(); // stop Visual mode
newwindow:
- if (Prenum)
- /* window height */
+ if (Prenum) {
+ // window height
vim_snprintf(cbuf, sizeof(cbuf) - 5, "%" PRId64, (int64_t)Prenum);
- else
+ } else {
cbuf[0] = NUL;
+ }
if (nchar == 'v' || nchar == Ctrl_V) {
xstrlcat(cbuf, "v", sizeof(cbuf));
}
@@ -162,23 +166,23 @@ newwindow:
do_cmdline_cmd(cbuf);
break;
- /* quit current window */
+ // quit current window
case Ctrl_Q:
case 'q':
- reset_VIsual_and_resel(); /* stop Visual mode */
+ reset_VIsual_and_resel(); // stop Visual mode
cmd_with_count("quit", (char_u *)cbuf, sizeof(cbuf), Prenum);
do_cmdline_cmd(cbuf);
break;
- /* close current window */
+ // close current window
case Ctrl_C:
case 'c':
- reset_VIsual_and_resel(); /* stop Visual mode */
+ reset_VIsual_and_resel(); // stop Visual mode
cmd_with_count("close", (char_u *)cbuf, sizeof(cbuf), Prenum);
do_cmdline_cmd(cbuf);
break;
- /* close preview window */
+ // close preview window
case Ctrl_Z:
case 'z':
CHECK_CMDWIN;
@@ -186,7 +190,7 @@ newwindow:
do_cmdline_cmd("pclose");
break;
- /* cursor to preview window */
+ // cursor to preview window
case 'P':
wp = NULL;
FOR_ALL_WINDOWS_IN_TAB(wp2, curtab) {
@@ -202,7 +206,7 @@ newwindow:
}
break;
- /* close all but current window */
+ // close all but current window
case Ctrl_O:
case 'o':
CHECK_CMDWIN;
@@ -211,10 +215,10 @@ newwindow:
do_cmdline_cmd(cbuf);
break;
- /* cursor to next window with wrap around */
+ // cursor to next window with wrap around
case Ctrl_W:
case 'w':
- /* cursor to previous window with wrap around */
+ // cursor to previous window with wrap around
case 'W':
CHECK_CMDWIN;
if (ONE_WINDOW && Prenum != 1) { // just one window
@@ -222,10 +226,11 @@ newwindow:
} else {
if (Prenum) { // go to specified window
for (wp = firstwin; --Prenum > 0; ) {
- if (wp->w_next == NULL)
+ if (wp->w_next == NULL) {
break;
- else
+ } else {
wp = wp->w_next;
+ }
}
} else {
if (nchar == 'W') { // go to previous window
@@ -252,7 +257,7 @@ newwindow:
}
break;
- /* cursor to window below */
+ // cursor to window below
case 'j':
case K_DOWN:
case Ctrl_J:
@@ -260,7 +265,7 @@ newwindow:
win_goto_ver(false, Prenum1);
break;
- /* cursor to window above */
+ // cursor to window above
case 'k':
case K_UP:
case Ctrl_K:
@@ -268,7 +273,7 @@ newwindow:
win_goto_ver(true, Prenum1);
break;
- /* cursor to left window */
+ // cursor to left window
case 'h':
case K_LEFT:
case Ctrl_H:
@@ -277,7 +282,7 @@ newwindow:
win_goto_hor(true, Prenum1);
break;
- /* cursor to right window */
+ // cursor to right window
case 'l':
case K_RIGHT:
case Ctrl_L:
@@ -285,13 +290,13 @@ newwindow:
win_goto_hor(false, Prenum1);
break;
- /* move window to new tab page */
+ // move window to new tab page
case 'T':
- if (one_window())
+ if (one_window()) {
MSG(_(m_onlyone));
- else {
- tabpage_T *oldtab = curtab;
- tabpage_T *newtab;
+ } else {
+ tabpage_T *oldtab = curtab;
+ tabpage_T *newtab;
/* First create a new tab with the window, then go back to
* the old tab and close the window there. */
@@ -311,19 +316,19 @@ newwindow:
}
break;
- /* cursor to top-left window */
+ // cursor to top-left window
case 't':
case Ctrl_T:
win_goto(firstwin);
break;
- /* cursor to bottom-right window */
+ // cursor to bottom-right window
case 'b':
case Ctrl_B:
win_goto(lastwin_nofloating());
break;
- /* cursor to last accessed (previous) window */
+ // cursor to last accessed (previous) window
case 'p':
case Ctrl_P:
if (!win_valid(prevwin)) {
@@ -333,14 +338,14 @@ newwindow:
}
break;
- /* exchange current and next window */
+ // exchange current and next window
case 'x':
case Ctrl_X:
CHECK_CMDWIN;
win_exchange(Prenum);
break;
- /* rotate windows downwards */
+ // rotate windows downwards
case Ctrl_R:
case 'r':
CHECK_CMDWIN;
@@ -348,14 +353,14 @@ newwindow:
win_rotate(false, (int)Prenum1); // downwards
break;
- /* rotate windows upwards */
+ // rotate windows upwards
case 'R':
CHECK_CMDWIN;
reset_VIsual_and_resel(); // stop Visual mode
win_rotate(true, (int)Prenum1); // upwards
break;
- /* move window to the very top/bottom/left/right */
+ // move window to the very top/bottom/left/right
case 'K':
case 'J':
case 'H':
@@ -366,43 +371,43 @@ newwindow:
| ((nchar == 'H' || nchar == 'K') ? WSP_TOP : WSP_BOT));
break;
- /* make all windows the same height */
+ // make all windows the same height
case '=':
win_equal(NULL, false, 'b');
break;
- /* increase current window height */
+ // increase current window height
case '+':
win_setheight(curwin->w_height + (int)Prenum1);
break;
- /* decrease current window height */
+ // decrease current window height
case '-':
win_setheight(curwin->w_height - (int)Prenum1);
break;
- /* set current window height */
+ // set current window height
case Ctrl__:
case '_':
win_setheight(Prenum ? (int)Prenum : Rows-1);
break;
- /* increase current window width */
+ // increase current window width
case '>':
win_setwidth(curwin->w_width + (int)Prenum1);
break;
- /* decrease current window width */
+ // decrease current window width
case '<':
win_setwidth(curwin->w_width - (int)Prenum1);
break;
- /* set current window width */
+ // set current window width
case '|':
win_setwidth(Prenum != 0 ? (int)Prenum : Columns);
break;
- /* jump to tag and split window if tag exists (in preview window) */
+ // jump to tag and split window if tag exists (in preview window)
case '}':
CHECK_CMDWIN;
if (Prenum) {
@@ -415,10 +420,11 @@ newwindow:
case Ctrl_RSB:
CHECK_CMDWIN;
// Keep visual mode, can select words to use as a tag.
- if (Prenum)
+ if (Prenum) {
postponed_split = Prenum;
- else
+ } else {
postponed_split = -1;
+ }
if (nchar != '}') {
g_do_tagpreview = 0;
@@ -429,7 +435,7 @@ newwindow:
do_nv_ident(Ctrl_RSB, NUL);
break;
- /* edit file name under cursor in a new window */
+ // edit file name under cursor in a new window
case 'f':
case 'F':
case Ctrl_F:
@@ -460,7 +466,7 @@ wingotofile:
/* Go to the first occurrence of the identifier under cursor along path in a
* new window -- webb
*/
- case 'i': /* Go to any match */
+ case 'i': // Go to any match
case Ctrl_I:
type = FIND_ANY;
FALLTHROUGH;
@@ -484,7 +490,7 @@ wingotofile:
break;
- /* CTRL-W g extended commands */
+ // CTRL-W g extended commands
case 'g':
case Ctrl_G:
CHECK_CMDWIN;
@@ -498,18 +504,20 @@ wingotofile:
switch (xchar) {
case '}':
xchar = Ctrl_RSB;
- if (Prenum)
+ if (Prenum) {
g_do_tagpreview = Prenum;
- else
+ } else {
g_do_tagpreview = p_pvh;
+ }
FALLTHROUGH;
case ']':
case Ctrl_RSB:
// Keep visual mode, can select words to use as a tag.
- if (Prenum)
+ if (Prenum) {
postponed_split = Prenum;
- else
+ } else {
postponed_split = -1;
+ }
/* Execute the command right here, required when
* "wincmd g}" was used in a function. */
@@ -520,8 +528,8 @@ wingotofile:
goto_tabpage_lastused();
break;
- case 'f': /* CTRL-W gf: "gf" in a new tab page */
- case 'F': /* CTRL-W gF: "gF" in a new tab page */
+ case 'f': // CTRL-W gf: "gf" in a new tab page
+ case 'F': // CTRL-W gF: "gF" in a new tab page
cmdmod.tab = tabpage_index(curtab) + 1;
nchar = xchar;
goto wingotofile;
@@ -555,13 +563,13 @@ wingotofile:
}
break;
- default: beep_flush();
+ default:
+ beep_flush();
break;
}
}
-static void cmd_with_count(char *cmd, char_u *bufp, size_t bufsize,
- int64_t Prenum)
+static void cmd_with_count(char *cmd, char_u *bufp, size_t bufsize, int64_t Prenum)
{
size_t len = xstrlcpy((char *)bufp, cmd, bufsize);
@@ -676,7 +684,7 @@ void win_set_minimal_style(win_T *wp)
}
// signcolumn: use 'auto'
- if (wp->w_p_scl[0] != 'a') {
+ if (wp->w_p_scl[0] != 'a' || STRLEN(wp->w_p_scl) >= 8) {
xfree(wp->w_p_scl);
wp->w_p_scl = (char_u *)xstrdup("auto");
}
@@ -737,6 +745,37 @@ void win_config_float(win_T *wp, FloatConfig fconfig)
redraw_later(wp, NOT_VALID);
}
+ // compute initial position
+ if (wp->w_float_config.relative == kFloatRelativeWindow) {
+ int row = wp->w_float_config.row;
+ int col = wp->w_float_config.col;
+ Error dummy = ERROR_INIT;
+ win_T *parent = find_window_by_handle(wp->w_float_config.window, &dummy);
+ if (parent) {
+ row += parent->w_winrow;
+ col += parent->w_wincol;
+ ScreenGrid *grid = &parent->w_grid;
+ int row_off = 0, col_off = 0;
+ screen_adjust_grid(&grid, &row_off, &col_off);
+ row += row_off;
+ col += col_off;
+ }
+ api_clear_error(&dummy);
+ if (wp->w_float_config.bufpos.lnum >= 0) {
+ pos_T pos = { wp->w_float_config.bufpos.lnum + 1,
+ wp->w_float_config.bufpos.col, 0 };
+ int trow, tcol, tcolc, tcole;
+ textpos2screenpos(wp, &pos, &trow, &tcol, &tcolc, &tcole, true);
+ row += trow - 1;
+ col += tcol - 1;
+ }
+ wp->w_winrow = row;
+ wp->w_wincol = col;
+ } else {
+ wp->w_winrow = fconfig.row;
+ wp->w_wincol = fconfig.col;
+ }
+
// changing border style while keeping border only requires redrawing border
if (fconfig.border) {
wp->w_redr_border = true;
@@ -770,7 +809,6 @@ int win_fdccol_count(win_T *wp)
}
}
-
void ui_ext_win_position(win_T *wp)
{
if (!wp->w_floating) {
@@ -817,6 +855,8 @@ void ui_ext_win_position(win_T *wp)
int comp_row = (int)row - (south ? wp->w_height : 0);
int comp_col = (int)col - (east ? wp->w_width : 0);
+ comp_row += grid->comp_row;
+ comp_col += grid->comp_col;
comp_row = MAX(MIN(comp_row, Rows-wp->w_height_outer-1), 0);
comp_col = MAX(MIN(comp_col, Columns-wp->w_width_outer), 0);
wp->w_winrow = comp_row;
@@ -834,21 +874,21 @@ void ui_ext_win_position(win_T *wp)
} else {
ui_call_win_external_pos(wp->w_grid_alloc.handle, wp->handle);
}
-
}
void ui_ext_win_viewport(win_T *wp)
{
if ((wp == curwin || ui_has(kUIMultigrid)) && wp->w_viewport_invalid) {
int botline = wp->w_botline;
- if (botline == wp->w_buffer->b_ml.ml_line_count+1
- && wp->w_empty_rows == 0) {
+ int line_count = wp->w_buffer->b_ml.ml_line_count;
+ if (botline == line_count+1 && wp->w_empty_rows == 0) {
// TODO(bfredl): The might be more cases to consider, like how does this
// interact with incomplete final line? Diff filler lines?
botline = wp->w_buffer->b_ml.ml_line_count;
}
ui_call_win_viewport(wp->w_grid_alloc.handle, wp->handle, wp->w_topline-1,
- botline, wp->w_cursor.lnum-1, wp->w_cursor.col);
+ botline, wp->w_cursor.lnum-1, wp->w_cursor.col,
+ line_count);
wp->w_viewport_invalid = false;
}
}
@@ -870,11 +910,12 @@ void ui_ext_win_viewport(win_T *wp)
*/
int win_split(int size, int flags)
{
- /* When the ":tab" modifier was used open a new tab page instead. */
- if (may_open_tabpage() == OK)
+ // When the ":tab" modifier was used open a new tab page instead.
+ if (may_open_tabpage() == OK) {
return OK;
+ }
- /* Add flags from ":vertical", ":topleft" and ":botright". */
+ // Add flags from ":vertical", ":topleft" and ":botright".
flags |= cmdmod.split;
if ((flags & WSP_TOP) && (flags & WSP_BOT)) {
EMSG(_("E442: Can't split topleft and botright at the same time"));
@@ -883,10 +924,11 @@ int win_split(int size, int flags)
/* When creating the help window make a snapshot of the window layout.
* Otherwise clear the snapshot, it's now invalid. */
- if (flags & WSP_HELP)
+ if (flags & WSP_HELP) {
make_snapshot(SNAP_HELP_IDX);
- else
+ } else {
clear_snapshot(curtab, SNAP_HELP_IDX);
+ }
return win_split_ins(size, flags, NULL, 0);
}
@@ -899,17 +941,17 @@ int win_split(int size, int flags)
*/
int win_split_ins(int size, int flags, win_T *new_wp, int dir)
{
- win_T *wp = new_wp;
- win_T *oldwin;
+ win_T *wp = new_wp;
+ win_T *oldwin;
int new_size = size;
int i;
int need_status = 0;
- int do_equal = FALSE;
+ bool do_equal = false;
int needed;
int available;
int oldwin_height = 0;
int layout;
- frame_T *frp, *curfrp, *frp2, *prevfrp;
+ frame_T *frp, *curfrp, *frp2, *prevfrp;
int before;
int minheight;
int wmh1;
@@ -981,8 +1023,9 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
EMSG(_(e_noroom));
return FAIL;
}
- if (new_size == 0)
+ if (new_size == 0) {
new_size = oldwin->w_width / 2;
+ }
if (new_size > available - minwidth - 1) {
new_size = available - minwidth - 1;
}
@@ -990,9 +1033,10 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
new_size = wmw1;
}
- /* if it doesn't fit in the current window, need win_equal() */
- if (oldwin->w_width - new_size - 1 < p_wmw)
- do_equal = TRUE;
+ // if it doesn't fit in the current window, need win_equal()
+ if (oldwin->w_width - new_size - 1 < p_wmw) {
+ do_equal = true;
+ }
// We don't like to take lines for the new window from a
// 'winfixwidth' window. Take them from a window to the left or right
@@ -1009,9 +1053,9 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
while (frp != NULL) {
if (frp->fr_win != oldwin && frp->fr_win != NULL
&& (frp->fr_win->w_width > new_size
- || frp->fr_win->w_width > oldwin->w_width
- - new_size - 1)) {
- do_equal = TRUE;
+ || frp->fr_win->w_width > (oldwin->w_width
+ - new_size - 1))) {
+ do_equal = true;
break;
}
frp = frp->fr_next;
@@ -1064,8 +1108,9 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
oldwin->w_status_height = STATUS_HEIGHT;
oldwin_height -= STATUS_HEIGHT;
}
- if (new_size == 0)
+ if (new_size == 0) {
new_size = oldwin_height / 2;
+ }
if (new_size > available - minheight - STATUS_HEIGHT) {
new_size = available - minheight - STATUS_HEIGHT;
@@ -1074,9 +1119,10 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
new_size = wmh1;
}
- /* if it doesn't fit in the current window, need win_equal() */
- if (oldwin_height - new_size - STATUS_HEIGHT < p_wmh)
- do_equal = TRUE;
+ // if it doesn't fit in the current window, need win_equal()
+ if (oldwin_height - new_size - STATUS_HEIGHT < p_wmh) {
+ do_equal = true;
+ }
/* We don't like to take lines for the new window from a
* 'winfixheight' window. Take them from a window above or below
@@ -1088,10 +1134,11 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
did_set_fraction = true;
win_setheight_win(oldwin->w_height + new_size + STATUS_HEIGHT,
- oldwin);
+ oldwin);
oldwin_height = oldwin->w_height;
- if (need_status)
+ if (need_status) {
oldwin_height -= STATUS_HEIGHT;
+ }
}
/* Only make all windows the same height if one of them (except oldwin)
@@ -1105,7 +1152,7 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
&& (frp->fr_win->w_height > new_size
|| frp->fr_win->w_height > oldwin_height - new_size
- STATUS_HEIGHT)) {
- do_equal = TRUE;
+ do_equal = true;
break;
}
frp = frp->fr_next;
@@ -1120,28 +1167,29 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
&& ((flags & WSP_BOT)
|| (flags & WSP_BELOW)
|| (!(flags & WSP_ABOVE)
- && (
- (flags & WSP_VERT) ? p_spr :
- p_sb)))) {
- /* new window below/right of current one */
- if (new_wp == NULL)
- wp = win_alloc(oldwin, FALSE);
- else
+ && ((flags & WSP_VERT) ? p_spr : p_sb)))) {
+ // new window below/right of current one
+ if (new_wp == NULL) {
+ wp = win_alloc(oldwin, false);
+ } else {
win_append(oldwin, wp);
+ }
} else {
- if (new_wp == NULL)
- wp = win_alloc(oldwin->w_prev, FALSE);
- else
+ if (new_wp == NULL) {
+ wp = win_alloc(oldwin->w_prev, false);
+ } else {
win_append(oldwin->w_prev, wp);
+ }
}
if (new_wp == NULL) {
- if (wp == NULL)
+ if (wp == NULL) {
return FAIL;
+ }
new_frame(wp);
- /* make the contents of the new window the same as the current one */
+ // make the contents of the new window the same as the current one
win_init(wp, curwin, flags);
} else if (wp->w_floating) {
new_frame(wp);
@@ -1157,25 +1205,29 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
if ((topframe->fr_layout == FR_COL && (flags & WSP_VERT) == 0)
|| (topframe->fr_layout == FR_ROW && (flags & WSP_VERT) != 0)) {
curfrp = topframe->fr_child;
- if (flags & WSP_BOT)
- while (curfrp->fr_next != NULL)
+ if (flags & WSP_BOT) {
+ while (curfrp->fr_next != NULL) {
curfrp = curfrp->fr_next;
- } else
+ }
+ }
+ } else {
curfrp = topframe;
+ }
before = (flags & WSP_TOP);
} else {
curfrp = oldwin->w_frame;
- if (flags & WSP_BELOW)
+ if (flags & WSP_BELOW) {
before = FALSE;
- else if (flags & WSP_ABOVE)
+ } else if (flags & WSP_ABOVE) {
before = TRUE;
- else if (flags & WSP_VERT)
+ } else if (flags & WSP_VERT) {
before = !p_spr;
- else
+ } else {
before = !p_sb;
+ }
}
if (curfrp->fr_parent == NULL || curfrp->fr_parent->fr_layout != layout) {
- /* Need to create a new frame in the tree to make a branch. */
+ // Need to create a new frame in the tree to make a branch.
frp = xcalloc(1, sizeof(frame_T));
*frp = *curfrp;
curfrp->fr_layout = layout;
@@ -1194,17 +1246,19 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
}
}
- if (new_wp == NULL)
+ if (new_wp == NULL) {
frp = wp->w_frame;
- else
+ } else {
frp = new_wp->w_frame;
+ }
frp->fr_parent = curfrp->fr_parent;
- /* Insert the new frame at the right place in the frame list. */
- if (before)
+ // Insert the new frame at the right place in the frame list.
+ if (before) {
frame_insert(curfrp, frp);
- else
+ } else {
frame_append(curfrp, frp);
+ }
/* Set w_fraction now so that the cursor keeps the same relative
* vertical position. */
@@ -1221,12 +1275,12 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
oldwin->w_status_height = need_status;
}
if (flags & (WSP_TOP | WSP_BOT)) {
- /* set height and row of new window to full height */
+ // set height and row of new window to full height
wp->w_winrow = tabline_height();
win_new_height(wp, curfrp->fr_height - (p_ls > 0));
wp->w_status_height = (p_ls > 0);
} else {
- /* height and row of new window is same as current window */
+ // height and row of new window is same as current window
wp->w_winrow = oldwin->w_winrow;
win_new_height(wp, oldwin->w_height);
wp->w_status_height = oldwin->w_status_height;
@@ -1236,30 +1290,33 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
/* "new_size" of the current window goes to the new window, use
* one column for the vertical separator */
win_new_width(wp, new_size);
- if (before)
+ if (before) {
wp->w_vsep_width = 1;
- else {
+ } else {
wp->w_vsep_width = oldwin->w_vsep_width;
oldwin->w_vsep_width = 1;
}
if (flags & (WSP_TOP | WSP_BOT)) {
- if (flags & WSP_BOT)
+ if (flags & WSP_BOT) {
frame_add_vsep(curfrp);
- /* Set width of neighbor frame */
+ }
+ // Set width of neighbor frame
frame_new_width(curfrp, curfrp->fr_width
- - (new_size + ((flags & WSP_TOP) != 0)), flags & WSP_TOP,
- FALSE);
- } else
+ - (new_size + ((flags & WSP_TOP) != 0)), flags & WSP_TOP,
+ false);
+ } else {
win_new_width(oldwin, oldwin->w_width - (new_size + 1));
- if (before) { /* new window left of current one */
+ }
+ if (before) { // new window left of current one
wp->w_wincol = oldwin->w_wincol;
oldwin->w_wincol += new_size + 1;
- } else /* new window right of current one */
+ } else { // new window right of current one
wp->w_wincol = oldwin->w_wincol + oldwin->w_width + 1;
+ }
frame_fix_width(oldwin);
frame_fix_width(wp);
} else {
- /* width and column of new window is same as current window */
+ // width and column of new window is same as current window
if (flags & (WSP_TOP | WSP_BOT)) {
wp->w_wincol = 0;
win_new_width(wp, Columns);
@@ -1295,14 +1352,16 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
oldwin->w_status_height = STATUS_HEIGHT;
}
}
- if (flags & WSP_BOT)
+ if (flags & WSP_BOT) {
frame_add_statusline(curfrp);
+ }
frame_fix_height(wp);
frame_fix_height(oldwin);
}
- if (flags & (WSP_TOP | WSP_BOT))
+ if (flags & (WSP_TOP | WSP_BOT)) {
(void)win_comp_pos();
+ }
// Both windows need redrawing. Update all status lines, in case they
// show something related to the window count or position.
@@ -1313,41 +1372,42 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
if (need_status) {
msg_row = Rows - 1;
msg_col = sc_col;
- msg_clr_eos_force(); /* Old command/ruler may still be there */
+ msg_clr_eos_force(); // Old command/ruler may still be there
comp_col();
msg_row = Rows - 1;
- msg_col = 0; /* put position back at start of line */
+ msg_col = 0; // put position back at start of line
}
/*
* equalize the window sizes.
*/
- if (do_equal || dir != 0)
+ if (do_equal || dir != 0) {
win_equal(wp, true,
- (flags & WSP_VERT) ? (dir == 'v' ? 'b' : 'h')
- : dir == 'h' ? 'b' :
- 'v');
+ (flags & WSP_VERT) ? (dir == 'v' ? 'b' : 'h')
+ : dir == 'h' ? 'b' :
+ 'v');
+ }
/* Don't change the window height/width to 'winheight' / 'winwidth' if a
* size was given. */
if (flags & WSP_VERT) {
i = p_wiw;
- if (size != 0)
+ if (size != 0) {
p_wiw = size;
-
+ }
} else {
i = p_wh;
- if (size != 0)
+ if (size != 0) {
p_wh = size;
+ }
}
// 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 {
@@ -1394,7 +1454,7 @@ static void win_init(win_T *newp, win_T *oldp, int flags)
newp->w_prev_fraction_row = oldp->w_prev_fraction_row;
copy_jumplist(oldp, newp);
if (flags & WSP_NEWLOC) {
- /* Don't copy the location list. */
+ // Don't copy the location list.
newp->w_llist = NULL;
newp->w_llist_ref = NULL;
} else {
@@ -1403,7 +1463,7 @@ static void win_init(win_T *newp, win_T *oldp, int flags)
newp->w_localdir = (oldp->w_localdir == NULL)
? NULL : vim_strsave(oldp->w_localdir);
- /* copy tagstack and folds */
+ // copy tagstack and folds
for (i = 0; i < oldp->w_tagstacklen; i++) {
taggy_T *tag = &newp->w_tagstack[i];
*tag = oldp->w_tagstack[i];
@@ -1429,16 +1489,16 @@ static void win_init(win_T *newp, win_T *oldp, int flags)
*/
static void win_init_some(win_T *newp, win_T *oldp)
{
- /* Use the same argument list. */
+ // Use the same argument list.
newp->w_alist = oldp->w_alist;
++newp->w_alist->al_refcount;
newp->w_arg_idx = oldp->w_arg_idx;
- /* copy options from existing window */
+ // copy options from existing window
win_copy_options(oldp, newp);
}
-/// Return TRUE if "win" is floating window in the current tab page.
+/// Return true if "win" is floating window in the current tab page.
///
/// @param win window to check
bool win_valid_floating(const win_T *win)
@@ -1516,17 +1576,14 @@ int win_count(void)
return count;
}
-/*
- * Make "count" windows on the screen.
- * Return actual number of windows on the screen.
- * Must be called when there is just one window, filling the whole screen
- * (excluding the command line).
- */
-int
-make_windows (
- int count,
- int vertical /* split windows vertically if TRUE */
-)
+/// Make "count" windows on the screen.
+/// Must be called when there is just one window, filling the whole screen
+/// (excluding the command line).
+///
+/// @param vertical split windows vertically if true
+///
+/// @return actual number of windows on the screen.
+int make_windows(int count, bool vertical)
{
int maxcount;
int todo;
@@ -1543,16 +1600,19 @@ make_windows (
- (p_wh - p_wmh)) / (p_wmh + STATUS_HEIGHT);
}
- if (maxcount < 2)
+ if (maxcount < 2) {
maxcount = 2;
- if (count > maxcount)
+ }
+ if (count > maxcount) {
count = maxcount;
+ }
/*
* add status line now, otherwise first window will be too big
*/
- if (count > 1)
- last_status(TRUE);
+ if (count > 1) {
+ last_status(true);
+ }
/*
* Don't execute autocommands while creating the windows. Must do that
@@ -1560,22 +1620,25 @@ make_windows (
*/
block_autocmds();
- /* todo is number of windows left to create */
- for (todo = count - 1; todo > 0; --todo)
+ // todo is number of windows left to create
+ for (todo = count - 1; todo > 0; --todo) {
if (vertical) {
if (win_split(curwin->w_width - (curwin->w_width - todo)
- / (todo + 1) - 1, WSP_VERT | WSP_ABOVE) == FAIL)
+ / (todo + 1) - 1, WSP_VERT | WSP_ABOVE) == FAIL) {
break;
+ }
} else {
if (win_split(curwin->w_height - (curwin->w_height - todo
* STATUS_HEIGHT) / (todo + 1)
- - STATUS_HEIGHT, WSP_ABOVE) == FAIL)
+ - STATUS_HEIGHT, WSP_ABOVE) == FAIL) {
break;
+ }
}
+ }
unblock_autocmds();
- /* return actual number of windows */
+ // return actual number of windows
return count - todo;
}
@@ -1584,10 +1647,10 @@ make_windows (
*/
static void win_exchange(long Prenum)
{
- frame_T *frp;
- frame_T *frp2;
- win_T *wp;
- win_T *wp2;
+ frame_T *frp;
+ frame_T *frp2;
+ win_T *wp;
+ win_T *wp2;
int temp;
if (curwin->w_floating) {
@@ -1607,17 +1670,20 @@ static void win_exchange(long Prenum)
*/
if (Prenum) {
frp = curwin->w_frame->fr_parent->fr_child;
- while (frp != NULL && --Prenum > 0)
+ while (frp != NULL && --Prenum > 0) {
frp = frp->fr_next;
- } else if (curwin->w_frame->fr_next != NULL) /* Swap with next */
+ }
+ } else if (curwin->w_frame->fr_next != NULL) { // Swap with next
frp = curwin->w_frame->fr_next;
- else /* Swap last window in row/col with previous */
+ } else { // Swap last window in row/col with previous
frp = curwin->w_frame->fr_prev;
+ }
/* We can only exchange a window with another window, not with a frame
* containing windows. */
- if (frp == NULL || frp->fr_win == NULL || frp->fr_win == curwin)
+ if (frp == NULL || frp->fr_win == NULL || frp->fr_win == curwin) {
return;
+ }
wp = frp->fr_win;
/*
@@ -1640,10 +1706,11 @@ static void win_exchange(long Prenum)
win_remove(wp, NULL);
frame_remove(wp->w_frame);
win_append(wp2, wp);
- if (frp2 == NULL)
+ if (frp2 == NULL) {
frame_insert(wp->w_frame->fr_parent->fr_child, wp->w_frame);
- else
+ } else {
frame_append(frp2, wp->w_frame);
+ }
}
temp = curwin->w_status_height;
curwin->w_status_height = wp->w_status_height;
@@ -1652,23 +1719,12 @@ static void win_exchange(long Prenum)
curwin->w_vsep_width = wp->w_vsep_width;
wp->w_vsep_width = temp;
- /* If the windows are not in the same frame, exchange the sizes to avoid
- * messing up the window layout. Otherwise fix the frame sizes. */
- if (curwin->w_frame->fr_parent != wp->w_frame->fr_parent) {
- temp = curwin->w_height;
- curwin->w_height = wp->w_height;
- wp->w_height = temp;
- temp = curwin->w_width;
- curwin->w_width = wp->w_width;
- wp->w_width = temp;
- } else {
- frame_fix_height(curwin);
- frame_fix_height(wp);
- frame_fix_width(curwin);
- frame_fix_width(wp);
- }
+ frame_fix_height(curwin);
+ frame_fix_height(wp);
+ frame_fix_width(curwin);
+ frame_fix_width(wp);
- (void)win_comp_pos(); /* recompute window positions */
+ (void)win_comp_pos(); // recompute window positions
win_enter(wp, true);
redraw_later(curwin, NOT_VALID);
@@ -1679,9 +1735,9 @@ static void win_exchange(long Prenum)
// if upwards false the first window becomes the second one
static void win_rotate(bool upwards, int count)
{
- win_T *wp1;
- win_T *wp2;
- frame_T *frp;
+ win_T *wp1;
+ win_T *wp2;
+ frame_T *frp;
int n;
if (curwin->w_floating) {
@@ -1704,8 +1760,8 @@ static void win_rotate(bool upwards, int count)
}
while (count--) {
- if (upwards) { /* first window becomes last window */
- /* remove first window/frame from the list */
+ if (upwards) { // first window becomes last window
+ // remove first window/frame from the list
frp = curwin->w_frame->fr_parent->fr_child;
assert(frp != NULL);
wp1 = frp->fr_win;
@@ -1713,30 +1769,32 @@ static void win_rotate(bool upwards, int count)
frame_remove(frp);
assert(frp->fr_parent->fr_child);
- /* find last frame and append removed window/frame after it */
- for (; frp->fr_next != NULL; frp = frp->fr_next)
+ // find last frame and append removed window/frame after it
+ for (; frp->fr_next != NULL; frp = frp->fr_next) {
;
+ }
win_append(frp->fr_win, wp1);
frame_append(frp, wp1->w_frame);
- wp2 = frp->fr_win; /* previously last window */
- } else { /* last window becomes first window */
- /* find last window/frame in the list and remove it */
+ wp2 = frp->fr_win; // previously last window
+ } else { // last window becomes first window
+ // find last window/frame in the list and remove it
for (frp = curwin->w_frame; frp->fr_next != NULL;
- frp = frp->fr_next)
+ frp = frp->fr_next) {
;
+ }
wp1 = frp->fr_win;
- wp2 = wp1->w_prev; /* will become last window */
+ wp2 = wp1->w_prev; // will become last window
win_remove(wp1, NULL);
frame_remove(frp);
assert(frp->fr_parent->fr_child);
- /* append the removed window/frame before the first in the list */
+ // append the removed window/frame before the first in the list
win_append(frp->fr_parent->fr_child->fr_win->w_prev, wp1);
frame_insert(frp->fr_parent->fr_child, frp);
}
- /* exchange status height and vsep width of old and new last window */
+ // exchange status height and vsep width of old and new last window
n = wp2->w_status_height;
wp2->w_status_height = wp1->w_status_height;
wp1->w_status_height = n;
@@ -1748,7 +1806,7 @@ static void win_rotate(bool upwards, int count)
frame_fix_width(wp1);
frame_fix_width(wp2);
- /* recompute w_winrow and w_wincol for all windows */
+ // recompute w_winrow and w_wincol for all windows
(void)win_comp_pos();
}
@@ -1785,17 +1843,17 @@ static void win_totop(int size, int flags)
(void)winframe_remove(curwin, &dir, NULL);
}
win_remove(curwin, NULL);
- last_status(FALSE); /* may need to remove last status line */
- (void)win_comp_pos(); /* recompute window positions */
+ last_status(false); // may need to remove last status line
+ (void)win_comp_pos(); // recompute window positions
- /* Split a window on the desired side and put the window there. */
+ // Split a window on the desired side and put the window there.
(void)win_split_ins(size, flags, curwin, dir);
if (!(flags & WSP_VERT)) {
win_setheight(height);
- if (p_ea)
+ if (p_ea) {
win_equal(curwin, true, 'v');
+ }
}
-
}
/*
@@ -1806,11 +1864,12 @@ void win_move_after(win_T *win1, win_T *win2)
{
int height;
- /* check if the arguments are reasonable */
- if (win1 == win2)
+ // check if the arguments are reasonable
+ if (win1 == win2) {
return;
+ }
- /* check if there is something to do */
+ // check if there is something to do
if (win2->w_next != win1) {
/* may need move the status line/vertical separator of the last window
* */
@@ -1853,58 +1912,54 @@ void win_move_after(win_T *win1, win_T *win2)
win2->w_pos_changed = true;
}
-/*
- * Make all windows the same height.
- * 'next_curwin' will soon be the current window, make sure it has enough
- * rows.
- */
-void win_equal(
- win_T *next_curwin, // pointer to current window to be or NULL
- bool current, // do only frame with current window
- int dir // 'v' for vertically, 'h' for horizontally,
- // 'b' for both, 0 for using p_ead
-)
-{
- if (dir == 0)
+/// Make all windows the same height.
+///'next_curwin' will soon be the current window, make sure it has enough rows.
+///
+/// @param next_curwin pointer to current window to be or NULL
+/// @param current do only frame with current window
+/// @param dir 'v' for vertically, 'h' for horizontally, 'b' for both, 0 for using p_ead
+void win_equal(win_T *next_curwin, bool current, int dir)
+{
+ if (dir == 0) {
dir = *p_ead;
+ }
win_equal_rec(next_curwin == NULL ? curwin : next_curwin, current,
topframe, dir, 0, tabline_height(),
Columns, topframe->fr_height);
}
-/*
- * Set a frame to a new position and height, spreading the available room
- * equally over contained frames.
- * The window "next_curwin" (if not NULL) should at least get the size from
- * 'winheight' and 'winwidth' if possible.
- */
-static void win_equal_rec(
- win_T *next_curwin, /* pointer to current window to be or NULL */
- bool current, /* do only frame with current window */
- frame_T *topfr, /* frame to set size off */
- int dir, /* 'v', 'h' or 'b', see win_equal() */
- int col, /* horizontal position for frame */
- int row, /* vertical position for frame */
- int width, /* new width of frame */
- int height /* new height of frame */
-)
+/// Set a frame to a new position and height, spreading the available room
+/// equally over contained frames.
+/// The window "next_curwin" (if not NULL) should at least get the size from
+/// 'winheight' and 'winwidth' if possible.
+///
+/// @param next_curwin pointer to current window to be or NULL
+/// @param current do only frame with current window
+/// @param topfr frame to set size off
+/// @param dir 'v', 'h' or 'b', see win_equal()
+/// @param col horizontal position for frame
+/// @param row vertical position for frame
+/// @param width new width of frame
+/// @param height new height of frame
+static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int dir, int col,
+ int row, int width, int height)
{
int n, m;
int extra_sep = 0;
int wincount, totwincount = 0;
- frame_T *fr;
+ frame_T *fr;
int next_curwin_size = 0;
int room = 0;
int new_size;
int has_next_curwin = 0;
- int hnc;
+ bool hnc;
if (topfr->fr_layout == FR_LEAF) {
/* Set the width/height of this frame.
* Redraw when size or position changes */
if (topfr->fr_height != height || topfr->fr_win->w_winrow != row
- || topfr->fr_width != width || topfr->fr_win->w_wincol != col
- ) {
+ || topfr->fr_width != width ||
+ topfr->fr_win->w_wincol != col) {
topfr->fr_win->w_winrow = row;
frame_new_height(topfr, height, false, false);
topfr->fr_win->w_wincol = col;
@@ -1915,15 +1970,16 @@ static void win_equal_rec(
topfr->fr_width = width;
topfr->fr_height = height;
- if (dir != 'v') { /* equalize frame widths */
+ if (dir != 'v') { // equalize frame widths
/* Compute the maximum number of windows horizontally in this
* frame. */
n = frame_minwidth(topfr, NOWIN);
- /* add one for the rightmost window, it doesn't have a separator */
- if (col + width == Columns)
+ // add one for the rightmost window, it doesn't have a separator
+ if (col + width == Columns) {
extra_sep = 1;
- else
+ } else {
extra_sep = 0;
+ }
totwincount = (n + extra_sep) / (p_wmw + 1);
has_next_curwin = frame_has_win(topfr, next_curwin);
@@ -1951,12 +2007,14 @@ static void win_equal_rec(
if (frame_has_win(fr, next_curwin)) {
room += p_wiw - p_wmw;
next_curwin_size = 0;
- if (new_size < p_wiw)
+ if (new_size < p_wiw) {
new_size = p_wiw;
- } else
- /* These windows don't use up room. */
+ }
+ } else {
+ // These windows don't use up room.
totwincount -= (n + (fr->fr_next == NULL
? extra_sep : 0)) / (p_wmw + 1);
+ }
room -= new_size - n;
if (room < 0) {
new_size += room;
@@ -1965,58 +2023,64 @@ static void win_equal_rec(
fr->fr_newwidth = new_size;
}
if (next_curwin_size == -1) {
- if (!has_next_curwin)
+ if (!has_next_curwin) {
next_curwin_size = 0;
- else if (totwincount > 1
- && (room + (totwincount - 2))
- / (totwincount - 1) > p_wiw) {
+ } else if (totwincount > 1
+ && (room + (totwincount - 2))
+ / (totwincount - 1) > p_wiw) {
/* Can make all windows wider than 'winwidth', spread
* the room equally. */
next_curwin_size = (room + p_wiw
+ (totwincount - 1) * p_wmw
+ (totwincount - 1)) / totwincount;
room -= next_curwin_size - p_wiw;
- } else
+ } else {
next_curwin_size = p_wiw;
+ }
}
}
- if (has_next_curwin)
- --totwincount; /* don't count curwin */
+ if (has_next_curwin) {
+ --totwincount; // don't count curwin
+ }
}
FOR_ALL_FRAMES(fr, topfr->fr_child) {
wincount = 1;
- if (fr->fr_next == NULL)
- /* last frame gets all that remains (avoid roundoff error) */
+ if (fr->fr_next == NULL) {
+ // last frame gets all that remains (avoid roundoff error)
new_size = width;
- else if (dir == 'v')
+ } else if (dir == 'v') {
new_size = fr->fr_width;
- else if (frame_fixed_width(fr)) {
+ } else if (frame_fixed_width(fr)) {
new_size = fr->fr_newwidth;
- wincount = 0; /* doesn't count as a sizeable window */
+ wincount = 0; // doesn't count as a sizeable window
} else {
- /* Compute the maximum number of windows horiz. in "fr". */
+ // Compute the maximum number of windows horiz. in "fr".
n = frame_minwidth(fr, NOWIN);
wincount = (n + (fr->fr_next == NULL ? extra_sep : 0))
/ (p_wmw + 1);
m = frame_minwidth(fr, next_curwin);
- if (has_next_curwin)
+ if (has_next_curwin) {
hnc = frame_has_win(fr, next_curwin);
- else
- hnc = FALSE;
- if (hnc) /* don't count next_curwin */
- --wincount;
- if (totwincount == 0)
+ } else {
+ hnc = false;
+ }
+ if (hnc) { // don't count next_curwin
+ wincount--;
+ }
+ if (totwincount == 0) {
new_size = room;
- else
+ } else {
new_size = (wincount * room + (totwincount / 2)) / totwincount;
- if (hnc) { /* add next_curwin size */
+ }
+ if (hnc) { // add next_curwin size
next_curwin_size -= p_wiw - (m - n);
new_size += next_curwin_size;
room -= new_size - next_curwin_size;
- } else
+ } else {
room -= new_size;
+ }
new_size += n;
}
@@ -2024,25 +2088,27 @@ static void win_equal_rec(
* window, unless equalizing all frames. */
if (!current || dir != 'v' || topfr->fr_parent != NULL
|| (new_size != fr->fr_width)
- || frame_has_win(fr, next_curwin))
+ || frame_has_win(fr, next_curwin)) {
win_equal_rec(next_curwin, current, fr, dir, col, row,
- new_size, height);
+ new_size, height);
+ }
col += new_size;
width -= new_size;
totwincount -= wincount;
}
- } else { /* topfr->fr_layout == FR_COL */
+ } else { // topfr->fr_layout == FR_COL
topfr->fr_width = width;
topfr->fr_height = height;
- if (dir != 'h') { /* equalize frame heights */
- /* Compute maximum number of windows vertically in this frame. */
+ if (dir != 'h') { // equalize frame heights
+ // Compute maximum number of windows vertically in this frame.
n = frame_minheight(topfr, NOWIN);
- /* add one for the bottom window if it doesn't have a statusline */
- if (row + height == cmdline_row && p_ls == 0)
+ // add one for the bottom window if it doesn't have a statusline
+ if (row + height == cmdline_row && p_ls == 0) {
extra_sep = 1;
- else
+ } else {
extra_sep = 0;
+ }
totwincount = (n + extra_sep) / (p_wmh + 1);
has_next_curwin = frame_has_win(topfr, next_curwin);
@@ -2072,12 +2138,14 @@ static void win_equal_rec(
if (frame_has_win(fr, next_curwin)) {
room += p_wh - p_wmh;
next_curwin_size = 0;
- if (new_size < p_wh)
+ if (new_size < p_wh) {
new_size = p_wh;
- } else
- /* These windows don't use up room. */
+ }
+ } else {
+ // These windows don't use up room.
totwincount -= (n + (fr->fr_next == NULL
? extra_sep : 0)) / (p_wmh + 1);
+ }
room -= new_size - n;
if (room < 0) {
new_size += room;
@@ -2086,67 +2154,74 @@ static void win_equal_rec(
fr->fr_newheight = new_size;
}
if (next_curwin_size == -1) {
- if (!has_next_curwin)
+ if (!has_next_curwin) {
next_curwin_size = 0;
- else if (totwincount > 1
- && (room + (totwincount - 2))
- / (totwincount - 1) > p_wh) {
+ } else if (totwincount > 1
+ && (room + (totwincount - 2))
+ / (totwincount - 1) > p_wh) {
/* can make all windows higher than 'winheight',
* spread the room equally. */
next_curwin_size = (room + p_wh
+ (totwincount - 1) * p_wmh
+ (totwincount - 1)) / totwincount;
room -= next_curwin_size - p_wh;
- } else
+ } else {
next_curwin_size = p_wh;
+ }
}
}
- if (has_next_curwin)
- --totwincount; /* don't count curwin */
+ if (has_next_curwin) {
+ --totwincount; // don't count curwin
+ }
}
FOR_ALL_FRAMES(fr, topfr->fr_child) {
wincount = 1;
- if (fr->fr_next == NULL)
- /* last frame gets all that remains (avoid roundoff error) */
+ if (fr->fr_next == NULL) {
+ // last frame gets all that remains (avoid roundoff error)
new_size = height;
- else if (dir == 'h')
+ } else if (dir == 'h') {
new_size = fr->fr_height;
- else if (frame_fixed_height(fr)) {
+ } else if (frame_fixed_height(fr)) {
new_size = fr->fr_newheight;
- wincount = 0; /* doesn't count as a sizeable window */
+ wincount = 0; // doesn't count as a sizeable window
} else {
- /* Compute the maximum number of windows vert. in "fr". */
+ // Compute the maximum number of windows vert. in "fr".
n = frame_minheight(fr, NOWIN);
wincount = (n + (fr->fr_next == NULL ? extra_sep : 0))
/ (p_wmh + 1);
m = frame_minheight(fr, next_curwin);
- if (has_next_curwin)
+ if (has_next_curwin) {
hnc = frame_has_win(fr, next_curwin);
- else
- hnc = FALSE;
- if (hnc) /* don't count next_curwin */
- --wincount;
- if (totwincount == 0)
+ } else {
+ hnc = false;
+ }
+ if (hnc) { // don't count next_curwin
+ wincount--;
+ }
+ if (totwincount == 0) {
new_size = room;
- else
+ } else {
new_size = (wincount * room + (totwincount / 2)) / totwincount;
- if (hnc) { /* add next_curwin size */
+ }
+ if (hnc) { // add next_curwin size
next_curwin_size -= p_wh - (m - n);
new_size += next_curwin_size;
room -= new_size - next_curwin_size;
- } else
+ } else {
room -= new_size;
+ }
new_size += n;
}
/* Skip frame that is full width when splitting or closing a
* window, unless equalizing all frames. */
if (!current || dir != 'h' || topfr->fr_parent != NULL
|| (new_size != fr->fr_height)
- || frame_has_win(fr, next_curwin))
+ || frame_has_win(fr, next_curwin)) {
win_equal_rec(next_curwin, current, fr, dir, col, row,
- width, new_size);
+ width, new_size);
+ }
row += new_size;
height -= new_size;
totwincount -= wincount;
@@ -2159,7 +2234,7 @@ static void win_equal_rec(
/// @param keep_curwin don't close `curwin`
void close_windows(buf_T *buf, int keep_curwin)
{
- tabpage_T *tp, *nexttp;
+ tabpage_T *tp, *nexttp;
int h = tabline_height();
++RedrawingDisabled;
@@ -2172,13 +2247,14 @@ void close_windows(buf_T *buf, int keep_curwin)
break;
}
- /* Start all over, autocommands may change the window layout. */
+ // Start all over, autocommands may change the window layout.
wp = firstwin;
- } else
+ } else {
wp = wp->w_next;
+ }
}
- /* Also check windows in other tab pages. */
+ // Also check windows in other tab pages.
for (tp = first_tabpage; tp != NULL; tp = nexttp) {
nexttp = tp->tp_next;
if (tp != curtab) {
@@ -2252,14 +2328,13 @@ bool last_nonfloat(win_T *wp) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
/// last window in the tabpage
///
/// @return true when the window was closed already.
-static bool close_last_window_tabpage(win_T *win, bool free_buf,
- tabpage_T *prev_curtab)
+static bool close_last_window_tabpage(win_T *win, bool free_buf, tabpage_T *prev_curtab)
FUNC_ATTR_NONNULL_ARG(1)
{
if (!ONE_WINDOW) {
return false;
}
- buf_T *old_curbuf = curbuf;
+ buf_T *old_curbuf = curbuf;
Terminal *term = win->w_buffer ? win->w_buffer->terminal : NULL;
if (term) {
@@ -2275,8 +2350,8 @@ static bool close_last_window_tabpage(win_T *win, bool free_buf,
* Don't trigger autocommands yet, they may use wrong values, so do
* that below.
*/
- goto_tabpage_tp(alt_tabpage(), FALSE, TRUE);
- redraw_tabline = TRUE;
+ goto_tabpage_tp(alt_tabpage(), false, true);
+ redraw_tabline = true;
// save index for tabclosed event
char_u prev_idx[NUMBUFLEN];
@@ -2288,8 +2363,9 @@ static bool close_last_window_tabpage(win_T *win, bool free_buf,
int h = tabline_height();
win_close_othertab(win, free_buf, prev_curtab);
- if (h != tabline_height())
+ if (h != tabline_height()) {
shell_new_rows();
+ }
}
// Since goto_tabpage_tp above did not trigger *Enter autocommands, do
@@ -2309,12 +2385,12 @@ static bool close_last_window_tabpage(win_T *win, bool free_buf,
// Returns FAIL when the window was not closed.
int win_close(win_T *win, bool free_buf)
{
- win_T *wp;
- int other_buffer = FALSE;
- int close_curwin = FALSE;
+ win_T *wp;
+ bool other_buffer = false;
+ bool close_curwin = false;
int dir;
bool help_window = false;
- tabpage_T *prev_curtab = curtab;
+ tabpage_T *prev_curtab = curtab;
frame_T *win_frame = win->w_floating ? NULL : win->w_frame->fr_parent;
const bool had_diffmode = win->w_p_diff;
@@ -2345,8 +2421,9 @@ int win_close(win_T *win, bool free_buf)
/* When closing the last window in a tab page first go to another tab page
* and then close the window and the tab page to avoid that curwin and
* curtab are invalid while we are freeing memory. */
- if (close_last_window_tabpage(win, free_buf, prev_curtab))
+ if (close_last_window_tabpage(win, free_buf, prev_curtab)) {
return FAIL;
+ }
/* When closing the help window, try restoring a snapshot after closing
* the window. Otherwise clear the snapshot, it's now invalid. */
@@ -2376,14 +2453,16 @@ int win_close(win_T *win, bool free_buf)
* to be the last one left, return now.
*/
if (wp->w_buffer != curbuf) {
- other_buffer = TRUE;
+ other_buffer = true;
win->w_closing = true;
- apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
- if (!win_valid(win))
+ apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, false, curbuf);
+ if (!win_valid(win)) {
return FAIL;
+ }
win->w_closing = false;
- if (last_window())
+ if (last_window()) {
return FAIL;
+ }
}
win->w_closing = true;
apply_autocmds(EVENT_WINLEAVE, NULL, NULL, false, curbuf);
@@ -2391,11 +2470,13 @@ int win_close(win_T *win, bool free_buf)
return FAIL;
}
win->w_closing = false;
- if (last_window())
+ if (last_window()) {
return FAIL;
- /* autocmds may abort script processing */
- if (aborting())
+ }
+ // autocmds may abort script processing
+ if (aborting()) {
return FAIL;
+ }
}
bool was_floating = win->w_floating;
@@ -2502,12 +2583,14 @@ int win_close(win_T *win, bool free_buf)
* finding another window to go to.
*/
for (;; ) {
- if (wp->w_next == NULL)
+ if (wp->w_next == NULL) {
wp = firstwin;
- else
+ } else {
wp = wp->w_next;
- if (wp == curwin)
+ }
+ if (wp == curwin) {
break;
+ }
if (!wp->w_p_pvw && !bt_quickfix(wp->w_buffer)) {
curwin = wp;
break;
@@ -2515,7 +2598,7 @@ int win_close(win_T *win, bool free_buf)
}
}
curbuf = curwin->w_buffer;
- close_curwin = TRUE;
+ close_curwin = true;
// The cursor position may be invalid if the buffer changed after last
// using the window.
@@ -2533,7 +2616,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);
@@ -2544,12 +2628,13 @@ int win_close(win_T *win, bool free_buf)
* If last window has a status line now and we don't want one,
* remove the status line.
*/
- last_status(FALSE);
+ last_status(false);
/* After closing the help window, try restoring the window layout from
* before it was opened. */
- if (help_window)
+ if (help_window) {
restore_snapshot(SNAP_HELP_IDX, close_curwin);
+ }
// If the window had 'diff' set and now there is only one window left in
// the tab page with 'diff' set, and "closeoff" is in 'diffopt', then
@@ -2596,8 +2681,8 @@ static void do_autocmd_winclosed(win_T *win)
void win_close_othertab(win_T *win, int free_buf, tabpage_T *tp)
{
int dir;
- tabpage_T *ptp = NULL;
- int free_tp = FALSE;
+ tabpage_T *ptp = NULL;
+ bool free_tp = false;
// Get here with win->w_buffer == NULL when win_close() detects the tab page
// changed.
@@ -2620,26 +2705,28 @@ void win_close_othertab(win_T *win, int free_buf, tabpage_T *tp)
/* Careful: Autocommands may have closed the tab page or made it the
* current tab page. */
- for (ptp = first_tabpage; ptp != NULL && ptp != tp; ptp = ptp->tp_next)
+ for (ptp = first_tabpage; ptp != NULL && ptp != tp; ptp = ptp->tp_next) {
;
- if (ptp == NULL || tp == curtab)
+ }
+ if (ptp == NULL || tp == curtab) {
return;
+ }
- /* Autocommands may have closed the window already. */
+ // Autocommands may have closed the window already.
{
bool found_window = false;
FOR_ALL_WINDOWS_IN_TAB(wp, tp) {
if (wp == win) {
- found_window = true;
- break;
+ found_window = true;
+ break;
}
}
if (!found_window) {
- return;
+ return;
}
}
- /* When closing the last window in a tab page remove the tab page. */
+ // When closing the last window in a tab page remove the tab page.
if (tp->tp_firstwin == tp->tp_lastwin) {
char_u prev_idx[NUMBUFLEN];
if (has_event(EVENT_TABCLOSED)) {
@@ -2666,23 +2753,24 @@ void win_close_othertab(win_T *win, int free_buf, tabpage_T *tp)
}
}
- /* Free the memory used for the window. */
+ // Free the memory used for the window.
win_free_mem(win, &dir, tp);
- if (free_tp)
+ if (free_tp) {
free_tabpage(tp);
+ }
}
-// Free the memory used for a window.
-// Returns a pointer to the window that got the freed up space.
-static win_T *win_free_mem(
- win_T *win,
- int *dirp, // set to 'v' or 'h' for direction if 'ea'
- tabpage_T *tp // tab page "win" is in, NULL for current
-)
+/// Free the memory used for a window.
+///
+/// @param dirp set to 'v' or 'h' for direction if 'ea'
+/// @param tp tab page "win" is in, NULL for current
+///
+/// @return a pointer to the window that got the freed up space.
+static win_T *win_free_mem(win_T *win, int *dirp, tabpage_T *tp)
{
- frame_T *frp;
- win_T *wp;
+ frame_T *frp;
+ win_T *wp;
if (!win->w_floating) {
// Remove the window and its frame from the tree of frames.
@@ -2702,7 +2790,11 @@ static win_T *win_free_mem(
// When deleting the current window of another tab page select a new
// current window.
if (tp != NULL && win == tp->tp_curwin) {
- tp->tp_curwin = wp;
+ if (win_valid(tp->tp_prevwin) && tp->tp_prevwin != win) {
+ tp->tp_curwin = tp->tp_prevwin;
+ } else {
+ tp->tp_curwin = tp->tp_firstwin;
+ }
}
return wp;
@@ -2713,8 +2805,9 @@ void win_free_all(void)
{
int dummy;
- while (first_tabpage->tp_next != NULL)
+ while (first_tabpage->tp_next != NULL) {
tabpage_close(TRUE);
+ }
while (lastwin != NULL && lastwin->w_floating) {
win_T *wp = lastwin;
@@ -2730,8 +2823,9 @@ void win_free_all(void)
aucmd_win = NULL;
}
- while (firstwin != NULL)
+ while (firstwin != NULL) {
(void)win_free_mem(firstwin, &dummy, NULL);
+ }
// No window should be used after this. Set curwin to NULL to crash
// instead of using freed memory.
@@ -2740,26 +2834,24 @@ void win_free_all(void)
#endif
-/*
- * Remove a window and its frame from the tree of frames.
- * Returns a pointer to the window that got the freed up space.
- */
-win_T *
-winframe_remove (
- win_T *win,
- int *dirp, /* set to 'v' or 'h' for direction if 'ea' */
- tabpage_T *tp /* tab page "win" is in, NULL for current */
-)
+/// Remove a window and its frame from the tree of frames.
+///
+/// @param dirp set to 'v' or 'h' for direction if 'ea'
+/// @param tp tab page "win" is in, NULL for current
+///
+/// @return a pointer to the window that got the freed up space.
+win_T *winframe_remove(win_T *win, int *dirp, tabpage_T *tp)
{
- frame_T *frp, *frp2, *frp3;
- frame_T *frp_close = win->w_frame;
- win_T *wp;
+ frame_T *frp, *frp2, *frp3;
+ frame_T *frp_close = win->w_frame;
+ win_T *wp;
/*
* If there is only one window there is nothing to remove.
*/
- if (tp == NULL ? ONE_WINDOW : tp->tp_firstwin == tp->tp_lastwin)
+ if (tp == NULL ? ONE_WINDOW : tp->tp_firstwin == tp->tp_lastwin) {
return NULL;
+ }
/*
* Remove the window from its frame.
@@ -2767,7 +2859,7 @@ winframe_remove (
frp2 = win_altframe(win, tp);
wp = frame2win(frp2);
- /* Remove this frame from the list of frames. */
+ // Remove this frame from the list of frames.
frame_remove(frp_close);
if (frp_close->fr_parent->fr_layout == FR_COL) {
@@ -2797,7 +2889,7 @@ winframe_remove (
}
}
frame_new_height(frp2, frp2->fr_height + frp_close->fr_height,
- frp2 == frp_close->fr_next ? TRUE : FALSE, FALSE);
+ frp2 == frp_close->fr_next, false);
*dirp = 'v';
} else {
/* When 'winfixwidth' is set, try to find another frame in the column
@@ -2826,7 +2918,7 @@ winframe_remove (
}
}
frame_new_width(frp2, frp2->fr_width + frp_close->fr_width,
- frp2 == frp_close->fr_next ? TRUE : FALSE, FALSE);
+ frp2 == frp_close->fr_next, false);
*dirp = 'h';
}
@@ -2848,8 +2940,9 @@ winframe_remove (
frp->fr_parent = frp2->fr_parent;
}
frp2->fr_parent->fr_win = frp2->fr_win;
- if (frp2->fr_win != NULL)
+ if (frp2->fr_win != NULL) {
frp2->fr_win->w_frame = frp2->fr_parent;
+ }
frp = frp2->fr_parent;
if (topframe->fr_child == frp2) {
topframe->fr_child = frp;
@@ -2860,18 +2953,21 @@ winframe_remove (
if (frp2 != NULL && frp2->fr_layout == frp->fr_layout) {
/* The frame above the parent has the same layout, have to merge
* the frames into this list. */
- if (frp2->fr_child == frp)
+ if (frp2->fr_child == frp) {
frp2->fr_child = frp->fr_child;
+ }
assert(frp->fr_child);
frp->fr_child->fr_prev = frp->fr_prev;
- if (frp->fr_prev != NULL)
+ if (frp->fr_prev != NULL) {
frp->fr_prev->fr_next = frp->fr_child;
+ }
for (frp3 = frp->fr_child;; frp3 = frp3->fr_next) {
frp3->fr_parent = frp2;
if (frp3->fr_next == NULL) {
frp3->fr_next = frp->fr_next;
- if (frp->fr_next != NULL)
+ if (frp->fr_next != NULL) {
frp->fr_next->fr_prev = frp3;
+ }
break;
}
}
@@ -2885,21 +2981,19 @@ winframe_remove (
return wp;
}
-// Return a pointer to the frame that will receive the empty screen space that
-// is left over after "win" is closed.
-//
-// If 'splitbelow' or 'splitright' is set, the space goes above or to the left
-// by default. Otherwise, the free space goes below or to the right. The
-// result is that opening a window and then immediately closing it will
-// preserve the initial window layout. The 'wfh' and 'wfw' settings are
-// respected when possible.
-static frame_T *
-win_altframe (
- win_T *win,
- tabpage_T *tp /* tab page "win" is in, NULL for current */
-)
-{
- frame_T *frp;
+/// If 'splitbelow' or 'splitright' is set, the space goes above or to the left
+/// by default. Otherwise, the free space goes below or to the right. The
+/// result is that opening a window and then immediately closing it will
+/// preserve the initial window layout. The 'wfh' and 'wfw' settings are
+/// respected when possible.
+///
+/// @param tp tab page "win" is in, NULL for current
+///
+/// @return a pointer to the frame that will receive the empty screen space that
+/// is left over after "win" is closed.
+static frame_T *win_altframe(win_T *win, tabpage_T *tp)
+{
+ frame_T *frp;
if (tp == NULL ? ONE_WINDOW : tp->tp_firstwin == tp->tp_lastwin) {
return alt_tabpage()->tp_curwin->w_frame;
@@ -2941,15 +3035,17 @@ win_altframe (
*/
static tabpage_T *alt_tabpage(void)
{
- tabpage_T *tp;
+ tabpage_T *tp;
- /* Use the next tab page if possible. */
- if (curtab->tp_next != NULL)
+ // Use the next tab page if possible.
+ if (curtab->tp_next != NULL) {
return curtab->tp_next;
+ }
- /* Find the last but one tab page. */
- for (tp = first_tabpage; tp->tp_next != curtab; tp = tp->tp_next)
+ // Find the last but one tab page.
+ for (tp = first_tabpage; tp->tp_next != curtab; tp = tp->tp_next) {
;
+ }
return tp;
}
@@ -2958,8 +3054,9 @@ static tabpage_T *alt_tabpage(void)
*/
static win_T *frame2win(frame_T *frp)
{
- while (frp->fr_win == NULL)
+ while (frp->fr_win == NULL) {
frp = frp->fr_child;
+ }
return frp->fr_win;
}
@@ -2982,21 +3079,16 @@ static bool frame_has_win(const frame_T *frp, const win_T *wp)
return false;
}
-/*
- * Set a new height for a frame. Recursively sets the height for contained
- * frames and windows. Caller must take care of positions.
- */
-static void
-frame_new_height (
- frame_T *topfrp,
- int height,
- int topfirst, /* resize topmost contained frame first */
- int wfh /* obey 'winfixheight' when there is a choice;
- may cause the height not to be set */
-)
+/// Set a new height for a frame. Recursively sets the height for contained
+/// frames and windows. Caller must take care of positions.
+///
+/// @param topfirst resize topmost contained frame first.
+/// @param wfh obey 'winfixheight' when there is a choice;
+/// may cause the height not to be set.
+static void frame_new_height(frame_T *topfrp, int height, bool topfirst, bool wfh)
FUNC_ATTR_NONNULL_ALL
{
- frame_T *frp;
+ frame_T *frp;
int extra_lines;
int h;
@@ -3010,37 +3102,42 @@ frame_new_height (
FOR_ALL_FRAMES(frp, topfrp->fr_child) {
frame_new_height(frp, height, topfirst, wfh);
if (frp->fr_height > height) {
- /* Could not fit the windows, make the whole row higher. */
+ // Could not fit the windows, make the whole row higher.
height = frp->fr_height;
break;
}
}
} while (frp != NULL);
- } else { /* fr_layout == FR_COL */
+ } else { // fr_layout == FR_COL
/* Complicated case: Resize a column of frames. Resize the bottom
* frame first, frames above that when needed. */
frp = topfrp->fr_child;
- if (wfh)
- /* Advance past frames with one window with 'wfh' set. */
+ if (wfh) {
+ // Advance past frames with one window with 'wfh' set.
while (frame_fixed_height(frp)) {
frp = frp->fr_next;
- if (frp == NULL)
- return; /* no frame without 'wfh', give up */
+ if (frp == NULL) {
+ return; // no frame without 'wfh', give up
+ }
}
+ }
if (!topfirst) {
- /* Find the bottom frame of this column */
- while (frp->fr_next != NULL)
+ // Find the bottom frame of this column
+ while (frp->fr_next != NULL) {
frp = frp->fr_next;
- if (wfh)
- /* Advance back for frames with one window with 'wfh' set. */
- while (frame_fixed_height(frp))
+ }
+ if (wfh) {
+ // Advance back for frames with one window with 'wfh' set.
+ while (frame_fixed_height(frp)) {
frp = frp->fr_prev;
+ }
+ }
}
extra_lines = height - topfrp->fr_height;
if (extra_lines < 0) {
- /* reduce height of contained frames, bottom or top frame first */
+ // reduce height of contained frames, bottom or top frame first
while (frp != NULL) {
h = frame_minheight(frp, NULL);
if (frp->fr_height + extra_lines < h) {
@@ -3048,7 +3145,7 @@ frame_new_height (
frame_new_height(frp, h, topfirst, wfh);
} else {
frame_new_height(frp, frp->fr_height + extra_lines,
- topfirst, wfh);
+ topfirst, wfh);
break;
}
if (topfirst) {
@@ -3060,12 +3157,13 @@ frame_new_height (
frp = frp->fr_prev;
while (wfh && frp != NULL && frame_fixed_height(frp));
}
- /* Increase "height" if we could not reduce enough frames. */
- if (frp == NULL)
+ // Increase "height" if we could not reduce enough frames.
+ if (frp == NULL) {
height -= extra_lines;
+ }
}
} else if (extra_lines > 0) {
- /* increase height of bottom or top frame */
+ // increase height of bottom or top frame
frame_new_height(frp, frp->fr_height + extra_lines, topfirst, wfh);
}
}
@@ -3146,13 +3244,14 @@ static bool frame_fixed_width(frame_T *frp)
*/
static void frame_add_statusline(frame_T *frp)
{
- win_T *wp;
+ win_T *wp;
if (frp->fr_layout == FR_LEAF) {
wp = frp->fr_win;
if (wp->w_status_height == 0) {
- if (wp->w_height > 0) /* don't make it negative */
+ if (wp->w_height > 0) { // don't make it negative
--wp->w_height;
+ }
wp->w_status_height = STATUS_HEIGHT;
}
} else if (frp->fr_layout == FR_ROW) {
@@ -3169,33 +3268,31 @@ static void frame_add_statusline(frame_T *frp)
}
}
-/*
- * Set width of a frame. Handles recursively going through contained frames.
- * May remove separator line for windows at the right side (for win_close()).
- */
-static void
-frame_new_width (
- frame_T *topfrp,
- int width,
- int leftfirst, /* resize leftmost contained frame first */
- int wfw /* obey 'winfixwidth' when there is a choice;
- may cause the width not to be set */
-)
-{
- frame_T *frp;
+/// Set width of a frame. Handles recursively going through contained frames.
+/// May remove separator line for windows at the right side (for win_close()).
+///
+/// @param leftfirst resize leftmost contained frame first.
+/// @param wfw obey 'winfixwidth' when there is a choice;
+/// may cause the width not to be set.
+static void frame_new_width(frame_T *topfrp, int width, bool leftfirst, bool wfw)
+{
+ frame_T *frp;
int extra_cols;
int w;
- win_T *wp;
+ win_T *wp;
if (topfrp->fr_layout == FR_LEAF) {
- /* Simple case: just one window. */
+ // Simple case: just one window.
wp = topfrp->fr_win;
- /* Find out if there are any windows right of this one. */
- for (frp = topfrp; frp->fr_parent != NULL; frp = frp->fr_parent)
- if (frp->fr_parent->fr_layout == FR_ROW && frp->fr_next != NULL)
+ // Find out if there are any windows right of this one.
+ for (frp = topfrp; frp->fr_parent != NULL; frp = frp->fr_parent) {
+ if (frp->fr_parent->fr_layout == FR_ROW && frp->fr_next != NULL) {
break;
- if (frp->fr_parent == NULL)
+ }
+ }
+ if (frp->fr_parent == NULL) {
wp->w_vsep_width = 0;
+ }
win_new_width(wp, width - wp->w_vsep_width);
} else if (topfrp->fr_layout == FR_COL) {
do {
@@ -3203,37 +3300,42 @@ frame_new_width (
FOR_ALL_FRAMES(frp, topfrp->fr_child) {
frame_new_width(frp, width, leftfirst, wfw);
if (frp->fr_width > width) {
- /* Could not fit the windows, make whole column wider. */
+ // Could not fit the windows, make whole column wider.
width = frp->fr_width;
break;
}
}
} while (frp != NULL);
- } else { /* fr_layout == FR_ROW */
+ } else { // fr_layout == FR_ROW
/* Complicated case: Resize a row of frames. Resize the rightmost
* frame first, frames left of it when needed. */
frp = topfrp->fr_child;
- if (wfw)
- /* Advance past frames with one window with 'wfw' set. */
+ if (wfw) {
+ // Advance past frames with one window with 'wfw' set.
while (frame_fixed_width(frp)) {
frp = frp->fr_next;
- if (frp == NULL)
- return; /* no frame without 'wfw', give up */
+ if (frp == NULL) {
+ return; // no frame without 'wfw', give up
+ }
}
+ }
if (!leftfirst) {
- /* Find the rightmost frame of this row */
- while (frp->fr_next != NULL)
+ // Find the rightmost frame of this row
+ while (frp->fr_next != NULL) {
frp = frp->fr_next;
- if (wfw)
- /* Advance back for frames with one window with 'wfw' set. */
- while (frame_fixed_width(frp))
+ }
+ if (wfw) {
+ // Advance back for frames with one window with 'wfw' set.
+ while (frame_fixed_width(frp)) {
frp = frp->fr_prev;
+ }
+ }
}
extra_cols = width - topfrp->fr_width;
if (extra_cols < 0) {
- /* reduce frame width, rightmost frame first */
+ // reduce frame width, rightmost frame first
while (frp != NULL) {
w = frame_minwidth(frp, NULL);
if (frp->fr_width + extra_cols < w) {
@@ -3241,7 +3343,7 @@ frame_new_width (
frame_new_width(frp, w, leftfirst, wfw);
} else {
frame_new_width(frp, frp->fr_width + extra_cols,
- leftfirst, wfw);
+ leftfirst, wfw);
break;
}
if (leftfirst) {
@@ -3253,12 +3355,13 @@ frame_new_width (
frp = frp->fr_prev;
while (wfw && frp != NULL && frame_fixed_width(frp));
}
- /* Increase "width" if we could not reduce enough frames. */
- if (frp == NULL)
+ // Increase "width" if we could not reduce enough frames.
+ if (frp == NULL) {
width -= extra_cols;
+ }
}
} else if (extra_cols > 0) {
- /* increase width of rightmost frame */
+ // increase width of rightmost frame
frame_new_width(frp, frp->fr_width + extra_cols, leftfirst, wfw);
}
}
@@ -3272,13 +3375,14 @@ frame_new_width (
static void frame_add_vsep(const frame_T *frp)
FUNC_ATTR_NONNULL_ARG(1)
{
- win_T *wp;
+ win_T *wp;
if (frp->fr_layout == FR_LEAF) {
wp = frp->fr_win;
if (wp->w_vsep_width == 0) {
- if (wp->w_width > 0) /* don't make it negative */
+ if (wp->w_width > 0) { // don't make it negative
--wp->w_width;
+ }
wp->w_vsep_width = 1;
}
} else if (frp->fr_layout == FR_COL) {
@@ -3290,8 +3394,9 @@ static void frame_add_vsep(const frame_T *frp)
assert(frp->fr_layout == FR_ROW);
// Only need to handle the last frame in the row.
frp = frp->fr_child;
- while (frp->fr_next != NULL)
+ while (frp->fr_next != NULL) {
frp = frp->fr_next;
+ }
frame_add_vsep(frp);
}
}
@@ -3322,7 +3427,7 @@ static void frame_fix_height(win_T *wp)
*/
static int frame_minheight(frame_T *topfrp, win_T *next_curwin)
{
- frame_T *frp;
+ frame_T *frp;
int m;
int n;
@@ -3340,15 +3445,16 @@ static int frame_minheight(frame_T *topfrp, win_T *next_curwin)
}
}
} else if (topfrp->fr_layout == FR_ROW) {
- /* get the minimal height from each frame in this row */
+ // get the minimal height from each frame in this row
m = 0;
FOR_ALL_FRAMES(frp, topfrp->fr_child) {
n = frame_minheight(frp, next_curwin);
- if (n > m)
+ if (n > m) {
m = n;
+ }
}
} else {
- /* Add up the minimal heights for all frames in this column. */
+ // Add up the minimal heights for all frames in this column.
m = 0;
FOR_ALL_FRAMES(frp, topfrp->fr_child) {
m += frame_minheight(frp, next_curwin);
@@ -3358,41 +3464,39 @@ static int frame_minheight(frame_T *topfrp, win_T *next_curwin)
return m;
}
-/*
- * Compute the minimal width for frame "topfrp".
- * When "next_curwin" isn't NULL, use p_wiw for this window.
- * When "next_curwin" is NOWIN, don't use at least one column for the current
- * window.
- */
-static int
-frame_minwidth (
- frame_T *topfrp,
- win_T *next_curwin /* use p_wh and p_wiw for next_curwin */
-)
+/// Compute the minimal width for frame "topfrp".
+/// When "next_curwin" isn't NULL, use p_wiw for this window.
+/// When "next_curwin" is NOWIN, don't use at least one column for the current
+/// window.
+///
+/// @param next_curwin use p_wh and p_wiw for next_curwin
+static int frame_minwidth(frame_T *topfrp, win_T *next_curwin)
{
- frame_T *frp;
+ frame_T *frp;
int m, n;
if (topfrp->fr_win != NULL) {
- if (topfrp->fr_win == next_curwin)
+ if (topfrp->fr_win == next_curwin) {
m = p_wiw + topfrp->fr_win->w_vsep_width;
- else {
- /* window: minimal width of the window plus separator column */
+ } else {
+ // window: minimal width of the window plus separator column
m = p_wmw + topfrp->fr_win->w_vsep_width;
- /* Current window is minimal one column wide */
- if (p_wmw == 0 && topfrp->fr_win == curwin && next_curwin == NULL)
+ // Current window is minimal one column wide
+ if (p_wmw == 0 && topfrp->fr_win == curwin && next_curwin == NULL) {
++m;
+ }
}
} else if (topfrp->fr_layout == FR_COL) {
- /* get the minimal width from each frame in this column */
+ // get the minimal width from each frame in this column
m = 0;
FOR_ALL_FRAMES(frp, topfrp->fr_child) {
n = frame_minwidth(frp, next_curwin);
- if (n > m)
+ if (n > m) {
m = n;
+ }
}
} else {
- /* Add up the minimal widths for all frames in this row. */
+ // Add up the minimal widths for all frames in this row.
m = 0;
FOR_ALL_FRAMES(frp, topfrp->fr_child) {
m += frame_minwidth(frp, next_curwin);
@@ -3403,21 +3507,17 @@ frame_minwidth (
}
-/*
- * Try to close all windows except current one.
- * Buffers in the other windows become hidden if 'hidden' is set, or '!' is
- * used and the buffer was modified.
- *
- * Used by ":bdel" and ":only".
- */
-void
-close_others (
- int message,
- int forceit /* always hide all other windows */
-)
-{
- win_T *wp;
- win_T *nextwp;
+/// Try to close all windows except current one.
+/// Buffers in the other windows become hidden if 'hidden' is set, or '!' is
+/// used and the buffer was modified.
+///
+/// Used by ":bdel" and ":only".
+///
+/// @param forceit always hide all other windows
+void close_others(int message, int forceit)
+{
+ win_T *wp;
+ win_T *nextwp;
int r;
if (curwin->w_floating) {
@@ -3429,23 +3529,22 @@ close_others (
if (one_window() && !lastwin->w_floating) {
if (message
- && !autocmd_busy
- ) {
+ && !autocmd_busy) {
MSG(_(m_onlyone));
}
return;
}
- /* Be very careful here: autocommands may change the window layout. */
+ // Be very careful here: autocommands may change the window layout.
for (wp = firstwin; win_valid(wp); wp = nextwp) {
nextwp = wp->w_next;
- if (wp == curwin) { /* don't close current window */
+ if (wp == curwin) { // don't close current window
continue;
}
- /* Check if it's allowed to abandon this window */
+ // Check if it's allowed to abandon this window
r = can_abandon(wp->w_buffer, forceit);
- if (!win_valid(wp)) { /* autocommands messed wp up */
+ if (!win_valid(wp)) { // autocommands messed wp up
nextwp = firstwin;
continue;
}
@@ -3457,14 +3556,16 @@ close_others (
continue;
}
}
- if (bufIsChanged(wp->w_buffer))
+ if (bufIsChanged(wp->w_buffer)) {
continue;
+ }
}
win_close(wp, !buf_hide(wp->w_buffer) && !bufIsChanged(wp->w_buffer));
}
- if (message && !ONE_WINDOW)
+ if (message && !ONE_WINDOW) {
EMSG(_("E445: Other window contains changes"));
+ }
}
@@ -3484,7 +3585,7 @@ void win_init_empty(win_T *wp)
wp->w_cursor.lnum = 1;
wp->w_curswant = wp->w_cursor.col = 0;
wp->w_cursor.coladd = 0;
- wp->w_pcmark.lnum = 1; /* pcmark not cleared but set to line 1 */
+ wp->w_pcmark.lnum = 1; // pcmark not cleared but set to line 1
wp->w_pcmark.col = 0;
wp->w_prev_pcmark.lnum = 0;
wp->w_prev_pcmark.col = 0;
@@ -3502,8 +3603,9 @@ void win_init_empty(win_T *wp)
*/
int win_alloc_first(void)
{
- if (win_alloc_firstwin(NULL) == FAIL)
+ if (win_alloc_firstwin(NULL) == FAIL) {
return FAIL;
+ }
first_tabpage = alloc_tabpage();
first_tabpage->tp_topframe = topframe;
@@ -3537,7 +3639,7 @@ void win_alloc_aucmd_win(void)
*/
static int win_alloc_firstwin(win_T *oldwin)
{
- curwin = win_alloc(NULL, FALSE);
+ curwin = win_alloc(NULL, false);
if (oldwin == NULL) {
/* Very first window, need to create an empty buffer for it and
* initialize from scratch. */
@@ -3547,14 +3649,14 @@ static int win_alloc_firstwin(win_T *oldwin)
}
curwin->w_buffer = curbuf;
curwin->w_s = &(curbuf->b_s);
- curbuf->b_nwindows = 1; /* there is one window */
+ curbuf->b_nwindows = 1; // there is one window
curwin->w_alist = &global_alist;
- curwin_init(); /* init current window */
+ curwin_init(); // init current window
} else {
- /* First window in new tab page, initialize it from "oldwin". */
+ // First window in new tab page, initialize it from "oldwin".
win_init(curwin, oldwin, 0);
- /* We don't want cursor- and scroll-binding in the first window. */
+ // We don't want cursor- and scroll-binding in the first window.
RESET_BINDING(curwin);
}
@@ -3601,7 +3703,7 @@ static tabpage_T *alloc_tabpage(void)
static int last_tp_handle = 0;
tabpage_T *tp = xcalloc(1, sizeof(tabpage_T));
tp->handle = ++last_tp_handle;
- handle_register_tabpage(tp);
+ pmap_put(handle_T)(&tabpage_handles, tp->handle, tp);
// Init t: variables.
tp->tp_vars = tv_dict_alloc();
@@ -3616,11 +3718,12 @@ void free_tabpage(tabpage_T *tp)
{
int idx;
- handle_unregister_tabpage(tp);
+ pmap_del(handle_T)(&tabpage_handles, tp->handle);
diff_clear(tp);
- for (idx = 0; idx < SNAP_COUNT; ++idx)
+ for (idx = 0; idx < SNAP_COUNT; ++idx) {
clear_snapshot(tp, idx);
- vars_clear(&tp->tp_vars->dv_hashtab); /* free all t: variables */
+ }
+ vars_clear(&tp->tp_vars->dv_hashtab); // free all t: variables
hash_init(&tp->tp_vars->dv_hashtab);
unref_var_dict(tp->tp_vars);
@@ -3642,8 +3745,8 @@ void free_tabpage(tabpage_T *tp)
/// @return Was the new tabpage created successfully? FAIL or OK.
int win_new_tabpage(int after, char_u *filename)
{
- tabpage_T *old_curtab = curtab;
- tabpage_T *newtp;
+ tabpage_T *old_curtab = curtab;
+ tabpage_T *newtp;
int n;
newtp = alloc_tabpage();
@@ -3667,14 +3770,15 @@ int win_new_tabpage(int after, char_u *filename)
newtp->tp_next = first_tabpage;
first_tabpage = newtp;
} else {
- tabpage_T *tp = old_curtab;
+ tabpage_T *tp = old_curtab;
if (after > 0) {
// Put new tab page before tab page "after".
n = 2;
for (tp = first_tabpage; tp->tp_next != NULL
- && n < after; tp = tp->tp_next)
+ && n < after; tp = tp->tp_next) {
++n;
+ }
}
newtp->tp_next = tp->tp_next;
tp->tp_next = newtp;
@@ -3717,7 +3821,7 @@ int may_open_tabpage(void)
int n = (cmdmod.tab == 0) ? postponed_split_tab : cmdmod.tab;
if (n != 0) {
- cmdmod.tab = 0; /* reset it to avoid doing it twice */
+ cmdmod.tab = 0; // reset it to avoid doing it twice
postponed_split_tab = 0;
return win_new_tabpage(n, NULL);
}
@@ -3733,9 +3837,10 @@ int make_tabpages(int maxcount)
int count = maxcount;
int todo;
- /* Limit to 'tabpagemax' tabs. */
- if (count > p_tpm)
+ // Limit to 'tabpagemax' tabs.
+ if (count > p_tpm) {
count = p_tpm;
+ }
/*
* Don't execute autocommands while creating the tab pages. Must do that
@@ -3751,7 +3856,7 @@ int make_tabpages(int maxcount)
unblock_autocmds();
- /* return actual number of tab pages */
+ // return actual number of tab pages
return count - todo;
}
@@ -3812,11 +3917,12 @@ void close_tabpage(tabpage_T *tab)
*/
tabpage_T *find_tabpage(int n)
{
- tabpage_T *tp;
+ tabpage_T *tp;
int i = 1;
- for (tp = first_tabpage; tp != NULL && i != n; tp = tp->tp_next)
+ for (tp = first_tabpage; tp != NULL && i != n; tp = tp->tp_next) {
++i;
+ }
return tp;
}
@@ -3827,41 +3933,42 @@ tabpage_T *find_tabpage(int n)
int tabpage_index(tabpage_T *ftp)
{
int i = 1;
- tabpage_T *tp;
+ tabpage_T *tp;
- for (tp = first_tabpage; tp != NULL && tp != ftp; tp = tp->tp_next)
+ for (tp = first_tabpage; tp != NULL && tp != ftp; tp = tp->tp_next) {
++i;
+ }
return i;
}
-/*
- * Prepare for leaving the current tab page.
- * When autocommands change "curtab" we don't leave the tab page and return
- * FAIL.
- * Careful: When OK is returned need to get a new tab page very very soon!
- */
-static int
-leave_tabpage (
- buf_T *new_curbuf, /* what is going to be the new curbuf,
- NULL if unknown */
- int trigger_leave_autocmds
-)
+/// Prepare for leaving the current tab page.
+/// When autocommands change "curtab" we don't leave the tab page and return
+/// FAIL.
+/// Careful: When OK is returned need to get a new tab page very very soon!
+///
+/// @param new_curbuf what is going to be the new curbuf,
+/// NULL if unknown.
+/// @param trigger_leave_autocmds when true trigger *Leave autocommands.
+static int leave_tabpage(buf_T *new_curbuf, bool trigger_leave_autocmds)
{
- tabpage_T *tp = curtab;
+ tabpage_T *tp = curtab;
- reset_VIsual_and_resel(); /* stop Visual mode */
+ reset_VIsual_and_resel(); // stop Visual mode
if (trigger_leave_autocmds) {
if (new_curbuf != curbuf) {
- apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
- if (curtab != tp)
+ apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, false, curbuf);
+ if (curtab != tp) {
return FAIL;
+ }
}
- apply_autocmds(EVENT_WINLEAVE, NULL, NULL, FALSE, curbuf);
- if (curtab != tp)
+ apply_autocmds(EVENT_WINLEAVE, NULL, NULL, false, curbuf);
+ if (curtab != tp) {
return FAIL;
- apply_autocmds(EVENT_TABLEAVE, NULL, NULL, FALSE, curbuf);
- if (curtab != tp)
+ }
+ apply_autocmds(EVENT_TABLEAVE, NULL, NULL, false, curbuf);
+ if (curtab != tp) {
return FAIL;
+ }
}
tp->tp_curwin = curwin;
tp->tp_prevwin = prevwin;
@@ -3874,16 +3981,16 @@ leave_tabpage (
return OK;
}
-/*
- * Start using tab page "tp".
- * Only to be used after leave_tabpage() or freeing the current tab page.
- * Only trigger *Enter autocommands when trigger_enter_autocmds is TRUE.
- * Only trigger *Leave autocommands when trigger_leave_autocmds is TRUE.
- */
-static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, int trigger_enter_autocmds, int trigger_leave_autocmds)
+/// Start using tab page "tp".
+/// Only to be used after leave_tabpage() or freeing the current tab page.
+///
+/// @param trigger_enter_autocmds when true trigger *Enter autocommands.
+/// @param trigger_leave_autocmds when true trigger *Leave autocommands.
+static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, bool trigger_enter_autocmds,
+ bool trigger_leave_autocmds)
{
int old_off = tp->tp_firstwin->w_winrow;
- win_T *next_prevwin = tp->tp_prevwin;
+ win_T *next_prevwin = tp->tp_prevwin;
tabpage_T *old_curtab = curtab;
curtab = tp;
@@ -3892,14 +3999,15 @@ static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, int trigger_enter_au
topframe = tp->tp_topframe;
if (old_curtab != curtab) {
- tabpage_check_windows(old_curtab);
+ 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
@@ -3934,9 +4042,10 @@ static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, int trigger_enter_au
/* Apply autocommands after updating the display, when 'rows' and
* 'columns' have been set correctly. */
if (trigger_enter_autocmds) {
- apply_autocmds(EVENT_TABENTER, NULL, NULL, FALSE, curbuf);
- if (old_curbuf != curbuf)
- apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf);
+ apply_autocmds(EVENT_TABENTER, NULL, NULL, false, curbuf);
+ if (old_curbuf != curbuf) {
+ apply_autocmds(EVENT_BUFENTER, NULL, NULL, false, curbuf);
+ }
}
redraw_all_later(NOT_VALID);
@@ -3977,8 +4086,8 @@ static void tabpage_check_windows(tabpage_T *old_curtab)
*/
void goto_tabpage(int n)
{
- tabpage_T *tp = NULL; // shut up compiler
- tabpage_T *ttp;
+ tabpage_T *tp = NULL; // shut up compiler
+ tabpage_T *ttp;
int i;
if (text_locked()) {
@@ -3987,35 +4096,39 @@ void goto_tabpage(int n)
return;
}
- /* If there is only one it can't work. */
+ // If there is only one it can't work.
if (first_tabpage->tp_next == NULL) {
- if (n > 1)
+ if (n > 1) {
beep_flush();
+ }
return;
}
if (n == 0) {
- /* No count, go to next tab page, wrap around end. */
- if (curtab->tp_next == NULL)
+ // No count, go to next tab page, wrap around end.
+ if (curtab->tp_next == NULL) {
tp = first_tabpage;
- else
+ } else {
tp = curtab->tp_next;
+ }
} else if (n < 0) {
/* "gT": go to previous tab page, wrap around end. "N gT" repeats
* this N times. */
ttp = curtab;
for (i = n; i < 0; ++i) {
for (tp = first_tabpage; tp->tp_next != ttp && tp->tp_next != NULL;
- tp = tp->tp_next)
+ tp = tp->tp_next) {
;
+ }
ttp = tp;
}
} else if (n == 9999) {
- /* Go to last tab page. */
- for (tp = first_tabpage; tp->tp_next != NULL; tp = tp->tp_next)
+ // Go to last tab page.
+ for (tp = first_tabpage; tp->tp_next != NULL; tp = tp->tp_next) {
;
+ }
} else {
- /* Go to tab page "n". */
+ // Go to tab page "n".
tp = find_tabpage(n);
if (tp == NULL) {
beep_flush();
@@ -4023,29 +4136,28 @@ void goto_tabpage(int n)
}
}
- goto_tabpage_tp(tp, TRUE, TRUE);
-
+ goto_tabpage_tp(tp, true, true);
}
-/*
- * Go to tabpage "tp".
- * Only trigger *Enter autocommands when trigger_enter_autocmds is TRUE.
- * Only trigger *Leave autocommands when trigger_leave_autocmds is TRUE.
- * Note: doesn't update the GUI tab.
- */
-void goto_tabpage_tp(tabpage_T *tp, int trigger_enter_autocmds, int trigger_leave_autocmds)
+/// Go to tabpage "tp".
+/// Note: doesn't update the GUI tab.
+///
+/// @param trigger_enter_autocmds when true trigger *Enter autocommands.
+/// @param trigger_leave_autocmds when true trigger *Leave autocommands.
+void goto_tabpage_tp(tabpage_T *tp, bool trigger_enter_autocmds, bool trigger_leave_autocmds)
{
- /* Don't repeat a message in another tab page. */
+ // Don't repeat a message in another tab page.
set_keep_msg(NULL, 0);
if (tp != curtab && leave_tabpage(tp->tp_curwin->w_buffer,
- trigger_leave_autocmds) == OK) {
- if (valid_tabpage(tp))
+ trigger_leave_autocmds) == OK) {
+ if (valid_tabpage(tp)) {
enter_tabpage(tp, curbuf, trigger_enter_autocmds,
- trigger_leave_autocmds);
- else
+ trigger_leave_autocmds);
+ } else {
enter_tabpage(curtab, curbuf, trigger_enter_autocmds,
- trigger_leave_autocmds);
+ trigger_leave_autocmds);
+ }
}
}
@@ -4064,7 +4176,7 @@ void goto_tabpage_lastused(void)
*/
void goto_tabpage_win(tabpage_T *tp, win_T *wp)
{
- goto_tabpage_tp(tp, TRUE, TRUE);
+ goto_tabpage_tp(tp, true, true);
if (curtab == tp && win_valid(wp)) {
win_enter(wp, true);
}
@@ -4120,8 +4232,8 @@ void tabpage_move(int nr)
tp_dst->tp_next = curtab;
}
- /* Need to redraw the tabline. Tab page contents doesn't change. */
- redraw_tabline = TRUE;
+ // Need to redraw the tabline. Tab page contents doesn't change.
+ redraw_tabline = true;
}
@@ -4134,20 +4246,22 @@ void tabpage_move(int nr)
*/
void win_goto(win_T *wp)
{
- win_T *owp = curwin;
+ win_T *owp = curwin;
if (text_locked()) {
beep_flush();
text_locked_msg();
return;
}
- if (curbuf_locked())
+ if (curbuf_locked()) {
return;
+ }
- if (wp->w_buffer != curbuf)
+ if (wp->w_buffer != curbuf) {
reset_VIsual_and_resel();
- else if (VIsual_active)
+ } else if (VIsual_active) {
wp->w_cursor = curwin->w_cursor;
+ }
win_enter(wp, true);
@@ -4185,9 +4299,9 @@ tabpage_T *win_find_tabpage(win_T *win)
/// @return found window
win_T *win_vert_neighbor(tabpage_T *tp, win_T *wp, bool up, long count)
{
- frame_T *fr;
- frame_T *nfr;
- frame_T *foundfr;
+ frame_T *fr;
+ frame_T *nfr;
+ frame_T *foundfr;
foundfr = wp->w_frame;
@@ -4233,9 +4347,11 @@ win_T *win_vert_neighbor(tabpage_T *tp, win_T *wp, bool up, long count)
fr = fr->fr_next;
}
}
- if (nfr->fr_layout == FR_COL && up)
- while (fr->fr_next != NULL)
+ if (nfr->fr_layout == FR_COL && up) {
+ while (fr->fr_next != NULL) {
fr = fr->fr_next;
+ }
+ }
nfr = fr;
}
}
@@ -4266,9 +4382,9 @@ static void win_goto_ver(bool up, long count)
/// @return found window
win_T *win_horz_neighbor(tabpage_T *tp, win_T *wp, bool left, long count)
{
- frame_T *fr;
- frame_T *nfr;
- frame_T *foundfr;
+ frame_T *fr;
+ frame_T *nfr;
+ frame_T *foundfr;
foundfr = wp->w_frame;
@@ -4307,15 +4423,18 @@ win_T *win_horz_neighbor(tabpage_T *tp, win_T *wp, bool left, long count)
}
fr = nfr->fr_child;
if (nfr->fr_layout == FR_COL) {
- /* Find the frame at the cursor row. */
+ // Find the frame at the cursor row.
while (fr->fr_next != NULL
&& frame2win(fr)->w_winrow + fr->fr_height
- <= wp->w_winrow + wp->w_wrow)
+ <= wp->w_winrow + wp->w_wrow) {
fr = fr->fr_next;
+ }
}
- if (nfr->fr_layout == FR_ROW && left)
- while (fr->fr_next != NULL)
+ if (nfr->fr_layout == FR_ROW && left) {
+ while (fr->fr_next != NULL) {
fr = fr->fr_next;
+ }
+ }
nfr = fr;
}
}
@@ -4341,44 +4460,45 @@ 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.
- * Can be called with "curwin_invalid" TRUE, which means that curwin has just
- * been closed and isn't valid.
- */
-static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid,
- int trigger_new_autocmds, int trigger_enter_autocmds,
- int trigger_leave_autocmds)
+/// Make window "wp" the current window.
+///
+/// @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)
{
- int other_buffer = FALSE;
+ bool other_buffer = false;
+ const bool curwin_invalid = (flags & WEE_CURWIN_INVALID);
- if (wp == curwin && !curwin_invalid) /* nothing to do */
+ 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;
- if (!win_valid(wp))
+ apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, false, curbuf);
+ other_buffer = true;
+ if (!win_valid(wp)) {
return;
+ }
}
- apply_autocmds(EVENT_WINLEAVE, NULL, NULL, FALSE, curbuf);
- if (!win_valid(wp))
+ apply_autocmds(EVENT_WINLEAVE, NULL, NULL, false, curbuf);
+ if (!win_valid(wp)) {
return;
- /* autocmds may abort script processing */
- if (aborting())
+ }
+ // autocmds may abort script processing
+ if (aborting()) {
return;
+ }
}
// sync undo before leaving the current buffer
- if (undo_sync && curbuf != wp->w_buffer) {
- u_sync(FALSE);
+ if ((flags & WEE_UNDO_SYNC) && curbuf != wp->w_buffer) {
+ u_sync(false);
}
// Might need to scroll the old window before switching, e.g., when the
@@ -4390,16 +4510,17 @@ static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid,
buf_copy_options(wp->w_buffer, BCO_ENTER | BCO_NOHELP);
}
if (!curwin_invalid) {
- prevwin = curwin; /* remember for CTRL-W p */
+ prevwin = curwin; // remember for CTRL-W p
curwin->w_redr_status = TRUE;
}
curwin = wp;
curbuf = wp->w_buffer;
check_cursor();
- if (!virtual_active())
+ if (!virtual_active()) {
curwin->w_cursor.coladd = 0;
- changed_line_abv_curs(); /* assume cursor position needs updating */
+ }
+ changed_line_abv_curs(); // assume cursor position needs updating
// New directory is either the local directory of the window, tab or NULL.
char *new_dir = (char *)(curwin->w_localdir
@@ -4437,10 +4558,10 @@ static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid,
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);
@@ -4474,9 +4595,9 @@ static void win_enter_ext(win_T *wp, bool undo_sync, int curwin_invalid,
win_setwidth((int)p_wiw);
}
- setmouse(); /* in case jumped to/from help buffer */
+ setmouse(); // in case jumped to/from help buffer
- /* Change directories when the 'acd' option is set. */
+ // Change directories when the 'acd' option is set.
do_autochdir();
}
@@ -4505,12 +4626,12 @@ win_T *buf_jump_open_win(buf_T *buf)
/// @return the found window, or NULL.
win_T *buf_jump_open_tab(buf_T *buf)
{
-
// First try the current tab page.
{
win_T *wp = buf_jump_open_win(buf);
- if (wp != NULL)
+ if (wp != NULL) {
return wp;
+ }
}
FOR_ALL_TABS(tp) {
@@ -4538,11 +4659,9 @@ win_T *buf_jump_open_tab(buf_T *buf)
return NULL;
}
-/*
- * Allocate a window structure and link it in the window list when "hidden" is
- * FALSE.
- */
-static win_T *win_alloc(win_T *after, int hidden)
+/// @param hidden allocate a window structure and link it in the window if
+// false.
+static win_T *win_alloc(win_T *after, bool hidden)
{
static int last_win_id = LOWEST_WIN_ID - 1;
@@ -4550,7 +4669,7 @@ static win_T *win_alloc(win_T *after, int hidden)
win_T *new_wp = xcalloc(1, sizeof(win_T));
new_wp->handle = ++last_win_id;
- handle_register_window(new_wp);
+ pmap_put(handle_T)(&window_handles, new_wp->handle, new_wp);
grid_assign_handle(&new_wp->w_grid_alloc);
@@ -4565,13 +4684,14 @@ static win_T *win_alloc(win_T *after, int hidden)
/*
* link the window in the window list
*/
- if (!hidden)
+ if (!hidden) {
win_append(after, new_wp);
+ }
new_wp->w_wincol = 0;
new_wp->w_width = Columns;
- /* position the display and the cursor at the top of the file. */
+ // position the display and the cursor at the top of the file.
new_wp->w_topline = 1;
new_wp->w_topfill = 0;
new_wp->w_botline = 2;
@@ -4585,7 +4705,7 @@ static win_T *win_alloc(win_T *after, int hidden)
new_wp->w_p_so = -1;
new_wp->w_p_siso = -1;
- /* We won't calculate w_fraction until resizing the window */
+ // We won't calculate w_fraction until resizing the window
new_wp->w_fraction = 0;
new_wp->w_prev_fraction_row = -1;
@@ -4598,8 +4718,7 @@ static win_T *win_alloc(win_T *after, int hidden)
// Free one wininfo_T.
-void
-free_wininfo(wininfo_T *wip, buf_T *bp)
+void free_wininfo(wininfo_T *wip, buf_T *bp)
{
if (wip->wi_optset) {
clear_winopt(&wip->wi_opt);
@@ -4609,22 +4728,18 @@ free_wininfo(wininfo_T *wip, buf_T *bp)
}
-/*
- * Remove window 'wp' from the window list and free the structure.
- */
-static void
-win_free (
- win_T *wp,
- tabpage_T *tp /* tab page "win" is in, NULL for current */
-)
+/// Remove window 'wp' from the window list and free the structure.
+///
+/// @param tp tab page "win" is in, NULL for current
+static void win_free(win_T *wp, tabpage_T *tp)
{
int i;
- wininfo_T *wip;
+ wininfo_T *wip;
- handle_unregister_window(wp);
+ pmap_del(handle_T)(&window_handles, wp->handle);
clearFolding(wp);
- /* reduce the reference count to the argument list. */
+ // reduce the reference count to the argument list.
alist_unlink(wp->w_alist);
/* Don't execute autocommands while the window is halfway being deleted.
@@ -4634,7 +4749,7 @@ win_free (
clear_winopt(&wp->w_onebuf_opt);
clear_winopt(&wp->w_allbuf_opt);
- vars_clear(&wp->w_vars->dv_hashtab); /* free all w: variables */
+ vars_clear(&wp->w_vars->dv_hashtab); // free all w: variables
hash_init(&wp->w_vars->dv_hashtab);
unref_var_dict(wp->w_vars);
@@ -4665,8 +4780,10 @@ win_free (
// If there already is an entry with "wi_win" set to NULL it
// must be removed, it would never be used.
+ // Skip "wip" itself, otherwise Coverity complains.
for (wip2 = buf->b_wininfo; wip2 != NULL; wip2 = wip2->wi_next) {
- if (wip2->wi_win == NULL) {
+ // `wip2 != wip` to satisfy Coverity. #14884
+ if (wip2 != wip && wip2->wi_win == NULL) {
if (wip2->wi_next != NULL) {
wip2->wi_next->wi_prev = wip2->wi_prev;
}
@@ -4695,8 +4812,9 @@ win_free (
win_free_grid(wp, false);
- if (wp != aucmd_win)
+ if (wp != aucmd_win) {
win_remove(wp, tp);
+ }
if (autocmd_busy) {
wp->w_next = au_pending_free_win;
au_pending_free_win = wp;
@@ -4725,33 +4843,32 @@ void win_free_grid(win_T *wp, bool reinit)
*/
void win_append(win_T *after, win_T *wp)
{
- win_T *before;
+ win_T *before;
- if (after == NULL) /* after NULL is in front of the first */
+ if (after == NULL) { // after NULL is in front of the first
before = firstwin;
- else
+ } else {
before = after->w_next;
+ }
wp->w_next = before;
wp->w_prev = after;
- if (after == NULL)
+ if (after == NULL) {
firstwin = wp;
- else
+ } else {
after->w_next = wp;
- if (before == NULL)
+ }
+ if (before == NULL) {
lastwin = wp;
- else
+ } else {
before->w_prev = wp;
+ }
}
-/*
- * Remove a window from the window list.
- */
-void
-win_remove (
- win_T *wp,
- tabpage_T *tp /* tab page "win" is in, NULL for current */
-)
+/// Remove a window from the window list.
+///
+/// @param tp tab page "win" is in, NULL for current
+void win_remove(win_T *wp, tabpage_T *tp)
{
if (wp->w_prev != NULL) {
wp->w_prev->w_next = wp->w_next;
@@ -4776,8 +4893,9 @@ static void frame_append(frame_T *after, frame_T *frp)
{
frp->fr_next = after->fr_next;
after->fr_next = frp;
- if (frp->fr_next != NULL)
+ if (frp->fr_next != NULL) {
frp->fr_next->fr_prev = frp;
+ }
frp->fr_prev = after;
}
@@ -4789,10 +4907,11 @@ static void frame_insert(frame_T *before, frame_T *frp)
frp->fr_next = before;
frp->fr_prev = before->fr_prev;
before->fr_prev = frp;
- if (frp->fr_prev != NULL)
+ if (frp->fr_prev != NULL) {
frp->fr_prev->fr_next = frp;
- else
+ } else {
frp->fr_parent->fr_child = frp;
+ }
}
/*
@@ -4804,10 +4923,6 @@ static void frame_remove(frame_T *frp)
frp->fr_prev->fr_next = frp->fr_next;
} else {
frp->fr_parent->fr_child = frp->fr_next;
- // special case: topframe->fr_child == frp
- if (topframe->fr_child == frp) {
- topframe->fr_child = frp->fr_next;
- }
}
if (frp->fr_next != NULL) {
frp->fr_next->fr_prev = frp->fr_prev;
@@ -4823,22 +4938,24 @@ void shell_new_rows(void)
{
int h = (int)ROWS_AVAIL;
- if (firstwin == NULL) /* not initialized yet */
+ if (firstwin == NULL) { // not initialized yet
return;
- if (h < frame_minheight(topframe, NULL))
+ }
+ if (h < frame_minheight(topframe, NULL)) {
h = frame_minheight(topframe, NULL);
+ }
/* First try setting the heights of windows with 'winfixheight'. If
* that doesn't result in the right height, forget about that option. */
- frame_new_height(topframe, h, FALSE, TRUE);
- if (!frame_check_height(topframe, h))
- frame_new_height(topframe, h, FALSE, FALSE);
+ frame_new_height(topframe, h, false, true);
+ if (!frame_check_height(topframe, h)) {
+ frame_new_height(topframe, h, false, false);
+ }
(void)win_comp_pos(); // recompute w_winrow and w_wincol
win_reconfig_floats(); // The size of floats might change
compute_cmdrow();
curtab->tp_ch_used = p_ch;
-
}
/*
@@ -4846,8 +4963,9 @@ void shell_new_rows(void)
*/
void shell_new_columns(void)
{
- if (firstwin == NULL) /* not initialized yet */
+ if (firstwin == NULL) { // not initialized yet
return;
+ }
/* First try setting the widths of windows with 'winfixwidth'. If that
* doesn't result in the right width, forget about that option. */
@@ -4920,7 +5038,7 @@ void win_size_restore(garray_T *gap)
}
}
}
- /* recompute the window positions */
+ // recompute the window positions
(void)win_comp_pos();
}
}
@@ -4962,17 +5080,16 @@ void win_reconfig_floats(void)
*/
static void frame_comp_pos(frame_T *topfrp, int *row, int *col)
{
- win_T *wp;
- frame_T *frp;
+ win_T *wp;
+ frame_T *frp;
int startcol;
int startrow;
wp = topfrp->fr_win;
if (wp != NULL) {
if (wp->w_winrow != *row
- || wp->w_wincol != *col
- ) {
- /* position changed, redraw */
+ || wp->w_wincol != *col) {
+ // position changed, redraw
wp->w_winrow = *row;
wp->w_wincol = *col;
redraw_later(wp, NOT_VALID);
@@ -5043,7 +5160,6 @@ void win_setheight_win(int height, win_T *win)
msg_col = 0;
redraw_all_later(NOT_VALID);
}
-
}
@@ -5062,30 +5178,34 @@ void win_setheight_win(int height, win_T *win)
*/
static void frame_setheight(frame_T *curfrp, int height)
{
- int room; /* total number of lines available */
- int take; /* number of lines taken from other windows */
- int room_cmdline; /* lines available from cmdline */
+ int room; // total number of lines available
+ int take; // number of lines taken from other windows
+ int room_cmdline; // lines available from cmdline
int run;
- frame_T *frp;
+ frame_T *frp;
int h;
int room_reserved;
- /* If the height already is the desired value, nothing to do. */
- if (curfrp->fr_height == height)
+ // If the height already is the desired value, nothing to do.
+ if (curfrp->fr_height == height) {
return;
+ }
if (curfrp->fr_parent == NULL) {
- /* topframe: can only change the command line */
- if (height > ROWS_AVAIL)
+ // topframe: can only change the command line
+ if (height > ROWS_AVAIL) {
height = ROWS_AVAIL;
- if (height > 0)
- frame_new_height(curfrp, height, FALSE, FALSE);
+ }
+ if (height > 0) {
+ frame_new_height(curfrp, height, false, false);
+ }
} else if (curfrp->fr_parent->fr_layout == FR_ROW) {
/* Row of frames: Also need to resize frames left and right of this
* one. First check for the minimal height of these. */
h = frame_minheight(curfrp->fr_parent, NULL);
- if (height < h)
+ if (height < h) {
height = h;
+ }
frame_setheight(curfrp->fr_parent, height);
} else {
/*
@@ -5117,7 +5237,7 @@ static void frame_setheight(frame_T *curfrp, int height)
} else {
win_T *wp = lastwin_nofloating();
room_cmdline = Rows - p_ch
- - (wp->w_winrow + wp->w_height + wp->w_status_height);
+ - (wp->w_winrow + wp->w_height + wp->w_status_height);
if (room_cmdline < 0) {
room_cmdline = 0;
}
@@ -5131,8 +5251,8 @@ static void frame_setheight(frame_T *curfrp, int height)
break;
}
frame_setheight(curfrp->fr_parent, height
- + frame_minheight(curfrp->fr_parent, NOWIN) - (int)p_wmh - 1);
- /*NOTREACHED*/
+ + frame_minheight(curfrp->fr_parent, NOWIN) - (int)p_wmh - 1);
+ //NOTREACHED
}
/*
@@ -5143,17 +5263,20 @@ static void frame_setheight(frame_T *curfrp, int height)
/* If there is not enough room, also reduce the height of a window
* with 'winfixheight' set. */
- if (height > room + room_cmdline - room_reserved)
+ if (height > room + room_cmdline - room_reserved) {
room_reserved = room + room_cmdline - height;
+ }
/* If there is only a 'winfixheight' window and making the
* window smaller, need to make the other window taller. */
- if (take < 0 && room - curfrp->fr_height < room_reserved)
+ if (take < 0 && room - curfrp->fr_height < room_reserved) {
room_reserved = 0;
+ }
if (take > 0 && room_cmdline > 0) {
- /* use lines from cmdline first */
- if (take < room_cmdline)
+ // use lines from cmdline first
+ if (take < room_cmdline) {
room_cmdline = take;
+ }
take -= room_cmdline;
topframe->fr_height += room_cmdline;
}
@@ -5161,7 +5284,7 @@ static void frame_setheight(frame_T *curfrp, int height)
/*
* set the current frame to the new height
*/
- frame_new_height(curfrp, height, FALSE, FALSE);
+ frame_new_height(curfrp, height, false, false);
/*
* First take lines from the frames after the current frame. If
@@ -5169,38 +5292,40 @@ static void frame_setheight(frame_T *curfrp, int height)
* frame.
*/
for (run = 0; run < 2; ++run) {
- if (run == 0)
- frp = curfrp->fr_next; /* 1st run: start with next window */
- else
- frp = curfrp->fr_prev; /* 2nd run: start with prev window */
+ if (run == 0) {
+ frp = curfrp->fr_next; // 1st run: start with next window
+ } else {
+ frp = curfrp->fr_prev; // 2nd run: start with prev window
+ }
while (frp != NULL && take != 0) {
h = frame_minheight(frp, NULL);
if (room_reserved > 0
&& frp->fr_win != NULL
&& frp->fr_win->w_p_wfh) {
- if (room_reserved >= frp->fr_height)
+ if (room_reserved >= frp->fr_height) {
room_reserved -= frp->fr_height;
- else {
- if (frp->fr_height - room_reserved > take)
+ } else {
+ if (frp->fr_height - room_reserved > take) {
room_reserved = frp->fr_height - take;
+ }
take -= frp->fr_height - room_reserved;
- frame_new_height(frp, room_reserved, FALSE, FALSE);
+ frame_new_height(frp, room_reserved, false, false);
room_reserved = 0;
}
} else {
if (frp->fr_height - take < h) {
take -= frp->fr_height - h;
- frame_new_height(frp, h, FALSE, FALSE);
+ frame_new_height(frp, h, false, false);
} else {
- frame_new_height(frp, frp->fr_height - take,
- FALSE, FALSE);
+ frame_new_height(frp, frp->fr_height - take, false, false);
take = 0;
}
}
- if (run == 0)
+ if (run == 0) {
frp = frp->fr_next;
- else
+ } else {
frp = frp->fr_prev;
+ }
}
}
}
@@ -5220,10 +5345,12 @@ void win_setwidth_win(int width, win_T *wp)
/* Always keep current window at least one column wide, even when
* 'winminwidth' is zero. */
if (wp == curwin) {
- if (width < p_wmw)
+ if (width < p_wmw) {
width = p_wmw;
- if (width == 0)
+ }
+ if (width == 0) {
width = 1;
+ }
} else if (width < 0) {
width = 0;
}
@@ -5238,7 +5365,6 @@ void win_setwidth_win(int width, win_T *wp)
(void)win_comp_pos();
redraw_all_later(NOT_VALID);
}
-
}
/*
@@ -5250,27 +5376,30 @@ void win_setwidth_win(int width, win_T *wp)
*/
static void frame_setwidth(frame_T *curfrp, int width)
{
- int room; /* total number of lines available */
- int take; /* number of lines taken from other windows */
+ int room; // total number of lines available
+ int take; // number of lines taken from other windows
int run;
- frame_T *frp;
+ frame_T *frp;
int w;
int room_reserved;
- /* If the width already is the desired value, nothing to do. */
- if (curfrp->fr_width == width)
+ // If the width already is the desired value, nothing to do.
+ if (curfrp->fr_width == width) {
return;
+ }
- if (curfrp->fr_parent == NULL)
- /* topframe: can't change width */
+ if (curfrp->fr_parent == NULL) {
+ // topframe: can't change width
return;
+ }
if (curfrp->fr_parent->fr_layout == FR_COL) {
/* Column of frames: Also need to resize frames above and below of
* this one. First check for the minimal width of these. */
w = frame_minwidth(curfrp->fr_parent, NULL);
- if (width < w)
+ if (width < w) {
width = w;
+ }
frame_setwidth(curfrp->fr_parent, width);
} else {
/*
@@ -5296,14 +5425,15 @@ static void frame_setwidth(frame_T *curfrp, int width)
}
}
- if (width <= room)
+ if (width <= room) {
break;
+ }
if (run == 2 || curfrp->fr_height >= ROWS_AVAIL) {
width = room;
break;
}
frame_setwidth(curfrp->fr_parent, width
- + frame_minwidth(curfrp->fr_parent, NOWIN) - (int)p_wmw - 1);
+ + frame_minwidth(curfrp->fr_parent, NOWIN) - (int)p_wmw - 1);
}
/*
@@ -5314,17 +5444,19 @@ static void frame_setwidth(frame_T *curfrp, int width)
/* If there is not enough room, also reduce the width of a window
* with 'winfixwidth' set. */
- if (width > room - room_reserved)
+ if (width > room - room_reserved) {
room_reserved = room - width;
+ }
/* If there is only a 'winfixwidth' window and making the
* window smaller, need to make the other window narrower. */
- if (take < 0 && room - curfrp->fr_width < room_reserved)
+ if (take < 0 && room - curfrp->fr_width < room_reserved) {
room_reserved = 0;
+ }
/*
* set the current frame to the new width
*/
- frame_new_width(curfrp, width, FALSE, FALSE);
+ frame_new_width(curfrp, width, false, false);
/*
* First take lines from the frames right of the current frame. If
@@ -5332,38 +5464,40 @@ static void frame_setwidth(frame_T *curfrp, int width)
* frame.
*/
for (run = 0; run < 2; ++run) {
- if (run == 0)
- frp = curfrp->fr_next; /* 1st run: start with next window */
- else
- frp = curfrp->fr_prev; /* 2nd run: start with prev window */
+ if (run == 0) {
+ frp = curfrp->fr_next; // 1st run: start with next window
+ } else {
+ frp = curfrp->fr_prev; // 2nd run: start with prev window
+ }
while (frp != NULL && take != 0) {
w = frame_minwidth(frp, NULL);
if (room_reserved > 0
&& frp->fr_win != NULL
&& frp->fr_win->w_p_wfw) {
- if (room_reserved >= frp->fr_width)
+ if (room_reserved >= frp->fr_width) {
room_reserved -= frp->fr_width;
- else {
- if (frp->fr_width - room_reserved > take)
+ } else {
+ if (frp->fr_width - room_reserved > take) {
room_reserved = frp->fr_width - take;
+ }
take -= frp->fr_width - room_reserved;
- frame_new_width(frp, room_reserved, FALSE, FALSE);
+ frame_new_width(frp, room_reserved, false, false);
room_reserved = 0;
}
} else {
if (frp->fr_width - take < w) {
take -= frp->fr_width - w;
- frame_new_width(frp, w, FALSE, FALSE);
+ frame_new_width(frp, w, false, false);
} else {
- frame_new_width(frp, frp->fr_width - take,
- FALSE, FALSE);
+ frame_new_width(frp, frp->fr_width - take, false, false);
take = 0;
}
}
- if (run == 0)
+ if (run == 0) {
frp = frp->fr_next;
- else
+ } else {
frp = frp->fr_prev;
+ }
}
}
}
@@ -5409,69 +5543,71 @@ void win_setminwidth(void)
}
}
-/*
- * Status line of dragwin is dragged "offset" lines down (negative is up).
- */
+/// Status line of dragwin is dragged "offset" lines down (negative is up).
void win_drag_status_line(win_T *dragwin, int offset)
{
- frame_T *curfr;
- frame_T *fr;
+ frame_T *curfr;
+ frame_T *fr;
int room;
int row;
- int up; /* if TRUE, drag status line up, otherwise down */
+ bool up; // if true, drag status line up, otherwise down
int n;
fr = dragwin->w_frame;
curfr = fr;
- if (fr != topframe) { /* more than one window */
+ if (fr != topframe) { // more than one window
fr = fr->fr_parent;
/* When the parent frame is not a column of frames, its parent should
* be. */
if (fr->fr_layout != FR_COL) {
curfr = fr;
- if (fr != topframe) /* only a row of windows, may drag statusline */
+ if (fr != topframe) { // only a row of windows, may drag statusline
fr = fr->fr_parent;
+ }
}
}
/* If this is the last frame in a column, may want to resize the parent
* frame instead (go two up to skip a row of frames). */
while (curfr != topframe && curfr->fr_next == NULL) {
- if (fr != topframe)
+ if (fr != topframe) {
fr = fr->fr_parent;
+ }
curfr = fr;
- if (fr != topframe)
+ if (fr != topframe) {
fr = fr->fr_parent;
+ }
}
- if (offset < 0) { /* drag up */
- up = TRUE;
+ if (offset < 0) { // drag up
+ up = true;
offset = -offset;
- /* sum up the room of the current frame and above it */
+ // sum up the room of the current frame and above it
if (fr == curfr) {
- /* only one window */
+ // only one window
room = fr->fr_height - frame_minheight(fr, NULL);
} else {
room = 0;
for (fr = fr->fr_child;; fr = fr->fr_next) {
room += fr->fr_height - frame_minheight(fr, NULL);
- if (fr == curfr)
+ if (fr == curfr) {
break;
+ }
}
}
- fr = curfr->fr_next; /* put fr at frame that grows */
- } else { /* drag down */
- up = FALSE;
- /*
- * Only dragging the last status line can reduce p_ch.
- */
+ fr = curfr->fr_next; // put fr at frame that grows
+ } else { // drag down
+ up = false;
+ // Only dragging the last status line can reduce p_ch.
room = Rows - cmdline_row;
- if (curfr->fr_next == NULL)
+ if (curfr->fr_next == NULL) {
room -= 1;
- else
+ } else {
room -= p_ch;
- if (room < 0)
+ }
+ if (room < 0) {
room = 0;
+ }
// sum up the room of frames below of the current one
FOR_ALL_FRAMES(fr, curfr->fr_next) {
room += fr->fr_height - frame_minheight(fr, NULL);
@@ -5479,23 +5615,26 @@ void win_drag_status_line(win_T *dragwin, int offset)
fr = curfr; // put fr at window that grows
}
- if (room < offset) /* Not enough room */
- offset = room; /* Move as far as we can */
- if (offset <= 0)
+ if (room < offset) { // Not enough room
+ offset = room; // Move as far as we can
+ }
+ if (offset <= 0) {
return;
+ }
/*
* Grow frame fr by "offset" lines.
* Doesn't happen when dragging the last status line up.
*/
- if (fr != NULL)
- frame_new_height(fr, fr->fr_height + offset, up, FALSE);
-
- if (up)
- fr = curfr; /* current frame gets smaller */
- else
- fr = curfr->fr_next; /* next frame gets smaller */
+ if (fr != NULL) {
+ frame_new_height(fr, fr->fr_height + offset, up, false);
+ }
+ if (up) {
+ fr = curfr; // current frame gets smaller
+ } else {
+ fr = curfr->fr_next; // next frame gets smaller
+ }
/*
* Now make the other frames smaller.
*/
@@ -5503,15 +5642,16 @@ void win_drag_status_line(win_T *dragwin, int offset)
n = frame_minheight(fr, NULL);
if (fr->fr_height - offset <= n) {
offset -= fr->fr_height - n;
- frame_new_height(fr, n, !up, FALSE);
+ frame_new_height(fr, n, !up, false);
} else {
- frame_new_height(fr, fr->fr_height - offset, !up, FALSE);
+ frame_new_height(fr, fr->fr_height - offset, !up, false);
break;
}
- if (up)
+ if (up) {
fr = fr->fr_prev;
- else
+ } else {
fr = fr->fr_next;
+ }
}
row = win_comp_pos();
grid_fill(&default_grid, row, cmdline_row, 0, Columns, ' ', ' ', 0);
@@ -5520,8 +5660,9 @@ void win_drag_status_line(win_T *dragwin, int offset)
}
cmdline_row = row;
p_ch = Rows - cmdline_row;
- if (p_ch < 1)
+ if (p_ch < 1) {
p_ch = 1;
+ }
curtab->tp_ch_used = p_ch;
redraw_all_later(SOME_VALID);
showmode();
@@ -5532,21 +5673,23 @@ void win_drag_status_line(win_T *dragwin, int offset)
*/
void win_drag_vsep_line(win_T *dragwin, int offset)
{
- frame_T *curfr;
- frame_T *fr;
+ frame_T *curfr;
+ frame_T *fr;
int room;
- int left; /* if TRUE, drag separator line left, otherwise right */
+ bool left; // if true, drag separator line left, otherwise right
int n;
fr = dragwin->w_frame;
- if (fr == topframe) /* only one window (cannot happen?) */
+ if (fr == topframe) { // only one window (cannot happen?)
return;
+ }
curfr = fr;
fr = fr->fr_parent;
- /* When the parent frame is not a row of frames, its parent should be. */
+ // When the parent frame is not a row of frames, its parent should be.
if (fr->fr_layout != FR_ROW) {
- if (fr == topframe) /* only a column of windows (cannot happen?) */
+ if (fr == topframe) { // only a column of windows (cannot happen?)
return;
+ }
curfr = fr;
fr = fr->fr_parent;
}
@@ -5554,8 +5697,9 @@ void win_drag_vsep_line(win_T *dragwin, int offset)
/* If this is the last frame in a row, may want to resize a parent
* frame instead. */
while (curfr->fr_next == NULL) {
- if (fr == topframe)
+ if (fr == topframe) {
break;
+ }
curfr = fr;
fr = fr->fr_parent;
if (fr != topframe) {
@@ -5564,20 +5708,21 @@ void win_drag_vsep_line(win_T *dragwin, int offset)
}
}
- if (offset < 0) { /* drag left */
- left = TRUE;
+ if (offset < 0) { // drag left
+ left = true;
offset = -offset;
- /* sum up the room of the current frame and left of it */
+ // sum up the room of the current frame and left of it
room = 0;
for (fr = fr->fr_child;; fr = fr->fr_next) {
room += fr->fr_width - frame_minwidth(fr, NULL);
- if (fr == curfr)
+ if (fr == curfr) {
break;
+ }
}
- fr = curfr->fr_next; /* put fr at frame that grows */
- } else { /* drag right */
- left = FALSE;
- /* sum up the room of frames right of the current one */
+ fr = curfr->fr_next; // put fr at frame that grows
+ } else { // drag right
+ left = false;
+ // sum up the room of frames right of the current one
room = 0;
FOR_ALL_FRAMES(fr, curfr->fr_next) {
room += fr->fr_width - frame_minwidth(fr, NULL);
@@ -5600,28 +5745,29 @@ void win_drag_vsep_line(win_T *dragwin, int offset)
return; // Safety check, should not happen.
}
- /* grow frame fr by offset lines */
- frame_new_width(fr, fr->fr_width + offset, left, FALSE);
-
- /* shrink other frames: current and at the left or at the right */
- if (left)
- fr = curfr; /* current frame gets smaller */
- else
- fr = curfr->fr_next; /* next frame gets smaller */
+ // grow frame fr by offset lines
+ frame_new_width(fr, fr->fr_width + offset, left, false);
+ // shrink other frames: current and at the left or at the right
+ if (left) {
+ fr = curfr; // current frame gets smaller
+ } else {
+ fr = curfr->fr_next; // next frame gets smaller
+ }
while (fr != NULL && offset > 0) {
n = frame_minwidth(fr, NULL);
if (fr->fr_width - offset <= n) {
offset -= fr->fr_width - n;
- frame_new_width(fr, n, !left, FALSE);
+ frame_new_width(fr, n, !left, false);
} else {
- frame_new_width(fr, fr->fr_width - offset, !left, FALSE);
+ frame_new_width(fr, fr->fr_width - offset, !left, false);
break;
}
- if (left)
+ if (left) {
fr = fr->fr_prev;
- else
+ } else {
fr = fr->fr_next;
+ }
}
(void)win_comp_pos();
redraw_all_later(NOT_VALID);
@@ -5639,7 +5785,7 @@ void set_fraction(win_T *wp)
// it's halfway that line. Thus with two lines it is 25%, with three
// lines 17%, etc. Similarly for the last line: 75%, 83%, etc.
wp->w_fraction = ((long)wp->w_wrow * FRACTION_MULT + FRACTION_MULT / 2)
- / (long)wp->w_height_inner;
+ / (long)wp->w_height_inner;
}
}
@@ -5665,9 +5811,9 @@ void win_new_height(win_T *wp, int height)
void scroll_to_fraction(win_T *wp, int prev_height)
{
- linenr_T lnum;
- int sline, line_size;
- int height = wp->w_height_inner;
+ linenr_T lnum;
+ int sline, line_size;
+ int height = wp->w_height_inner;
// Don't change w_topline in any of these cases:
// - window height is 0
@@ -5676,15 +5822,16 @@ void scroll_to_fraction(win_T *wp, int prev_height)
// is visible.
if (height > 0
&& (!wp->w_p_scb || wp == curwin)
- && (height < wp->w_buffer->b_ml.ml_line_count || wp->w_topline > 1)
- ) {
+ && (height < wp->w_buffer->b_ml.ml_line_count ||
+ wp->w_topline > 1)) {
/*
* Find a value for w_topline that shows the cursor at the same
* relative position in the window as before (more or less).
*/
lnum = wp->w_cursor.lnum;
- if (lnum < 1) /* can happen when starting up */
+ if (lnum < 1) { // can happen when starting up
lnum = 1;
+ }
wp->w_wrow = ((long)wp->w_fraction * (long)height - 1L) / FRACTION_MULT;
line_size = plines_win_col(wp, lnum, (long)(wp->w_cursor.col)) - 1;
sline = wp->w_wrow - line_size;
@@ -5720,7 +5867,7 @@ void scroll_to_fraction(win_T *wp, int prev_height)
while (sline > 0 && lnum > 1) {
(void)hasFoldingWin(wp, lnum, &lnum, NULL, true, NULL);
if (lnum == 1) {
- /* first line in buffer is folded */
+ // first line in buffer is folded
line_size = 1;
--sline;
break;
@@ -5859,7 +6006,7 @@ void win_comp_scroll(win_T *wp)
void command_height(void)
{
int h;
- frame_T *frp;
+ frame_T *frp;
int old_p_ch = curtab->tp_ch_used;
/* Use the value of p_ch that we remembered. This is needed for when the
@@ -5873,15 +6020,16 @@ void command_height(void)
frp = frp->fr_parent;
}
- /* Avoid changing the height of a window with 'winfixheight' set. */
+ // Avoid changing the height of a window with 'winfixheight' set.
while (frp->fr_prev != NULL && frp->fr_layout == FR_LEAF
- && frp->fr_win->w_p_wfh)
+ && frp->fr_win->w_p_wfh) {
frp = frp->fr_prev;
+ }
if (starting != NO_SCREEN) {
cmdline_row = Rows - p_ch;
- if (p_ch > old_p_ch) { /* p_ch got bigger */
+ if (p_ch > old_p_ch) { // p_ch got bigger
while (p_ch > old_p_ch) {
if (frp == NULL) {
EMSG(_(e_noroom));
@@ -5891,14 +6039,15 @@ void command_height(void)
break;
}
h = frp->fr_height - frame_minheight(frp, NULL);
- if (h > p_ch - old_p_ch)
+ if (h > p_ch - old_p_ch) {
h = p_ch - old_p_ch;
+ }
old_p_ch += h;
frame_add_height(frp, -h);
frp = frp->fr_prev;
}
- /* Recompute window positions. */
+ // Recompute window positions.
(void)win_comp_pos();
// clear the lines added to cmdline
@@ -5906,19 +6055,21 @@ void command_height(void)
grid_fill(&default_grid, cmdline_row, Rows, 0, Columns, ' ', ' ', 0);
}
msg_row = cmdline_row;
- redraw_cmdline = TRUE;
+ redraw_cmdline = true;
return;
}
- if (msg_row < cmdline_row)
+ if (msg_row < cmdline_row) {
msg_row = cmdline_row;
- redraw_cmdline = TRUE;
+ }
+ redraw_cmdline = true;
}
frame_add_height(frp, (int)(old_p_ch - p_ch));
- /* Recompute window positions. */
- if (frp != lastwin->w_frame)
+ // Recompute window positions.
+ if (frp != lastwin->w_frame) {
(void)win_comp_pos();
+ }
}
/*
@@ -5927,11 +6078,12 @@ void command_height(void)
*/
static void frame_add_height(frame_T *frp, int n)
{
- frame_new_height(frp, frp->fr_height + n, FALSE, FALSE);
+ frame_new_height(frp, frp->fr_height + n, false, false);
for (;; ) {
frp = frp->fr_parent;
- if (frp == NULL)
+ if (frp == NULL) {
break;
+ }
frp->fr_height += n;
}
}
@@ -5946,9 +6098,10 @@ char_u *grab_file_name(long count, linenr_T *file_lnum)
int options = FNAME_MESS | FNAME_EXP | FNAME_REL | FNAME_UNESC;
if (VIsual_active) {
size_t len;
- char_u *ptr;
- if (get_visual_text(NULL, &ptr, &len) == FAIL)
+ char_u *ptr;
+ if (get_visual_text(NULL, &ptr, &len) == FAIL) {
return NULL;
+ }
// Only recognize ":123" here
if (file_lnum != NULL && ptr[len] == ':' && isdigit(ptr[len + 1])) {
char_u *p = ptr + len + 1;
@@ -5968,33 +6121,26 @@ char_u *grab_file_name(long count, linenr_T *file_lnum)
* NULL is returned if the file name or file is not found.
*
* options:
- * FNAME_MESS give error messages
- * FNAME_EXP expand to path
- * FNAME_HYP check for hypertext link
- * FNAME_INCL apply "includeexpr"
+ * FNAME_MESS give error messages
+ * FNAME_EXP expand to path
+ * FNAME_HYP check for hypertext link
+ * FNAME_INCL apply "includeexpr"
*/
char_u *file_name_at_cursor(int options, long count, linenr_T *file_lnum)
{
return file_name_in_line(get_cursor_line_ptr(),
- curwin->w_cursor.col, options, count, curbuf->b_ffname,
- file_lnum);
+ curwin->w_cursor.col, options, count, curbuf->b_ffname,
+ file_lnum);
}
-/*
- * Return the name of the file under or after ptr[col].
- * Otherwise like file_name_at_cursor().
- */
-char_u *
-file_name_in_line (
- char_u *line,
- int col,
- int options,
- long count,
- char_u *rel_fname, /* file we are searching relative to */
- linenr_T *file_lnum /* line number after the file name */
-)
-{
- char_u *ptr;
+/// @param rel_fname file we are searching relative to
+/// @param file_lnum line number after the file name
+///
+/// @return the name of the file under or after ptr[col]. Otherwise like file_name_at_cursor().
+char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u *rel_fname,
+ linenr_T *file_lnum)
+{
+ char_u *ptr;
size_t len;
bool in_type = true;
bool is_url = false;
@@ -6059,8 +6205,9 @@ file_name_in_line (
* But don't remove "..", could be a directory name.
*/
if (len > 2 && vim_strchr((char_u *)".,:;!", ptr[len - 1]) != NULL
- && ptr[len - 2] != '.')
+ && ptr[len - 2] != '.') {
--len;
+ }
if (file_lnum != NULL) {
char_u *p;
@@ -6092,34 +6239,31 @@ file_name_in_line (
return find_file_name_in_path(ptr, len, options, count, rel_fname);
}
-/*
- * Add or remove a status line for the bottom window(s), according to the
- * value of 'laststatus'.
- */
-void
-last_status (
- int morewin /* pretend there are two or more windows */
-)
+/// Add or remove a status line for the bottom window(s), according to the
+/// value of 'laststatus'.
+///
+/// @param morewin pretend there are two or more windows if true.
+void last_status(bool morewin)
{
- /* Don't make a difference between horizontal or vertical split. */
+ // Don't make a difference between horizontal or vertical split.
last_status_rec(topframe, (p_ls == 2
|| (p_ls == 1 && (morewin || !one_window()))));
}
-static void last_status_rec(frame_T *fr, int statusline)
+static void last_status_rec(frame_T *fr, bool statusline)
{
- frame_T *fp;
- win_T *wp;
+ frame_T *fp;
+ win_T *wp;
if (fr->fr_layout == FR_LEAF) {
wp = fr->fr_win;
if (wp->w_status_height != 0 && !statusline) {
- /* remove status line */
+ // remove status line
win_new_height(wp, wp->w_height + 1);
wp->w_status_height = 0;
comp_col();
} else if (wp->w_status_height == 0 && statusline) {
- /* Find a frame to take a line from. */
+ // Find a frame to take a line from.
fp = fr;
while (fp->fr_height <= frame_minheight(fp, NULL)) {
if (fp == topframe) {
@@ -6128,18 +6272,20 @@ static void last_status_rec(frame_T *fr, int statusline)
}
/* In a column of frames: go to frame above. If already at
* the top or in a row of frames: go to parent. */
- if (fp->fr_parent->fr_layout == FR_COL && fp->fr_prev != NULL)
+ if (fp->fr_parent->fr_layout == FR_COL && fp->fr_prev != NULL) {
fp = fp->fr_prev;
- else
+ } else {
fp = fp->fr_parent;
+ }
}
wp->w_status_height = 1;
if (fp != fr) {
- frame_new_height(fp, fp->fr_height - 1, FALSE, FALSE);
+ frame_new_height(fp, fp->fr_height - 1, false, false);
frame_fix_height(wp);
(void)win_comp_pos();
- } else
+ } else {
win_new_height(wp, wp->w_height - 1);
+ }
comp_col();
redraw_all_later(SOME_VALID);
}
@@ -6149,9 +6295,10 @@ static void last_status_rec(frame_T *fr, int statusline)
last_status_rec(fp, statusline);
}
} else {
- /* horizontally split window, set status line for last one */
- for (fp = fr->fr_child; fp->fr_next != NULL; fp = fp->fr_next)
+ // horizontally split window, set status line for last one
+ for (fp = fr->fr_child; fp->fr_next != NULL; fp = fp->fr_next) {
;
+ }
last_status_rec(fp, statusline);
}
}
@@ -6166,8 +6313,10 @@ int tabline_height(void)
}
assert(first_tabpage);
switch (p_stal) {
- case 0: return 0;
- case 1: return (first_tabpage->tp_next == NULL) ? 0 : 1;
+ case 0:
+ return 0;
+ case 1:
+ return (first_tabpage->tp_next == NULL) ? 0 : 1;
}
return 1;
}
@@ -6178,8 +6327,9 @@ int tabline_height(void)
*/
int min_rows(void)
{
- if (firstwin == NULL) /* not initialized yet */
+ if (firstwin == NULL) { // not initialized yet
return MIN_LINES;
+ }
int total = 0;
FOR_ALL_TABS(tp) {
@@ -6189,7 +6339,7 @@ int min_rows(void)
}
}
total += tabline_height();
- total += 1; /* count the room for the command line */
+ total += 1; // count the room for the command line
return total;
}
@@ -6214,12 +6364,11 @@ bool only_one_window(void) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
return count <= 1;
}
-/*
- * Correct the cursor line number in other windows. Used after changing the
- * current buffer, and before applying autocommands.
- * When "do_curwin" is TRUE, also check current window.
- */
-void check_lnums(int do_curwin)
+/// Correct the cursor line number in other windows. Used after changing the
+/// current buffer, and before applying autocommands.
+///
+/// @param do_curwin when true, also check current window.
+void check_lnums(bool do_curwin)
{
FOR_ALL_TAB_WINDOWS(tp, wp) {
if ((do_curwin || wp != curwin) && wp->w_buffer == curbuf) {
@@ -6285,12 +6434,15 @@ static void make_snapshot_rec(frame_T *fr, frame_T **frp)
(*frp)->fr_layout = fr->fr_layout;
(*frp)->fr_width = fr->fr_width;
(*frp)->fr_height = fr->fr_height;
- if (fr->fr_next != NULL)
+ if (fr->fr_next != NULL) {
make_snapshot_rec(fr->fr_next, &((*frp)->fr_next));
- if (fr->fr_child != NULL)
+ }
+ if (fr->fr_child != NULL) {
make_snapshot_rec(fr->fr_child, &((*frp)->fr_child));
- if (fr->fr_layout == FR_LEAF && fr->fr_win == curwin)
+ }
+ if (fr->fr_layout == FR_LEAF && fr->fr_win == curwin) {
(*frp)->fr_win = curwin;
+ }
}
/*
@@ -6311,18 +6463,14 @@ static void clear_snapshot_rec(frame_T *fr)
}
}
-/*
- * Restore a previously created snapshot, if there is any.
- * This is only done if the screen size didn't change and the window layout is
- * still the same.
- */
-void
-restore_snapshot (
- int idx,
- int close_curwin /* closing current window */
-)
+/// Restore a previously created snapshot, if there is any.
+/// This is only done if the screen size didn't change and the window layout is
+/// still the same.
+///
+/// @param close_curwin closing current window
+void restore_snapshot(int idx, int close_curwin)
{
- win_T *wp;
+ win_T *wp;
if (curtab->tp_snapshot[idx] != NULL
&& curtab->tp_snapshot[idx]->fr_width == topframe->fr_width
@@ -6349,8 +6497,9 @@ static int check_snapshot_rec(frame_T *sn, frame_T *fr)
&& check_snapshot_rec(sn->fr_next, fr->fr_next) == FAIL)
|| (sn->fr_child != NULL
&& check_snapshot_rec(sn->fr_child, fr->fr_child) == FAIL)
- || (sn->fr_win != NULL && !win_valid(sn->fr_win)))
+ || (sn->fr_win != NULL && !win_valid(sn->fr_win))) {
return FAIL;
+ }
return OK;
}
@@ -6361,25 +6510,27 @@ static int check_snapshot_rec(frame_T *sn, frame_T *fr)
*/
static win_T *restore_snapshot_rec(frame_T *sn, frame_T *fr)
{
- win_T *wp = NULL;
- win_T *wp2;
+ win_T *wp = NULL;
+ win_T *wp2;
fr->fr_height = sn->fr_height;
fr->fr_width = sn->fr_width;
if (fr->fr_layout == FR_LEAF) {
- frame_new_height(fr, fr->fr_height, FALSE, FALSE);
- frame_new_width(fr, fr->fr_width, FALSE, FALSE);
+ frame_new_height(fr, fr->fr_height, false, false);
+ frame_new_width(fr, fr->fr_width, false, false);
wp = sn->fr_win;
}
if (sn->fr_next != NULL) {
wp2 = restore_snapshot_rec(sn->fr_next, fr->fr_next);
- if (wp2 != NULL)
+ if (wp2 != NULL) {
wp = wp2;
+ }
}
if (sn->fr_child != NULL) {
wp2 = restore_snapshot_rec(sn->fr_child, fr->fr_child);
- if (wp2 != NULL)
+ if (wp2 != NULL) {
wp = wp2;
+ }
}
return wp;
}
@@ -6406,23 +6557,24 @@ static win_T *get_snapshot_focus(int idx)
return win_valid(sn->fr_win) ? sn->fr_win : NULL;
}
-/*
- * Set "win" to be the curwin and "tp" to be the current tab page.
- * restore_win() MUST be called to undo, also when FAIL is returned.
- * No autocommands will be executed until restore_win() is called.
- * When "no_display" is TRUE the display won't be affected, no redraw is
- * triggered, another tabpage access is limited.
- * Returns FAIL if switching to "win" failed.
- */
-int switch_win(win_T **save_curwin, tabpage_T **save_curtab, win_T *win, tabpage_T *tp, int no_display)
+/// Set "win" to be the curwin and "tp" to be the current tab page.
+/// restore_win() MUST be called to undo, also when FAIL is returned.
+/// No autocommands will be executed until restore_win() is called.
+///
+/// @param no_display if true the display won't be affected, no redraw is
+/// triggered, another tabpage access is limited.
+///
+/// @return FAIL if switching to "win" failed.
+int switch_win(win_T **save_curwin, tabpage_T **save_curtab, win_T *win, tabpage_T *tp,
+ bool no_display)
{
block_autocmds();
return switch_win_noblock(save_curwin, save_curtab, win, tp, no_display);
}
// As switch_win() but without blocking autocommands.
-int switch_win_noblock(win_T **save_curwin, tabpage_T **save_curtab,
- win_T *win, tabpage_T *tp, int no_display)
+int switch_win_noblock(win_T **save_curwin, tabpage_T **save_curtab, win_T *win, tabpage_T *tp,
+ bool no_display)
{
*save_curwin = curwin;
if (tp != NULL) {
@@ -6433,8 +6585,9 @@ int switch_win_noblock(win_T **save_curwin, tabpage_T **save_curtab,
curtab = tp;
firstwin = curtab->tp_firstwin;
lastwin = curtab->tp_lastwin;
- } else
- goto_tabpage_tp(tp, FALSE, FALSE);
+ } else {
+ goto_tabpage_tp(tp, false, false);
+ }
}
if (!win_valid(win)) {
return FAIL;
@@ -6454,8 +6607,7 @@ void restore_win(win_T *save_curwin, tabpage_T *save_curtab, bool no_display)
}
// As restore_win() but without unblocking autocommands.
-void restore_win_noblock(win_T *save_curwin, tabpage_T *save_curtab,
- bool no_display)
+void restore_win_noblock(win_T *save_curwin, tabpage_T *save_curtab, bool no_display)
{
if (save_curtab != NULL && valid_tabpage(save_curtab)) {
if (no_display) {
@@ -6464,8 +6616,9 @@ void restore_win_noblock(win_T *save_curwin, tabpage_T *save_curtab,
curtab = save_curtab;
firstwin = curtab->tp_firstwin;
lastwin = curtab->tp_lastwin;
- } else
- goto_tabpage_tp(save_curtab, FALSE, FALSE);
+ } else {
+ goto_tabpage_tp(save_curtab, false, false);
+ }
}
if (win_valid(save_curwin)) {
curwin = save_curwin;
@@ -6510,16 +6663,15 @@ void restore_buffer(bufref_T *save_curbuf)
/// particular ID is desired
/// @param[in] conceal_char pointer to conceal replacement char
/// @return ID of added match, -1 on failure.
-int match_add(win_T *wp, const char *const grp, const char *const pat,
- int prio, int id, list_T *pos_list,
- const char *const conceal_char)
+int match_add(win_T *wp, const char *const grp, const char *const pat, int prio, int id,
+ list_T *pos_list, const char *const conceal_char)
FUNC_ATTR_NONNULL_ARG(1, 2)
{
matchitem_T *cur;
matchitem_T *prev;
matchitem_T *m;
int hlg_id;
- regprog_T *regprog = NULL;
+ regprog_T *regprog = NULL;
int rtype = SOME_VALID;
if (*grp == NUL || (pat != NULL && *pat == NUL)) {
@@ -6541,8 +6693,7 @@ int match_add(win_T *wp, const char *const grp, const char *const pat,
cur = cur->next;
}
}
- if ((hlg_id = syn_name2id((const char_u *)grp)) == 0) {
- EMSG2(_(e_nogroup), grp);
+ if ((hlg_id = syn_check_group((const char_u *)grp, strlen(grp))) == 0) {
return -1;
}
if (pat != NULL && (regprog = vim_regcomp((char_u *)pat, RE_MAGIC)) == NULL) {
@@ -6553,10 +6704,12 @@ int match_add(win_T *wp, const char *const grp, const char *const pat,
// Find available match ID.
while (id == -1) {
cur = wp->w_match_head;
- while (cur != NULL && cur->id != wp->w_next_match_id)
+ while (cur != NULL && cur->id != wp->w_next_match_id) {
cur = cur->next;
- if (cur == NULL)
+ }
+ if (cur == NULL) {
id = wp->w_next_match_id;
+ }
wp->w_next_match_id++;
}
@@ -6648,8 +6801,8 @@ int match_add(win_T *wp, const char *const grp, const char *const pat,
}
});
- // Calculate top and bottom lines for redrawing area
- if (toplnum != 0){
+ // Calculate top and bottom lines for redrawing area
+ if (toplnum != 0) {
if (wp->w_buffer->b_mod_set) {
if (wp->w_buffer->b_mod_top > toplnum) {
wp->w_buffer->b_mod_top = toplnum;
@@ -6677,10 +6830,11 @@ int match_add(win_T *wp, const char *const grp, const char *const pat,
prev = cur;
cur = cur->next;
}
- if (cur == prev)
+ if (cur == prev) {
wp->w_match_head = m;
- else
+ } else {
prev->next = m;
+ }
m->next = cur;
redraw_later(wp, rtype);
@@ -6693,8 +6847,9 @@ fail:
/// Delete match with ID 'id' in the match list of window 'wp'.
-/// Print error messages if 'perr' is TRUE.
-int match_delete(win_T *wp, int id, int perr)
+///
+/// @param perr print error messages if true.
+int match_delete(win_T *wp, int id, bool perr)
{
matchitem_T *cur = wp->w_match_head;
matchitem_T *prev = cur;
@@ -6718,10 +6873,11 @@ int match_delete(win_T *wp, int id, int perr)
}
return -1;
}
- if (cur == prev)
+ if (cur == prev) {
wp->w_match_head = cur->next;
- else
+ } else {
prev->next = cur->next;
+ }
vim_regfree(cur->match.regprog);
xfree(cur->pattern);
if (cur->pos.toplnum != 0) {
@@ -6770,8 +6926,9 @@ matchitem_T *get_match(win_T *wp, int id)
{
matchitem_T *cur = wp->w_match_head;
- while (cur != NULL && cur->id != id)
+ while (cur != NULL && cur->id != id) {
cur = cur->next;
+ }
return cur;
}
@@ -6901,13 +7058,13 @@ void win_id2tabwin(typval_T *const argvars, typval_T *const rettv)
tv_list_append_number(list, winnr);
}
-win_T * win_id2wp(typval_T *argvars)
+win_T *win_id2wp(typval_T *argvars)
{
return win_id2wp_tp(argvars, NULL);
}
// Return the window and tab pointer of window "id".
-win_T * win_id2wp_tp(typval_T *argvars, tabpage_T **tpp)
+win_T *win_id2wp_tp(typval_T *argvars, tabpage_T **tpp)
{
int id = tv_get_number(&argvars[0]);