diff options
author | Jan Edmund Lazo <janedmundlazo@hotmail.com> | 2018-08-02 23:11:25 -0400 |
---|---|---|
committer | Jan Edmund Lazo <janedmundlazo@hotmail.com> | 2018-08-02 23:11:27 -0400 |
commit | c51c2f5a65881b2057907338099e12fa19811d41 (patch) | |
tree | 4cd12fb632635e1173690f964d9907dd5fe5680c | |
parent | 766683622a83c0e40f9aa152aec87bd67f87f21a (diff) | |
download | rneovim-c51c2f5a65881b2057907338099e12fa19811d41.tar.gz rneovim-c51c2f5a65881b2057907338099e12fa19811d41.tar.bz2 rneovim-c51c2f5a65881b2057907338099e12fa19811d41.zip |
misc: refactor plines_win{,_nofill}()
Add const to params and variables (declare and init on same line).
winheight (param) is bool so replace TRUE/FALSE macros with true/false.
-rw-r--r-- | src/nvim/misc1.c | 50 | ||||
-rw-r--r-- | src/nvim/screen.c | 15 | ||||
-rw-r--r-- | src/nvim/window.c | 15 |
3 files changed, 41 insertions, 39 deletions
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index e4137e1da3..da2d8f4e7c 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -1203,16 +1203,15 @@ int get_last_leader_offset(char_u *line, char_u **flags) /* * Return the number of window lines occupied by buffer line "lnum". */ -int plines(linenr_T lnum) +int plines(const linenr_T lnum) { - return plines_win(curwin, lnum, TRUE); + return plines_win(curwin, lnum, true); } -int -plines_win ( - win_T *wp, - linenr_T lnum, - int winheight /* when TRUE limit to window height */ +int plines_win( + win_T *const wp, + const linenr_T lnum, + const bool winheight // when true limit to window height ) { /* Check for filler lines above this buffer line. When folded the result @@ -1220,34 +1219,34 @@ plines_win ( return plines_win_nofill(wp, lnum, winheight) + diff_check_fill(wp, lnum); } -int plines_nofill(linenr_T lnum) +int plines_nofill(const linenr_T lnum) { - return plines_win_nofill(curwin, lnum, TRUE); + return plines_win_nofill(curwin, lnum, true); } -int -plines_win_nofill ( - win_T *wp, - linenr_T lnum, - int winheight /* when TRUE limit to window height */ +int plines_win_nofill( + win_T *const wp, + const linenr_T lnum, + const bool winheight // when true limit to window height ) { - int lines; - - if (!wp->w_p_wrap) + if (!wp->w_p_wrap) { return 1; + } - if (wp->w_width == 0) + if (wp->w_width == 0) { return 1; + } // A folded lines is handled just like an empty line. if (lineFolded(wp, lnum)) { return 1; } - lines = plines_win_nofold(wp, lnum); - if (winheight > 0 && lines > wp->w_height) + const int lines = plines_win_nofold(wp, lnum); + if (winheight && lines > wp->w_height) { return wp->w_height; + } return lines; } @@ -1347,11 +1346,12 @@ int plines_m_win(win_T *wp, linenr_T first, linenr_T last) ++count; /* count 1 for "+-- folded" line */ first += x; } else { - if (first == wp->w_topline) - count += plines_win_nofill(wp, first, TRUE) + wp->w_topfill; - else - count += plines_win(wp, first, TRUE); - ++first; + if (first == wp->w_topline) { + count += plines_win_nofill(wp, first, true) + wp->w_topfill; + } else { + count += plines_win(wp, first, true); + } + first++; } } return count; diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 24ea221c78..72b4a3a4f8 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -990,7 +990,7 @@ static void win_update(win_T *wp) * when it won't get updated below. */ if (wp->w_p_diff && bot_start > 0) wp->w_lines[0].wl_size = - plines_win_nofill(wp, wp->w_topline, TRUE) + plines_win_nofill(wp, wp->w_topline, true) + wp->w_topfill; } } @@ -1447,12 +1447,13 @@ static void win_update(win_T *wp) } wp->w_lines[idx].wl_lnum = lnum; - wp->w_lines[idx].wl_valid = TRUE; - if (row > wp->w_height) { /* past end of screen */ - /* we may need the size of that too long line later on */ - if (dollar_vcol == -1) - wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); - ++idx; + wp->w_lines[idx].wl_valid = true; + if (row > wp->w_height) { // past end of screen + // we may need the size of that too long line later on + if (dollar_vcol == -1) { + wp->w_lines[idx].wl_size = plines_win(wp, lnum, true); + } + idx++; break; } if (dollar_vcol == -1) diff --git a/src/nvim/window.c b/src/nvim/window.c index 274bf72f3b..7582c837c8 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -4848,8 +4848,8 @@ void scroll_to_fraction(win_T *wp, int prev_height) sline = wp->w_wrow - line_size; if (sline >= 0) { - /* Make sure the whole cursor line is visible, if possible. */ - int rows = plines_win(wp, lnum, FALSE); + // Make sure the whole cursor line is visible, if possible. + const int rows = plines_win(wp, lnum, false); if (sline > wp->w_height - rows) { sline = wp->w_height - rows; @@ -4884,12 +4884,13 @@ void scroll_to_fraction(win_T *wp, int prev_height) --sline; break; } - --lnum; - if (lnum == wp->w_topline) - line_size = plines_win_nofill(wp, lnum, TRUE) + lnum--; + if (lnum == wp->w_topline) { + line_size = plines_win_nofill(wp, lnum, true) + wp->w_topfill; - else - line_size = plines_win(wp, lnum, TRUE); + } else { + line_size = plines_win(wp, lnum, true); + } sline -= line_size; } |