diff options
Diffstat (limited to 'src/nvim/window.c')
-rw-r--r-- | src/nvim/window.c | 181 |
1 files changed, 87 insertions, 94 deletions
diff --git a/src/nvim/window.c b/src/nvim/window.c index dfe1ffdbd4..be49d3e574 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -59,8 +59,6 @@ #endif - - #define NOWIN (win_T *)-1 // non-existing window #define ROWS_AVAIL (Rows - p_ch - tabline_height()) @@ -94,7 +92,7 @@ void do_window(int nchar, long Prenum, int xchar) #define CHECK_CMDWIN \ do { \ if (cmdwin_type != 0) { \ - EMSG(_(e_cmdwin)); \ + emsg(_(e_cmdwin)); \ return; \ } \ } while (0) @@ -135,9 +133,9 @@ void do_window(int nchar, long Prenum, int xchar) if (buflist_findnr(Prenum == 0 ? curwin->w_alt_fnum : Prenum) == NULL) { if (Prenum == 0) { - EMSG(_(e_noalt)); + emsg(_(e_noalt)); } else { - EMSGN(_("E92: Buffer %" PRId64 " not found"), Prenum); + semsg(_("E92: Buffer %" PRId64 " not found"), (int64_t)Prenum); } break; } @@ -201,7 +199,7 @@ newwindow: } } if (wp == NULL) { - EMSG(_("E441: There is no preview window")); + emsg(_("E441: There is no preview window")); } else { win_goto(wp); } @@ -294,7 +292,7 @@ newwindow: // move window to new tab page case 'T': if (one_window()) { - MSG(_(m_onlyone)); + msg(_(m_onlyone)); } else { tabpage_T *oldtab = curtab; tabpage_T *newtab; @@ -464,9 +462,8 @@ wingotofile: } break; - /* Go to the first occurrence of the identifier under cursor along path in a - * new window -- webb - */ + // Go to the first occurrence of the identifier under cursor along path in a + // new window -- webb case 'i': // Go to any match case Ctrl_I: type = FIND_ANY; @@ -553,7 +550,7 @@ wingotofile: config.external = true; Error err = ERROR_INIT; if (!win_new_float(curwin, config, &err)) { - EMSG(err.msg); + emsg(err.msg); api_clear_error(&err); beep_flush(); } @@ -919,7 +916,7 @@ int win_split(int size, int flags) // 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")); + emsg(_("E442: Can't split topleft and botright at the same time")); return FAIL; } @@ -972,7 +969,7 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir) // add a status line when p_ls == 1 and splitting the first window if (one_nonfloat() && p_ls == 1 && oldwin->w_status_height == 0) { if (oldwin->w_height <= p_wmh && new_in_layout) { - EMSG(_(e_noroom)); + emsg(_(e_noroom)); return FAIL; } need_status = STATUS_HEIGHT; @@ -1021,7 +1018,7 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir) needed += minwidth; } if (available < needed && new_in_layout) { - EMSG(_(e_noroom)); + emsg(_(e_noroom)); return FAIL; } if (new_size == 0) { @@ -1046,8 +1043,8 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir) win_setwidth_win(oldwin->w_width + new_size + 1, oldwin); } - /* Only make all windows the same width if one of them (except oldwin) - * is wider than one of the split windows. */ + // Only make all windows the same width if one of them (except oldwin) + // is wider than one of the split windows. if (!do_equal && p_ea && size == 0 && *p_ead != 'v' && oldwin->w_frame->fr_parent != NULL) { frp = oldwin->w_frame->fr_parent->fr_child; @@ -1101,7 +1098,7 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir) needed += minheight; } if (available < needed && new_in_layout) { - EMSG(_(e_noroom)); + emsg(_(e_noroom)); return FAIL; } oldwin_height = oldwin->w_height; @@ -1125,9 +1122,9 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir) 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 - * instead, if possible. */ + // We don't like to take lines for the new window from a + // 'winfixheight' window. Take them from a window above or below + // instead, if possible. if (oldwin->w_p_wfh) { // Set w_fraction now so that the cursor keeps the same relative // vertical position using the old height. @@ -1142,8 +1139,8 @@ int win_split_ins(int size, int flags, win_T *new_wp, int dir) } } - /* Only make all windows the same height if one of them (except oldwin) - * is higher than one of the split windows. */ + // Only make all windows the same height if one of them (except oldwin) + // is higher than one of the split windows. if (!do_equal && p_ea && size == 0 && *p_ead != 'h' && oldwin->w_frame->fr_parent != NULL) { @@ -1657,7 +1654,7 @@ static void win_exchange(long Prenum) int temp; if (curwin->w_floating) { - EMSG(e_floatexchange); + emsg(e_floatexchange); return; } @@ -1744,7 +1741,7 @@ static void win_rotate(bool upwards, int count) int n; if (curwin->w_floating) { - EMSG(e_floatexchange); + emsg(e_floatexchange); return; } @@ -1757,7 +1754,7 @@ static void win_rotate(bool upwards, int count) // Check if all frames in this row/col have one window. FOR_ALL_FRAMES(frp, curwin->w_frame->fr_parent->fr_child) { if (frp->fr_win == NULL) { - EMSG(_("E443: Cannot rotate when another window is split")); + emsg(_("E443: Cannot rotate when another window is split")); return; } } @@ -1774,7 +1771,6 @@ static void win_rotate(bool upwards, int count) // 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); @@ -1784,7 +1780,6 @@ static void win_rotate(bool upwards, int count) // find last window/frame in the list and remove it for (frp = curwin->w_frame; frp->fr_next != NULL; frp = frp->fr_next) { - ; } wp1 = frp->fr_win; wp2 = wp1->w_prev; // will become last window @@ -1874,15 +1869,14 @@ void win_move_after(win_T *win1, win_T *win2) // check if there is something to do if (win2->w_next != win1) { - /* may need move the status line/vertical separator of the last window - * */ + // may need move the status line/vertical separator of the last window if (win1 == lastwin) { height = win1->w_prev->w_status_height; win1->w_prev->w_status_height = win1->w_status_height; win1->w_status_height = height; if (win1->w_prev->w_vsep_width == 1) { - /* Remove the vertical separator from the last-but-one window, - * add it to the last window. Adjust the frame widths. */ + // Remove the vertical separator from the last-but-one window, + // add it to the last window. Adjust the frame widths. win1->w_prev->w_vsep_width = 0; win1->w_prev->w_frame->fr_width -= 1; win1->w_vsep_width = 1; @@ -1974,8 +1968,8 @@ static void win_equal_rec(win_T *next_curwin, bool current, frame_T *topfr, int topfr->fr_height = height; if (dir != 'v') { // equalize frame widths - /* Compute the maximum number of windows horizontally in this - * frame. */ + // 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) { @@ -2360,8 +2354,8 @@ static bool close_last_window_tabpage(win_T *win, bool free_buf, tabpage_T *prev char_u prev_idx[NUMBUFLEN]; sprintf((char *)prev_idx, "%i", tabpage_index(prev_curtab)); - /* Safety check: Autocommands may have closed the window when jumping - * to the other tab page. */ + // Safety check: Autocommands may have closed the window when jumping + // to the other tab page. if (valid_tabpage(prev_curtab) && prev_curtab->tp_firstwin == win) { int h = tabline_height(); @@ -2398,7 +2392,7 @@ int win_close(win_T *win, bool free_buf) const bool had_diffmode = win->w_p_diff; if (last_window() && !win->w_floating) { - EMSG(_("E444: Cannot close last window")); + emsg(_("E444: Cannot close last window")); return FAIL; } @@ -2407,29 +2401,29 @@ int win_close(win_T *win, bool free_buf) return FAIL; // window is already being closed } if (win == aucmd_win) { - EMSG(_(e_autocmd_close)); + emsg(_(e_autocmd_close)); return FAIL; } if ((firstwin == aucmd_win || lastwin == aucmd_win) && one_window()) { - EMSG(_("E814: Cannot close window, only autocmd window would remain")); + emsg(_("E814: Cannot close window, only autocmd window would remain")); return FAIL; } if ((firstwin == win && lastwin_nofloating() == win) && lastwin->w_floating) { // TODO(bfredl): we might close the float also instead - EMSG(e_floatonly); + emsg(e_floatonly); return FAIL; } - /* 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. */ + // 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)) { return FAIL; } - /* When closing the help window, try restoring a snapshot after closing - * the window. Otherwise clear the snapshot, it's now invalid. */ + // When closing the help window, try restoring a snapshot after closing + // the window. Otherwise clear the snapshot, it's now invalid. if (bt_help(win->w_buffer)) { help_window = true; } else { @@ -2575,9 +2569,9 @@ int win_close(win_T *win, bool free_buf) } } - /* Make sure curwin isn't invalid. It can cause severe trouble when - * printing an error message. For win_equal() curbuf needs to be valid - * too. */ + // Make sure curwin isn't invalid. It can cause severe trouble when + // printing an error message. For win_equal() curbuf needs to be valid + // too. if (win == curwin) { curwin = wp; if (wp->w_p_pvw || bt_quickfix(wp->w_buffer)) { @@ -2709,7 +2703,6 @@ 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) { - ; } if (ptp == NULL || tp == curtab) { return; @@ -2895,9 +2888,9 @@ win_T *winframe_remove(win_T *win, int *dirp, tabpage_T *tp) frp2 == frp_close->fr_next, false); *dirp = 'v'; } else { - /* When 'winfixwidth' is set, try to find another frame in the column - * (as close to the closed frame as possible) to distribute the width - * to. */ + // When 'winfixwidth' is set, try to find another frame in the column + // (as close to the closed frame as possible) to distribute the width + // to. if (frp2->fr_win != NULL && frp2->fr_win->w_p_wfw) { frp = frp_close->fr_prev; frp3 = frp_close->fr_next; @@ -3047,7 +3040,6 @@ static tabpage_T *alt_tabpage(void) // Find the last but one tab page. for (tp = first_tabpage; tp->tp_next != curtab; tp = tp->tp_next) { - ; } return tp; } @@ -3112,8 +3104,8 @@ static void frame_new_height(frame_T *topfrp, int height, bool topfirst, bool wf } } while (frp != NULL); } else { // fr_layout == FR_COL - /* Complicated case: Resize a column of frames. Resize the bottom - * frame first, frames above that when needed. */ + // Complicated case: Resize a column of frames. Resize the bottom + // frame first, frames above that when needed. frp = topfrp->fr_child; if (wfh) { @@ -3152,12 +3144,14 @@ static void frame_new_height(frame_T *topfrp, int height, bool topfirst, bool wf break; } if (topfirst) { - do + do{ frp = frp->fr_next; + } while (wfh && frp != NULL && frame_fixed_height(frp)); } else { - do + do{ frp = frp->fr_prev; + } while (wfh && frp != NULL && frame_fixed_height(frp)); } // Increase "height" if we could not reduce enough frames. @@ -3310,8 +3304,8 @@ static void frame_new_width(frame_T *topfrp, int width, bool leftfirst, bool wfw } } while (frp != NULL); } else { // fr_layout == FR_ROW - /* Complicated case: Resize a row of frames. Resize the rightmost - * frame first, frames left of it when needed. */ + // Complicated case: Resize a row of frames. Resize the rightmost + // frame first, frames left of it when needed. frp = topfrp->fr_child; if (wfw) { @@ -3350,12 +3344,14 @@ static void frame_new_width(frame_T *topfrp, int width, bool leftfirst, bool wfw break; } if (leftfirst) { - do + do{ frp = frp->fr_next; + } while (wfw && frp != NULL && frame_fixed_width(frp)); } else { - do + do{ frp = frp->fr_prev; + } while (wfw && frp != NULL && frame_fixed_width(frp)); } // Increase "width" if we could not reduce enough frames. @@ -3525,7 +3521,7 @@ void close_others(int message, int forceit) if (curwin->w_floating) { if (message && !autocmd_busy) { - EMSG(e_floatonly); + emsg(e_floatonly); } return; } @@ -3533,7 +3529,7 @@ void close_others(int message, int forceit) if (one_window() && !lastwin->w_floating) { if (message && !autocmd_busy) { - MSG(_(m_onlyone)); + msg(_(m_onlyone)); } return; } @@ -3567,7 +3563,7 @@ void close_others(int message, int forceit) } if (message && !ONE_WINDOW) { - EMSG(_("E445: Other window contains changes")); + emsg(_("E445: Other window contains changes")); } } @@ -4043,8 +4039,8 @@ static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, bool trigger_enter_a lastused_tabpage = old_curtab; - /* Apply autocommands after updating the display, when 'rows' and - * 'columns' have been set correctly. */ + // 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) { @@ -4122,14 +4118,12 @@ void goto_tabpage(int n) for (i = n; i < 0; ++i) { for (tp = first_tabpage; tp->tp_next != ttp && tp->tp_next != NULL; 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) { - ; } } else { // Go to tab page "n". @@ -4776,8 +4770,8 @@ static void win_free(win_T *wp, tabpage_T *tp) xfree(wp->w_localdir); xfree(wp->w_prevdir); - /* Remove the window from the b_wininfo lists, it may happen that the - * freed memory is re-used for another window. */ + // Remove the window from the b_wininfo lists, it may happen that the + // freed memory is re-used for another window. FOR_ALL_BUFFERS(buf) { for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) { if (wip->wi_win == wp) { @@ -4950,8 +4944,8 @@ void shell_new_rows(void) 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. */ + // 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); @@ -4972,8 +4966,8 @@ void shell_new_columns(void) return; } - /* First try setting the widths of windows with 'winfixwidth'. If that - * doesn't result in the right width, forget about that option. */ + // First try setting the widths of windows with 'winfixwidth'. If that + // doesn't result in the right width, forget about that option. frame_new_width(topframe, Columns, false, true); if (!frame_check_width(topframe, Columns)) { frame_new_width(topframe, Columns, false, false); @@ -5008,7 +5002,6 @@ void do_autocmd_winscrolled(win_T *wp) * Save the size of all windows in "gap". */ void win_size_save(garray_T *gap) - { ga_init(gap, (int)sizeof(int), 1); ga_grow(gap, win_count() * 2 + 1); @@ -5522,7 +5515,7 @@ void win_setminheight(void) } p_wmh--; if (first) { - EMSG(_(e_noroom)); + emsg(_(e_noroom)); first = false; } } @@ -5542,7 +5535,7 @@ void win_setminwidth(void) } p_wmw--; if (first) { - EMSG(_(e_noroom)); + emsg(_(e_noroom)); first = false; } } @@ -5572,8 +5565,8 @@ void win_drag_status_line(win_T *dragwin, int offset) } } - /* 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). */ + // 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) { fr = fr->fr_parent; @@ -5699,8 +5692,8 @@ void win_drag_vsep_line(win_T *dragwin, int offset) fr = fr->fr_parent; } - /* If this is the last frame in a row, may want to resize a parent - * frame instead. */ + // 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) { break; @@ -6037,7 +6030,7 @@ void command_height(void) if (p_ch > old_p_ch) { // p_ch got bigger while (p_ch > old_p_ch) { if (frp == NULL) { - EMSG(_(e_noroom)); + emsg(_(e_noroom)); p_ch = old_p_ch; curtab->tp_ch_used = p_ch; cmdline_row = Rows - p_ch; @@ -6159,7 +6152,7 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u } if (*ptr == NUL) { // nothing found if (options & FNAME_MESS) { - EMSG(_("E446: No file name under cursor")); + emsg(_("E446: No file name under cursor")); } return NULL; } @@ -6272,7 +6265,7 @@ static void last_status_rec(frame_T *fr, bool statusline) fp = fr; while (fp->fr_height <= frame_minheight(fp, NULL)) { if (fp == topframe) { - EMSG(_(e_noroom)); + emsg(_(e_noroom)); return; } // In a column of frames: go to frame above. If already at @@ -6302,7 +6295,6 @@ static void last_status_rec(frame_T *fr, bool statusline) } else { // 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); } @@ -6683,16 +6675,16 @@ int match_add(win_T *wp, const char *const grp, const char *const pat, int prio, return -1; } if (id < -1 || id == 0) { - EMSGN(_("E799: Invalid ID: %" PRId64 + semsg(_("E799: Invalid ID: %" PRId64 " (must be greater than or equal to 1)"), - id); + (int64_t)id); return -1; } if (id != -1) { cur = wp->w_match_head; while (cur != NULL) { if (cur->id == id) { - EMSGN(_("E801: ID already taken: %" PRId64), id); + semsg(_("E801: ID already taken: %" PRId64), (int64_t)id); return -1; } cur = cur->next; @@ -6702,7 +6694,7 @@ int match_add(win_T *wp, const char *const grp, const char *const pat, int prio, return -1; } if (pat != NULL && (regprog = vim_regcomp((char_u *)pat, RE_MAGIC)) == NULL) { - EMSG2(_(e_invarg2), pat); + semsg(_(e_invarg2), pat); return -1; } @@ -6748,7 +6740,7 @@ int match_add(win_T *wp, const char *const grp, const char *const pat, int prio, const list_T *const subl = TV_LIST_ITEM_TV(li)->vval.v_list; const listitem_T *subli = tv_list_first(subl); if (subli == NULL) { - emsgf(_("E5030: Empty list at position %d"), + semsg(_("E5030: Empty list at position %d"), (int)tv_list_idx_of_item(pos_list, li)); goto fail; } @@ -6790,7 +6782,7 @@ int match_add(win_T *wp, const char *const grp, const char *const pat, int prio, m->pos.pos[i].col = 0; m->pos.pos[i].len = 0; } else { - emsgf(_("E5031: List or number required at position %d"), + semsg(_("E5031: List or number required at position %d"), (int)tv_list_idx_of_item(pos_list, li)); goto fail; } @@ -6862,9 +6854,9 @@ int match_delete(win_T *wp, int id, bool perr) if (id < 1) { if (perr) { - EMSGN(_("E802: Invalid ID: %" PRId64 + semsg(_("E802: Invalid ID: %" PRId64 " (must be greater than or equal to 1)"), - id); + (int64_t)id); } return -1; } @@ -6874,7 +6866,7 @@ int match_delete(win_T *wp, int id, bool perr) } if (cur == NULL) { if (perr) { - EMSGN(_("E803: ID not found: %" PRId64), id); + semsg(_("E803: ID not found: %" PRId64), (int64_t)id); } return -1; } @@ -7162,7 +7154,8 @@ void win_ui_flush(void) } } -win_T *lastwin_nofloating(void) { +win_T *lastwin_nofloating(void) +{ win_T *res = lastwin; while (res->w_floating) { res = res->w_prev; |