diff options
Diffstat (limited to 'src/nvim/plines.c')
-rw-r--r-- | src/nvim/plines.c | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/src/nvim/plines.c b/src/nvim/plines.c index cc730ba307..e4d1ddf8d8 100644 --- a/src/nvim/plines.c +++ b/src/nvim/plines.c @@ -10,25 +10,21 @@ #include <string.h> #include "nvim/ascii.h" -#include "nvim/buffer.h" #include "nvim/charset.h" -#include "nvim/cursor.h" #include "nvim/decoration.h" #include "nvim/diff.h" #include "nvim/fold.h" -#include "nvim/func_attr.h" +#include "nvim/globals.h" #include "nvim/indent.h" -#include "nvim/main.h" +#include "nvim/macros.h" #include "nvim/mbyte.h" #include "nvim/memline.h" -#include "nvim/memory.h" #include "nvim/move.h" #include "nvim/option.h" #include "nvim/plines.h" -#include "nvim/screen.h" -#include "nvim/strings.h" +#include "nvim/pos.h" +#include "nvim/types.h" #include "nvim/vim.h" -#include "nvim/window.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "plines.c.generated.h" @@ -37,6 +33,9 @@ /// Functions calculating vertical size of text when displayed inside a window. /// Calls horizontal size functions defined below. +/// Return the number of window lines occupied by buffer line "lnum". +/// Includes any filler lines. +/// /// @param winheight when true limit to window height int plines_win(win_T *wp, linenr_T lnum, bool winheight) { @@ -71,6 +70,9 @@ bool win_may_fill(win_T *wp) return (wp->w_p_diff && diffopt_filler()) || wp->w_buffer->b_virt_line_blocks; } +/// Return the number of window lines occupied by buffer line "lnum". +/// Does not include filler lines. +/// /// @param winheight when true limit to window height int plines_win_nofill(win_T *wp, linenr_T lnum, bool winheight) { @@ -102,11 +104,11 @@ int plines_win_nofold(win_T *wp, linenr_T lnum) unsigned int col; int width; - s = (char *)ml_get_buf(wp->w_buffer, lnum, false); + s = ml_get_buf(wp->w_buffer, lnum, false); if (*s == NUL) { // empty line return 1; } - col = win_linetabsize(wp, lnum, (char_u *)s, MAXCOL); + col = win_linetabsize(wp, lnum, s, MAXCOL); // If list mode is on, then the '$' at the end of the line may take up one // extra column. @@ -144,7 +146,7 @@ int plines_win_col(win_T *wp, linenr_T lnum, long column) return lines + 1; } - char_u *line = ml_get_buf(wp->w_buffer, lnum, false); + char *line = ml_get_buf(wp->w_buffer, lnum, false); colnr_T col = 0; chartabsize_T cts; @@ -232,9 +234,8 @@ int win_chartabsize(win_T *wp, char *p, colnr_T col) buf_T *buf = wp->w_buffer; if (*p == TAB && (!wp->w_p_list || wp->w_p_lcs_chars.tab1)) { return tabstop_padding(col, buf->b_p_ts, buf->b_p_vts_array); - } else { - return ptr2cells(p); } + return ptr2cells(p); } /// Return the number of characters the string 's' will take on the screen, @@ -243,9 +244,9 @@ int win_chartabsize(win_T *wp, char *p, colnr_T col) /// @param s /// /// @return Number of characters the string will take on the screen. -int linetabsize(char_u *s) +int linetabsize(char *s) { - return linetabsize_col(0, (char *)s); + return linetabsize_col(0, s); } /// Like linetabsize(), but "s" starts at column "startcol". @@ -257,7 +258,7 @@ int linetabsize(char_u *s) int linetabsize_col(int startcol, char *s) { chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, 0, startcol, (char_u *)s, (char_u *)s); + init_chartabsize_arg(&cts, curwin, 0, startcol, s, s); while (*cts.cts_ptr != NUL) { cts.cts_vcol += lbr_chartabsize_adv(&cts); } @@ -272,11 +273,11 @@ int linetabsize_col(int startcol, char *s) /// @param len /// /// @return Number of characters the string will take on the screen. -unsigned int win_linetabsize(win_T *wp, linenr_T lnum, char_u *line, colnr_T len) +unsigned int win_linetabsize(win_T *wp, linenr_T lnum, char *line, colnr_T len) { chartabsize_T cts; init_chartabsize_arg(&cts, wp, lnum, 0, line, line); - for (; *cts.cts_ptr != NUL && (len == MAXCOL || cts.cts_ptr < (char *)line + len); + for (; *cts.cts_ptr != NUL && (len == MAXCOL || cts.cts_ptr < line + len); MB_PTR_ADV(cts.cts_ptr)) { cts.cts_vcol += win_lbr_chartabsize(&cts, NULL); } @@ -288,14 +289,13 @@ unsigned int win_linetabsize(win_T *wp, linenr_T lnum, char_u *line, colnr_T len /// /// "line" is the start of the line, "ptr" is the first relevant character. /// When "lnum" is zero do not use text properties that insert text. -void init_chartabsize_arg(chartabsize_T *cts, win_T *wp, linenr_T lnum, colnr_T col, char_u *line, - char_u *ptr) +void init_chartabsize_arg(chartabsize_T *cts, win_T *wp, linenr_T lnum FUNC_ATTR_UNUSED, + colnr_T col, char *line, char *ptr) { cts->cts_win = wp; - cts->cts_lnum = lnum; cts->cts_vcol = col; - cts->cts_line = (char *)line; - cts->cts_ptr = (char *)ptr; + cts->cts_line = line; + cts->cts_ptr = ptr; cts->cts_cur_text_width = 0; // TODO(bfredl): actually lookup inline virtual text here cts->cts_has_virt_text = false; @@ -354,7 +354,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) { win_T *wp = cts->cts_win; char *line = cts->cts_line; // start of the line - char_u *s = (char_u *)cts->cts_ptr; + char *s = cts->cts_ptr; colnr_T vcol = cts->cts_vcol; colnr_T col2; @@ -363,7 +363,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) int added; int mb_added = 0; int numberextra; - char_u *ps; + char *ps; int n; cts->cts_cur_text_width = 0; @@ -374,16 +374,16 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) if (wp->w_p_wrap) { return win_nolbr_chartabsize(cts, headp); } - return win_chartabsize(wp, (char *)s, vcol); + return win_chartabsize(wp, s, vcol); } // First get normal size, without 'linebreak' or virtual text - int size = win_chartabsize(wp, (char *)s, vcol); + int size = win_chartabsize(wp, s, vcol); if (cts->cts_has_virt_text) { // TODO(bfredl): inline virtual text } - int c = *s; + int c = (uint8_t)(*s); if (*s == TAB) { col_adj = size - 1; } @@ -392,7 +392,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) // needs a break here if (wp->w_p_lbr && vim_isbreak(c) - && !vim_isbreak((int)s[1]) + && !vim_isbreak((uint8_t)s[1]) && wp->w_p_wrap && (wp->w_width_inner != 0)) { // Count all characters from first non-blank after a blank up to next @@ -413,14 +413,14 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) for (;;) { ps = s; MB_PTR_ADV(s); - c = *s; + c = (uint8_t)(*s); if (!(c != NUL - && (vim_isbreak(c) || col2 == vcol || !vim_isbreak((int)(*ps))))) { + && (vim_isbreak(c) || col2 == vcol || !vim_isbreak((uint8_t)(*ps))))) { break; } - col2 += win_chartabsize(wp, (char *)s, col2); + col2 += win_chartabsize(wp, s, col2); if (col2 >= colmax) { // doesn't fit size = colmax - vcol + col_adj; @@ -428,7 +428,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) } } } else if ((size == 2) - && (MB_BYTE2LEN(*s) > 1) + && (MB_BYTE2LEN((uint8_t)(*s)) > 1) && wp->w_p_wrap && in_win_border(wp, vcol)) { // Count the ">" in the last column. @@ -439,9 +439,9 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) // May have to add something for 'breakindent' and/or 'showbreak' // string at start of line. // Set *headp to the size of what we add. + // Do not use 'showbreak' at the NUL after the text. added = 0; - - char *const sbr = (char *)get_showbreak_value(wp); + char *const sbr = c == NUL ? empty_option : (char *)get_showbreak_value(wp); if ((*sbr != NUL || wp->w_p_bri) && wp->w_p_wrap && vcol != 0) { colnr_T sbrlen = 0; int numberwidth = win_col_off(wp); @@ -456,7 +456,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) vcol %= numberextra; } if (*sbr != NUL) { - sbrlen = (colnr_T)mb_charlen((char_u *)sbr); + sbrlen = (colnr_T)mb_charlen(sbr); if (vcol >= sbrlen) { vcol -= sbrlen; } @@ -492,7 +492,7 @@ int win_lbr_chartabsize(chartabsize_T *cts, int *headp) } if (wp->w_p_bri) { - added += get_breakindent_win(wp, (char_u *)line); + added += get_breakindent_win(wp, line); } size += added; |