aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/window.c
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2022-08-03 00:08:17 -0600
committerJosh Rahm <joshuarahm@gmail.com>2022-08-03 00:08:17 -0600
commit9449e1b8d273ff78eb894c588110ffa0c17d6ee3 (patch)
tree9e4470c33bd4187d9f42f0b2c4aaa995310c5be8 /src/nvim/window.c
parent308e1940dcd64aa6c344c403d4f9e0dda58d9c5c (diff)
parentb8dcbcc732baf84fc48d6b272c3ade0bcb129b3b (diff)
downloadrneovim-9449e1b8d273ff78eb894c588110ffa0c17d6ee3.tar.gz
rneovim-9449e1b8d273ff78eb894c588110ffa0c17d6ee3.tar.bz2
rneovim-9449e1b8d273ff78eb894c588110ffa0c17d6ee3.zip
Merge remote-tracking branch 'upstream/master' into rahm
Diffstat (limited to 'src/nvim/window.c')
-rw-r--r--src/nvim/window.c340
1 files changed, 188 insertions, 152 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 2bffe2055f..abb277bd23 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -13,6 +13,7 @@
#include "nvim/diff.h"
#include "nvim/edit.h"
#include "nvim/eval.h"
+#include "nvim/eval/vars.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
@@ -171,7 +172,7 @@ void do_window(int nchar, long Prenum, int xchar)
CHECK_CMDWIN;
reset_VIsual_and_resel(); // stop Visual mode
- if (buflist_findnr(Prenum == 0 ? curwin->w_alt_fnum : Prenum) == NULL) {
+ if (buflist_findnr(Prenum == 0 ? curwin->w_alt_fnum : (int)Prenum) == NULL) {
if (Prenum == 0) {
emsg(_(e_noalt));
} else {
@@ -181,7 +182,7 @@ void do_window(int nchar, long Prenum, int xchar)
}
if (!curbuf_locked() && win_split(0, 0) == OK) {
- (void)buflist_getfile(Prenum == 0 ? curwin->w_alt_fnum : Prenum,
+ (void)buflist_getfile(Prenum == 0 ? curwin->w_alt_fnum : (int)Prenum,
(linenr_T)0, GETF_ALT, false);
}
break;
@@ -451,9 +452,9 @@ newwindow:
case '}':
CHECK_CMDWIN;
if (Prenum) {
- g_do_tagpreview = Prenum;
+ g_do_tagpreview = (int)Prenum;
} else {
- g_do_tagpreview = p_pvh;
+ g_do_tagpreview = (int)p_pvh;
}
FALLTHROUGH;
case ']':
@@ -461,7 +462,7 @@ newwindow:
CHECK_CMDWIN;
// Keep visual mode, can select words to use as a tag.
if (Prenum) {
- postponed_split = Prenum;
+ postponed_split = (int)Prenum;
} else {
postponed_split = -1;
}
@@ -550,16 +551,16 @@ wingotofile:
case '}':
xchar = Ctrl_RSB;
if (Prenum) {
- g_do_tagpreview = Prenum;
+ g_do_tagpreview = (int)Prenum;
} else {
- g_do_tagpreview = p_pvh;
+ g_do_tagpreview = (int)p_pvh;
}
FALLTHROUGH;
case ']':
case Ctrl_RSB:
// Keep visual mode, can select words to use as a tag.
if (Prenum) {
- postponed_split = Prenum;
+ postponed_split = (int)Prenum;
} else {
postponed_split = -1;
}
@@ -725,31 +726,31 @@ void win_set_minimal_style(win_T *wp)
wp->w_p_fcs = ((*old == NUL)
? (char_u *)xstrdup("eob: ")
: concat_str(old, (char_u *)",eob: "));
- xfree(old);
+ free_string_option(old);
}
if (wp->w_hl_ids[HLF_EOB] != -1) {
char_u *old = wp->w_p_winhl;
wp->w_p_winhl = ((*old == NUL)
? (char_u *)xstrdup("EndOfBuffer:")
: concat_str(old, (char_u *)",EndOfBuffer:"));
- xfree(old);
+ free_string_option(old);
}
// signcolumn: use 'auto'
if (wp->w_p_scl[0] != 'a' || STRLEN(wp->w_p_scl) >= 8) {
- xfree(wp->w_p_scl);
+ free_string_option(wp->w_p_scl);
wp->w_p_scl = (char_u *)xstrdup("auto");
}
// foldcolumn: use '0'
if (wp->w_p_fdc[0] != '0') {
- xfree(wp->w_p_fdc);
+ free_string_option(wp->w_p_fdc);
wp->w_p_fdc = (char_u *)xstrdup("0");
}
// colorcolumn: cleared
if (wp->w_p_cc != NULL && *wp->w_p_cc != NUL) {
- xfree(wp->w_p_cc);
+ free_string_option(wp->w_p_cc);
wp->w_p_cc = (char_u *)xstrdup("");
}
}
@@ -799,8 +800,8 @@ void win_config_float(win_T *wp, FloatConfig fconfig)
// compute initial position
if (wp->w_float_config.relative == kFloatRelativeWindow) {
- int row = wp->w_float_config.row;
- int col = wp->w_float_config.col;
+ int row = (int)wp->w_float_config.row;
+ int col = (int)wp->w_float_config.col;
Error dummy = ERROR_INIT;
win_T *parent = find_window_by_handle(wp->w_float_config.window, &dummy);
if (parent) {
@@ -824,8 +825,8 @@ void win_config_float(win_T *wp, FloatConfig fconfig)
wp->w_winrow = row;
wp->w_wincol = col;
} else {
- wp->w_winrow = fconfig.row;
- wp->w_wincol = fconfig.col;
+ wp->w_winrow = (int)fconfig.row;
+ wp->w_wincol = (int)fconfig.col;
}
// changing border style while keeping border only requires redrawing border
@@ -1064,10 +1065,10 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
* width.
*/
// Current window requires at least 1 space.
- wmw1 = (p_wmw == 0 ? 1 : p_wmw);
+ wmw1 = (p_wmw == 0 ? 1 : (int)p_wmw);
needed = wmw1 + 1;
if (flags & WSP_ROOM) {
- needed += p_wiw - wmw1;
+ needed += (int)p_wiw - wmw1;
}
if (flags & (WSP_BOT | WSP_TOP)) {
minwidth = frame_minwidth(topframe, NOWIN);
@@ -1141,10 +1142,10 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
// Check if we are able to split the current window and compute its height.
// Current window requires at least 1 space plus space for the window bar.
- wmh1 = MAX(p_wmh, 1) + oldwin->w_winbar_height;
+ wmh1 = MAX((int)p_wmh, 1) + oldwin->w_winbar_height;
needed = wmh1 + STATUS_HEIGHT;
if (flags & WSP_ROOM) {
- needed += p_wh - wmh1 + oldwin->w_winbar_height;
+ needed += (int)p_wh - wmh1 + oldwin->w_winbar_height;
}
if (p_ch < 1) {
needed += 1; // Adjust for cmdheight=0.
@@ -1304,7 +1305,7 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
// 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;
+ curfrp->fr_layout = (char)layout;
frp->fr_parent = curfrp;
frp->fr_next = NULL;
frp->fr_prev = NULL;
@@ -1489,20 +1490,17 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir)
// Don't change the window height/width to 'winheight' / 'winwidth' if a
// size was given.
if (flags & WSP_VERT) {
- i = p_wiw;
+ i = (int)p_wiw;
if (size != 0) {
p_wiw = size;
}
} else {
- i = p_wh;
+ i = (int)p_wh;
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, WEE_TRIGGER_NEW_AUTOCMDS | WEE_TRIGGER_ENTER_AUTOCMDS
| WEE_TRIGGER_LEAVE_AUTOCMDS);
@@ -1573,6 +1571,10 @@ static void win_init(win_T *newp, win_T *oldp, int flags)
}
newp->w_tagstackidx = oldp->w_tagstackidx;
newp->w_tagstacklen = oldp->w_tagstacklen;
+
+ // Keep same changelist position in new window.
+ newp->w_changelistidx = oldp->w_changelistidx;
+
copyFoldingState(oldp, newp);
win_init_some(newp, oldp);
@@ -1687,14 +1689,14 @@ int make_windows(int count, bool vertical)
if (vertical) {
// Each window needs at least 'winminwidth' lines and a separator column.
- maxcount = (curwin->w_width + curwin->w_vsep_width
- - (p_wiw - p_wmw)) / (p_wmw + 1);
+ maxcount = (int)(curwin->w_width + curwin->w_vsep_width
+ - (p_wiw - p_wmw)) / ((int)p_wmw + 1);
} else {
// Each window needs at least 'winminheight' lines.
// If statusline isn't global, each window also needs a statusline.
// If 'winbar' is set, each window also needs a winbar.
- maxcount = (curwin->w_height + curwin->w_hsep_height + curwin->w_status_height
- - (p_wh - p_wmh)) / (p_wmh + STATUS_HEIGHT + global_winbar_height());
+ maxcount = (int)(curwin->w_height + curwin->w_hsep_height + curwin->w_status_height
+ - (p_wh - p_wmh)) / ((int)p_wmh + STATUS_HEIGHT + global_winbar_height());
}
if (maxcount < 2) {
@@ -2037,10 +2039,10 @@ void win_move_after(win_T *win1, win_T *win2)
static int get_maximum_wincount(frame_T *fr, int height)
{
if (fr->fr_layout != FR_COL) {
- return (height / (p_wmh + STATUS_HEIGHT + frame2win(fr)->w_winbar_height));
+ return (height / ((int)p_wmh + STATUS_HEIGHT + frame2win(fr)->w_winbar_height));
} else if (global_winbar_height()) {
// If winbar is globally enabled, no need to check each window for it.
- return (height / (p_wmh + STATUS_HEIGHT + 1));
+ return (height / ((int)p_wmh + STATUS_HEIGHT + 1));
}
frame_T *frp;
@@ -2053,13 +2055,13 @@ static int get_maximum_wincount(frame_T *fr, int height)
if (height < (p_wmh + STATUS_HEIGHT + wp->w_winbar_height)) {
break;
}
- height -= p_wmh + STATUS_HEIGHT + wp->w_winbar_height;
+ height -= (int)p_wmh + STATUS_HEIGHT + wp->w_winbar_height;
total_wincount += 1;
}
// If we still have enough room for more windows, just use the default winbar height (which is 0)
// in order to get the amount of windows that'd fit in the remaining space
- total_wincount += height / (p_wmh + STATUS_HEIGHT);
+ total_wincount += height / ((int)p_wmh + STATUS_HEIGHT);
return total_wincount;
}
@@ -2132,7 +2134,7 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int
} else {
extra_sep = 0;
}
- totwincount = (n + extra_sep) / (p_wmw + 1);
+ totwincount = (n + extra_sep) / ((int)p_wmw + 1);
has_next_curwin = frame_has_win(topfr, next_curwin);
/*
@@ -2143,29 +2145,27 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int
m = frame_minwidth(topfr, next_curwin);
room = width - m;
if (room < 0) {
- next_curwin_size = p_wiw + room;
+ next_curwin_size = (int)p_wiw + room;
room = 0;
} else {
next_curwin_size = -1;
FOR_ALL_FRAMES(fr, topfr->fr_child) {
- // If 'winfixwidth' set keep the window width if
- // possible.
- // Watch out for this window being the next_curwin.
if (!frame_fixed_width(fr)) {
continue;
}
+ // If 'winfixwidth' set keep the window width if possible.
+ // Watch out for this window being the next_curwin.
n = frame_minwidth(fr, NOWIN);
new_size = fr->fr_width;
if (frame_has_win(fr, next_curwin)) {
- room += p_wiw - p_wmw;
+ room += (int)p_wiw - (int)p_wmw;
next_curwin_size = 0;
if (new_size < p_wiw) {
- new_size = p_wiw;
+ new_size = (int)p_wiw;
}
} else {
// These windows don't use up room.
- totwincount -= (n + (fr->fr_next == NULL
- ? extra_sep : 0)) / (p_wmw + 1);
+ totwincount -= (n + (fr->fr_next == NULL ? extra_sep : 0)) / ((int)p_wmw + 1);
}
room -= new_size - n;
if (room < 0) {
@@ -2182,12 +2182,12 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int
/ (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;
+ next_curwin_size = (int)(room + p_wiw
+ + (totwincount - 1) * p_wmw
+ + (totwincount - 1)) / totwincount;
+ room -= next_curwin_size - (int)p_wiw;
} else {
- next_curwin_size = p_wiw;
+ next_curwin_size = (int)p_wiw;
}
}
}
@@ -2210,8 +2210,7 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int
} else {
// 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);
+ wincount = (n + (fr->fr_next == NULL ? extra_sep : 0)) / ((int)p_wmw + 1);
m = frame_minwidth(fr, next_curwin);
if (has_next_curwin) {
hnc = frame_has_win(fr, next_curwin);
@@ -2227,7 +2226,7 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int
new_size = (wincount * room + (totwincount / 2)) / totwincount;
}
if (hnc) { // add next_curwin size
- next_curwin_size -= p_wiw - (m - n);
+ next_curwin_size -= (int)p_wiw - (m - n);
new_size += next_curwin_size;
room -= new_size - next_curwin_size;
} else {
@@ -2276,24 +2275,23 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int
if (room < 0) {
// The room is less than 'winheight', use all space for the
// current window.
- next_curwin_size = p_wh + room;
+ next_curwin_size = (int)p_wh + room;
room = 0;
} else {
next_curwin_size = -1;
FOR_ALL_FRAMES(fr, topfr->fr_child) {
- // If 'winfixheight' set keep the window height if
- // possible.
- // Watch out for this window being the next_curwin.
if (!frame_fixed_height(fr)) {
continue;
}
+ // If 'winfixheight' set keep the window height if possible.
+ // Watch out for this window being the next_curwin.
n = frame_minheight(fr, NOWIN);
new_size = fr->fr_height;
if (frame_has_win(fr, next_curwin)) {
- room += p_wh - p_wmh;
+ room += (int)p_wh - (int)p_wmh;
next_curwin_size = 0;
if (new_size < p_wh) {
- new_size = p_wh;
+ new_size = (int)p_wh;
}
} else {
// These windows don't use up room.
@@ -2314,12 +2312,12 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int
/ (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;
+ next_curwin_size = (int)(room + p_wh
+ + (totwincount - 1) * p_wmh
+ + (totwincount - 1)) / totwincount;
+ room -= next_curwin_size - (int)p_wh;
} else {
- next_curwin_size = p_wh;
+ next_curwin_size = (int)p_wh;
}
}
}
@@ -2358,7 +2356,7 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int
new_size = (wincount * room + (totwincount / 2)) / totwincount;
}
if (hnc) { // add next_curwin size
- next_curwin_size -= p_wh - (m - n);
+ next_curwin_size -= (int)p_wh - (m - n);
new_size += next_curwin_size;
room -= new_size - next_curwin_size;
} else {
@@ -3778,9 +3776,9 @@ static int frame_minheight(frame_T *topfrp, win_T *next_curwin)
+ topfrp->fr_win->w_status_height;
if (topfrp->fr_win == next_curwin) {
- m = p_wh + extra_height;
+ m = (int)p_wh + extra_height;
} else {
- m = p_wmh + extra_height;
+ m = (int)p_wmh + extra_height;
if (topfrp->fr_win == curwin && next_curwin == NULL) {
// Current window is minimal one line high.
if (p_wmh == 0) {
@@ -3821,10 +3819,10 @@ static int frame_minwidth(frame_T *topfrp, win_T *next_curwin)
if (topfrp->fr_win != NULL) {
if (topfrp->fr_win == next_curwin) {
- m = p_wiw + topfrp->fr_win->w_vsep_width;
+ m = (int)p_wiw + topfrp->fr_win->w_vsep_width;
} else {
// window: minimal width of the window plus separator column
- m = p_wmw + topfrp->fr_win->w_vsep_width;
+ m = (int)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) {
++m;
@@ -3903,9 +3901,7 @@ void close_others(int message, int forceit)
continue;
}
}
- win_close(wp,
- !buf_hide(wp->w_buffer) && !bufIsChanged(wp->w_buffer),
- false);
+ win_close(wp, !buf_hide(wp->w_buffer) && !bufIsChanged(wp->w_buffer), false);
}
if (message && !ONE_WINDOW) {
@@ -3981,7 +3977,7 @@ static int win_alloc_firstwin(win_T *oldwin)
new_frame(curwin);
topframe = curwin->w_frame;
topframe->fr_width = Columns;
- topframe->fr_height = Rows - p_ch - global_stl_height();
+ topframe->fr_height = Rows - (int)p_ch - global_stl_height();
return OK;
}
@@ -4003,11 +3999,11 @@ static void new_frame(win_T *wp)
*/
void win_init_size(void)
{
- firstwin->w_height = ROWS_AVAIL;
+ firstwin->w_height = (int)ROWS_AVAIL;
firstwin->w_height_inner = firstwin->w_height - firstwin->w_winbar_height;
firstwin->w_height_outer = firstwin->w_height;
firstwin->w_winrow_off = firstwin->w_winbar_height;
- topframe->fr_height = ROWS_AVAIL;
+ topframe->fr_height = (int)ROWS_AVAIL;
firstwin->w_width = Columns;
firstwin->w_width_inner = firstwin->w_width;
firstwin->w_width_outer = firstwin->w_width;
@@ -4116,7 +4112,6 @@ int win_new_tabpage(int after, char_u *filename)
newtp->tp_topframe = topframe;
last_status(false);
- set_winbar();
redraw_all_later(NOT_VALID);
@@ -4167,7 +4162,7 @@ int make_tabpages(int maxcount)
// Limit to 'tabpagemax' tabs.
if (count > p_tpm) {
- count = p_tpm;
+ count = (int)p_tpm;
}
/*
@@ -4303,7 +4298,7 @@ static int leave_tabpage(buf_T *new_curbuf, bool trigger_leave_autocmds)
tp->tp_prevwin = prevwin;
tp->tp_firstwin = firstwin;
tp->tp_lastwin = lastwin;
- tp->tp_old_Rows = Rows;
+ tp->tp_old_Rows_avail = ROWS_AVAIL;
tp->tp_old_Columns = Columns;
firstwin = NULL;
lastwin = NULL;
@@ -4343,10 +4338,7 @@ static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, bool trigger_enter_a
const int row = win_comp_pos(); // recompute w_winrow for all windows
diff_need_scrollbind = true;
- // The tabpage line may have appeared or disappeared, may need to resize
- // the frames for that. When the Vim window was resized need to update
- // frame sizes too. Use the stored value of p_ch, so that it can be
- // different for each tab page.
+ // Use the stored value of p_ch, so that it can be different for each tab page.
if (p_ch != curtab->tp_ch_used) {
clear_cmdline = true;
}
@@ -4359,7 +4351,9 @@ static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, bool trigger_enter_a
clear_cmdline = true;
}
- if (curtab->tp_old_Rows != Rows || (old_off != firstwin->w_winrow)) {
+ // The tabpage line may have appeared or disappeared, may need to resize the frames for that.
+ // When the Vim window was resized or ROWS_AVAIL changed need to update frame sizes too.
+ if (curtab->tp_old_Rows_avail != ROWS_AVAIL || (old_off != firstwin->w_winrow)) {
win_new_screen_rows();
}
if (curtab->tp_old_Columns != Columns && starting == 0) {
@@ -5118,10 +5112,10 @@ static void win_free(win_T *wp, tabpage_T *tp)
xfree(wp->w_localdir);
xfree(wp->w_prevdir);
- stl_clear_click_defs(wp->w_status_click_defs, wp->w_status_click_defs_size);
+ stl_clear_click_defs(wp->w_status_click_defs, (long)wp->w_status_click_defs_size);
xfree(wp->w_status_click_defs);
- stl_clear_click_defs(wp->w_winbar_click_defs, wp->w_winbar_click_defs_size);
+ stl_clear_click_defs(wp->w_winbar_click_defs, (long)wp->w_winbar_click_defs_size);
xfree(wp->w_winbar_click_defs);
// Remove the window from the b_wininfo lists, it may happen that the
@@ -5503,7 +5497,7 @@ void win_setheight_win(int height, win_T *win)
{
// Always keep current window at least one line high, even when 'winminheight' is zero.
// Keep window at least two lines high if 'winbar' is enabled.
- height = MAX(height, (win == curwin ? MAX(p_wmh, 1) : p_wmh) + win->w_winbar_height);
+ height = MAX(height, (int)(win == curwin ? MAX(p_wmh, 1) : p_wmh) + win->w_winbar_height);
if (win->w_floating) {
win->w_float_config.height = height;
@@ -5566,7 +5560,7 @@ static void frame_setheight(frame_T *curfrp, int height)
// If height is greater than the available space, try to create space for
// the frame by reducing 'cmdheight' if possible, while making sure
// `cmdheight` doesn't go below 1.
- height = MIN((p_ch > 0 ? ROWS_AVAIL + (p_ch - 1) : ROWS_AVAIL), height);
+ height = (int)MIN((p_ch > 0 ? ROWS_AVAIL + (p_ch - 1) : ROWS_AVAIL), height);
}
if (height > 0) {
frame_new_height(curfrp, height, false, false);
@@ -5608,7 +5602,7 @@ static void frame_setheight(frame_T *curfrp, int height)
room_cmdline = 0;
} else {
win_T *wp = lastwin_nofloating();
- room_cmdline = Rows - p_ch - global_stl_height()
+ room_cmdline = Rows - (int)p_ch - global_stl_height()
- (wp->w_winrow + wp->w_height + wp->w_hsep_height + wp->w_status_height);
if (room_cmdline < 0) {
room_cmdline = 0;
@@ -5718,7 +5712,7 @@ void win_setwidth_win(int width, win_T *wp)
// 'winminwidth' is zero.
if (wp == curwin) {
if (width < p_wmw) {
- width = p_wmw;
+ width = (int)p_wmw;
}
if (width == 0) {
width = 1;
@@ -5882,8 +5876,8 @@ void win_setminheight(void)
// loop until there is a 'winminheight' that is possible
while (p_wmh > 0) {
- const int room = Rows - p_ch;
- const int needed = min_rows() - 1; // 1 was added for the cmdline
+ const int room = Rows - (int)p_ch;
+ const int needed = min_rows();
if (room >= needed) {
break;
}
@@ -5973,7 +5967,7 @@ void win_drag_status_line(win_T *dragwin, int offset)
// Only dragging the last status line can reduce p_ch.
room = Rows - cmdline_row;
if (curfr->fr_next != NULL) {
- room -= p_ch + global_stl_height();
+ room -= (int)p_ch + global_stl_height();
}
if (room < 0) {
room = 0;
@@ -6151,8 +6145,7 @@ void set_fraction(win_T *wp)
// When cursor is in the first line the percentage is computed as if
// 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;
+ wp->w_fraction = (int)(wp->w_wrow * FRACTION_MULT + FRACTION_MULT / 2) / wp->w_height_inner;
}
}
@@ -6199,7 +6192,7 @@ void scroll_to_fraction(win_T *wp, int prev_height)
if (lnum < 1) { // can happen when starting up
lnum = 1;
}
- wp->w_wrow = ((long)wp->w_fraction * (long)height - 1L) / FRACTION_MULT;
+ wp->w_wrow = (int)((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;
@@ -6314,7 +6307,8 @@ void win_set_inner_size(win_T *wp)
// There is no point in adjusting the scroll position when exiting. Some
// values might be invalid.
- if (!exiting) {
+ // Skip scroll_to_fraction() when 'cmdheight' was set to one from zero.
+ if (!exiting && !made_cmdheight_nonzero) {
scroll_to_fraction(wp, prev_height);
}
redraw_later(wp, NOT_VALID); // SOME_VALID??
@@ -6384,7 +6378,7 @@ void command_height(void)
{
int h;
frame_T *frp;
- int old_p_ch = curtab->tp_ch_used;
+ int old_p_ch = (int)curtab->tp_ch_used;
// Use the value of p_ch that we remembered. This is needed for when the
// GUI starts up, we can't be sure in what order things happen. And when
@@ -6404,7 +6398,7 @@ void command_height(void)
}
if (starting != NO_SCREEN) {
- cmdline_row = Rows - p_ch;
+ cmdline_row = Rows - (int)p_ch;
if (p_ch > old_p_ch) { // p_ch got bigger
while (p_ch > old_p_ch) {
@@ -6412,12 +6406,12 @@ void command_height(void)
emsg(_(e_noroom));
p_ch = old_p_ch;
curtab->tp_ch_used = p_ch;
- cmdline_row = Rows - p_ch;
+ cmdline_row = Rows - (int)p_ch;
break;
}
h = frp->fr_height - frame_minheight(frp, NULL);
if (h > p_ch - old_p_ch) {
- h = p_ch - old_p_ch;
+ h = (int)p_ch - old_p_ch;
}
old_p_ch += h;
frame_add_height(frp, -h);
@@ -6481,9 +6475,9 @@ char_u *grab_file_name(long count, linenr_T *file_lnum)
}
// Only recognize ":123" here
if (file_lnum != NULL && ptr[len] == ':' && isdigit(ptr[len + 1])) {
- char_u *p = ptr + len + 1;
+ char *p = (char *)ptr + len + 1;
- *file_lnum = getdigits_long(&p, false, 0);
+ *file_lnum = (linenr_T)getdigits_long(&p, false, 0);
}
return find_file_name_in_path(ptr, len, options, count, (char_u *)curbuf->b_ffname);
}
@@ -6607,7 +6601,7 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u
}
p = skipwhite(p);
if (isdigit(*p)) {
- *file_lnum = getdigits_long((char_u **)&p, false, 0);
+ *file_lnum = (linenr_T)getdigits_long(&p, false, 0);
}
}
}
@@ -6637,7 +6631,7 @@ static void win_remove_status_line(win_T *wp, bool add_hsep)
}
comp_col();
- stl_clear_click_defs(wp->w_status_click_defs, wp->w_status_click_defs_size);
+ stl_clear_click_defs(wp->w_status_click_defs, (long)wp->w_status_click_defs_size);
xfree(wp->w_status_click_defs);
wp->w_status_click_defs_size = 0;
wp->w_status_click_defs = NULL;
@@ -6745,34 +6739,50 @@ static void last_status_rec(frame_T *fr, bool statusline, bool is_stl_global)
}
}
-// Add or remove window bars from windows depending on the value of 'winbar'.
-void set_winbar(void)
-{
- FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
- // Require the local value to be set in order to show winbar on a floating window.
- int winbar_height = wp->w_floating ? ((*wp->w_p_wbr != NUL) ? 1 : 0)
- : ((*p_wbr != NUL || *wp->w_p_wbr != NUL) ? 1 : 0);
-
- if (wp->w_winbar_height != winbar_height) {
- if (winbar_height == 1 && wp->w_height_inner <= 1) {
- if (wp->w_floating) {
- emsg(_(e_noroom));
- continue;
- } else if (!resize_frame_for_winbar(wp->w_frame)) {
- return;
- }
+/// Add or remove window bar from window "wp".
+///
+/// @param make_room Whether to resize frames to make room for winbar.
+///
+/// @return Success status.
+int set_winbar_win(win_T *wp, bool make_room)
+{
+ // Require the local value to be set in order to show winbar on a floating window.
+ int winbar_height = wp->w_floating ? ((*wp->w_p_wbr != NUL) ? 1 : 0)
+ : ((*p_wbr != NUL || *wp->w_p_wbr != NUL) ? 1 : 0);
+
+ if (wp->w_winbar_height != winbar_height) {
+ if (winbar_height == 1 && wp->w_height_inner <= 1) {
+ if (wp->w_floating) {
+ emsg(_(e_noroom));
+ return NOTDONE;
+ } else if (!make_room || !resize_frame_for_winbar(wp->w_frame)) {
+ return FAIL;
}
- wp->w_winbar_height = winbar_height;
- win_set_inner_size(wp);
- wp->w_redr_status = wp->w_redr_status || winbar_height;
+ }
+ wp->w_winbar_height = winbar_height;
+ win_set_inner_size(wp);
+ wp->w_redr_status = wp->w_redr_status || winbar_height;
- if (winbar_height == 0) {
- // When removing winbar, deallocate the w_winbar_click_defs array
- stl_clear_click_defs(wp->w_winbar_click_defs, wp->w_winbar_click_defs_size);
- xfree(wp->w_winbar_click_defs);
- wp->w_winbar_click_defs_size = 0;
- wp->w_winbar_click_defs = NULL;
- }
+ if (winbar_height == 0) {
+ // When removing winbar, deallocate the w_winbar_click_defs array
+ stl_clear_click_defs(wp->w_winbar_click_defs, (long)wp->w_winbar_click_defs_size);
+ xfree(wp->w_winbar_click_defs);
+ wp->w_winbar_click_defs_size = 0;
+ wp->w_winbar_click_defs = NULL;
+ }
+ }
+
+ return OK;
+}
+
+/// Add or remove window bars from all windows in tab depending on the value of 'winbar'.
+///
+/// @param make_room Whether to resize frames to make room for winbar.
+void set_winbar(bool make_room)
+{
+ FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
+ if (set_winbar_win(wp, make_room) == FAIL) {
+ break;
}
}
}
@@ -6821,7 +6831,9 @@ int min_rows(void)
}
}
total += tabline_height() + global_stl_height();
- total += 1; // count the room for the command line
+ if (p_ch > 0) {
+ total += 1; // count the room for the command line
+ }
return total;
}
@@ -6846,43 +6858,67 @@ 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.
-///
-/// @param do_curwin when true, also check current window.
-void check_lnums(bool do_curwin)
+/// Implementation of check_lnums() and check_lnums_nested().
+static void check_lnums_both(bool do_curwin, bool nested)
{
FOR_ALL_TAB_WINDOWS(tp, wp) {
if ((do_curwin || wp != curwin) && wp->w_buffer == curbuf) {
- // save the original cursor position and topline
- wp->w_save_cursor.w_cursor_save = wp->w_cursor;
- wp->w_save_cursor.w_topline_save = wp->w_topline;
+ if (!nested) {
+ // save the original cursor position and topline
+ wp->w_save_cursor.w_cursor_save = wp->w_cursor;
+ wp->w_save_cursor.w_topline_save = wp->w_topline;
+ }
- if (wp->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
+ bool need_adjust = wp->w_cursor.lnum > curbuf->b_ml.ml_line_count;
+ if (need_adjust) {
wp->w_cursor.lnum = curbuf->b_ml.ml_line_count;
}
- if (wp->w_topline > curbuf->b_ml.ml_line_count) {
- wp->w_topline = curbuf->b_ml.ml_line_count;
+ if (need_adjust || !nested) {
+ // save the (corrected) cursor position
+ wp->w_save_cursor.w_cursor_corr = wp->w_cursor;
}
- // save the corrected cursor position and topline
- wp->w_save_cursor.w_cursor_corr = wp->w_cursor;
- wp->w_save_cursor.w_topline_corr = wp->w_topline;
+ need_adjust = wp->w_topline > curbuf->b_ml.ml_line_count;
+ if (need_adjust) {
+ wp->w_topline = curbuf->b_ml.ml_line_count;
+ }
+ if (need_adjust || !nested) {
+ // save the (corrected) topline
+ wp->w_save_cursor.w_topline_corr = wp->w_topline;
+ }
}
}
}
+/// 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)
+{
+ check_lnums_both(do_curwin, false);
+}
+
+/// Like check_lnums() but for when check_lnums() was already called.
+void check_lnums_nested(bool do_curwin)
+{
+ check_lnums_both(do_curwin, true);
+}
+
/// Reset cursor and topline to its stored values from check_lnums().
/// check_lnums() must have been called first!
void reset_lnums(void)
{
FOR_ALL_TAB_WINDOWS(tp, wp) {
if (wp->w_buffer == curbuf) {
- // Restore the value if the autocommand didn't change it.
- if (equalpos(wp->w_save_cursor.w_cursor_corr, wp->w_cursor)) {
+ // Restore the value if the autocommand didn't change it and it was
+ // set.
+ if (equalpos(wp->w_save_cursor.w_cursor_corr, wp->w_cursor)
+ && wp->w_save_cursor.w_cursor_save.lnum != 0) {
wp->w_cursor = wp->w_save_cursor.w_cursor_save;
}
- if (wp->w_save_cursor.w_topline_corr == wp->w_topline) {
+ if (wp->w_save_cursor.w_topline_corr == wp->w_topline
+ && wp->w_save_cursor.w_topline_save != 0) {
wp->w_topline = wp->w_save_cursor.w_topline_save;
}
}
@@ -7201,14 +7237,14 @@ int win_getid(typval_T *argvars)
if (argvars[0].v_type == VAR_UNKNOWN) {
return curwin->handle;
}
- int winnr = tv_get_number(&argvars[0]);
+ int winnr = (int)tv_get_number(&argvars[0]);
win_T *wp;
if (winnr > 0) {
if (argvars[1].v_type == VAR_UNKNOWN) {
wp = firstwin;
} else {
tabpage_T *tp = NULL;
- int tabnr = tv_get_number(&argvars[1]);
+ int tabnr = (int)tv_get_number(&argvars[1]);
FOR_ALL_TABS(tp2) {
if (--tabnr == 0) {
tp = tp2;
@@ -7235,7 +7271,7 @@ int win_getid(typval_T *argvars)
int win_gotoid(typval_T *argvars)
{
- int id = tv_get_number(&argvars[0]);
+ int id = (int)tv_get_number(&argvars[0]);
FOR_ALL_TAB_WINDOWS(tp, wp) {
if (wp->handle == id) {
@@ -7302,7 +7338,7 @@ win_T *win_id2wp_tp(int id, tabpage_T **tpp)
int win_id2win(typval_T *argvars)
{
int nr = 1;
- int id = tv_get_number(&argvars[0]);
+ int id = (int)tv_get_number(&argvars[0]);
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->handle == id) {
@@ -7315,7 +7351,7 @@ int win_id2win(typval_T *argvars)
void win_findbuf(typval_T *argvars, list_T *list)
{
- int bufnr = tv_get_number(&argvars[0]);
+ int bufnr = (int)tv_get_number(&argvars[0]);
FOR_ALL_TAB_WINDOWS(tp, wp) {
if (wp->w_buffer->b_fnum == bufnr) {