Skip to content

Commit

Permalink
refactor: use "csarg" for CharsizeArg variables (neovim#27123)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeertzjq authored Jan 22, 2024
1 parent 8c6de91 commit e68deca
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 130 deletions.
6 changes: 3 additions & 3 deletions src/nvim/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a
}
}

CharsizeArg arg;
CSType cstype = init_charsize_arg(&arg, curwin, pos->lnum, line);
CharsizeArg csarg;
CSType cstype = init_charsize_arg(&csarg, curwin, pos->lnum, line);
StrCharInfo ci = utf_ptr2StrCharInfo(line);
col = 0;
while (col <= wcol && *ci.ptr != NUL) {
CharSize cs = win_charsize(cstype, col, ci.ptr, ci.chr.value, &arg);
CharSize cs = win_charsize(cstype, col, ci.ptr, ci.chr.value, &csarg);
csize = cs.width;
head = cs.head;
col += cs.width;
Expand Down
14 changes: 7 additions & 7 deletions src/nvim/drawline.c
Original file line number Diff line number Diff line change
Expand Up @@ -1338,13 +1338,13 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
char *prev_ptr = ptr;
CharSize cs = { 0 };

CharsizeArg arg;
CSType cstype = init_charsize_arg(&arg, wp, lnum, line);
arg.max_head_vcol = start_col;
CharsizeArg csarg;
CSType cstype = init_charsize_arg(&csarg, wp, lnum, line);
csarg.max_head_vcol = start_col;
int vcol = wlv.vcol;
StrCharInfo ci = utf_ptr2StrCharInfo(ptr);
while (vcol < start_col && *ci.ptr != NUL) {
cs = win_charsize(cstype, vcol, ci.ptr, ci.chr.value, &arg);
cs = win_charsize(cstype, vcol, ci.ptr, ci.chr.value, &csarg);
vcol += cs.width;
prev_ptr = ci.ptr;
ci = utfc_next(ci);
Expand Down Expand Up @@ -2083,11 +2083,11 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
int mb_off = utf_head_off(line, ptr - 1);
char *p = ptr - (mb_off + 1);

CharsizeArg arg;
CharsizeArg csarg;
// lnum == 0, do not want virtual text to be counted here
CSType cstype = init_charsize_arg(&arg, wp, 0, line);
CSType cstype = init_charsize_arg(&csarg, wp, 0, line);
wlv.n_extra = win_charsize(cstype, wlv.vcol, p, utf_ptr2CharInfo(p).value,
&arg).width - 1;
&csarg).width - 1;

if (on_last_col && mb_c != TAB) {
// Do not continue search/match highlighting over the
Expand Down
22 changes: 11 additions & 11 deletions src/nvim/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1687,11 +1687,11 @@ void change_indent(int type, int amount, int round, int replaced, bool call_chan
char *const line = get_cursor_line_ptr();
vcol = 0;
if (*line != NUL) {
CharsizeArg arg;
CSType cstype = init_charsize_arg(&arg, curwin, 0, line);
CharsizeArg csarg;
CSType cstype = init_charsize_arg(&csarg, curwin, 0, line);
StrCharInfo ci = utf_ptr2StrCharInfo(line);
while (true) {
int next_vcol = vcol + win_charsize(cstype, vcol, ci.ptr, ci.chr.value, &arg).width;
int next_vcol = vcol + win_charsize(cstype, vcol, ci.ptr, ci.chr.value, &csarg).width;
if (next_vcol > end_vcol) {
break;
}
Expand Down Expand Up @@ -4353,13 +4353,13 @@ static bool ins_tab(void)
char *tab = "\t";
int32_t tab_v = (uint8_t)(*tab);

CharsizeArg arg;
CSType cstype = init_charsize_arg(&arg, curwin, 0, tab);
CharsizeArg csarg;
CSType cstype = init_charsize_arg(&csarg, curwin, 0, tab);

// Use as many TABs as possible. Beware of 'breakindent', 'showbreak'
// and 'linebreak' adding extra virtual columns.
while (ascii_iswhite(*ptr)) {
int i = win_charsize(cstype, vcol, tab, tab_v, &arg).width;
int i = win_charsize(cstype, vcol, tab, tab_v, &csarg).width;
if (vcol + i > want_vcol) {
break;
}
Expand All @@ -4381,9 +4381,9 @@ static bool ins_tab(void)
if (change_col >= 0) {
int repl_off = 0;
// Skip over the spaces we need.
cstype = init_charsize_arg(&arg, curwin, 0, ptr);
cstype = init_charsize_arg(&csarg, curwin, 0, ptr);
while (vcol < want_vcol && *ptr == ' ') {
vcol += win_charsize(cstype, vcol, ptr, (uint8_t)(' '), &arg).width;
vcol += win_charsize(cstype, vcol, ptr, (uint8_t)(' '), &csarg).width;
ptr++;
repl_off++;
}
Expand Down Expand Up @@ -4567,12 +4567,12 @@ int ins_copychar(linenr_T lnum)
int const end_vcol = curwin->w_virtcol;
char *line = ml_get(lnum);

CharsizeArg arg;
CSType cstype = init_charsize_arg(&arg, curwin, lnum, line);
CharsizeArg csarg;
CSType cstype = init_charsize_arg(&csarg, curwin, lnum, line);
StrCharInfo ci = utf_ptr2StrCharInfo(line);
int vcol = 0;
while (vcol < end_vcol && *ci.ptr != NUL) {
vcol += win_charsize(cstype, vcol, ci.ptr, ci.chr.value, &arg).width;
vcol += win_charsize(cstype, vcol, ci.ptr, ci.chr.value, &csarg).width;
if (vcol > end_vcol) {
break;
}
Expand Down
6 changes: 3 additions & 3 deletions src/nvim/getchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -2507,15 +2507,15 @@ static int vgetorpeek(bool advance)
ptr = get_cursor_line_ptr();
char *endptr = ptr + curwin->w_cursor.col;

CharsizeArg arg;
CSType cstype = init_charsize_arg(&arg, curwin, curwin->w_cursor.lnum, ptr);
CharsizeArg csarg;
CSType cstype = init_charsize_arg(&csarg, curwin, curwin->w_cursor.lnum, ptr);
StrCharInfo ci = utf_ptr2StrCharInfo(ptr);
int vcol = 0;
while (ci.ptr < endptr) {
if (!ascii_iswhite(ci.chr.value)) {
curwin->w_wcol = vcol;
}
vcol += win_charsize(cstype, vcol, ci.ptr, ci.chr.value, &arg).width;
vcol += win_charsize(cstype, vcol, ci.ptr, ci.chr.value, &csarg).width;
ci = utfc_next(ci);
}

Expand Down
14 changes: 7 additions & 7 deletions src/nvim/indent.c
Original file line number Diff line number Diff line change
Expand Up @@ -1248,13 +1248,13 @@ int get_lisp_indent(void)

char *line = get_cursor_line_ptr();

CharsizeArg arg;
CSType cstype = init_charsize_arg(&arg, curwin, pos->lnum, line);
CharsizeArg csarg;
CSType cstype = init_charsize_arg(&csarg, curwin, pos->lnum, line);

StrCharInfo sci = utf_ptr2StrCharInfo(line);
amount = 0;
while (*sci.ptr != NUL && col > 0) {
amount += win_charsize(cstype, amount, sci.ptr, sci.chr.value, &arg).width;
amount += win_charsize(cstype, amount, sci.ptr, sci.chr.value, &csarg).width;
sci = utfc_next(sci);
col--;
}
Expand All @@ -1274,7 +1274,7 @@ int get_lisp_indent(void)
colnr_T firsttry = amount;

while (ascii_iswhite(*that)) {
amount += win_charsize(cstype, amount, that, (uint8_t)(*that), &arg).width;
amount += win_charsize(cstype, amount, that, (uint8_t)(*that), &csarg).width;
that++;
}

Expand Down Expand Up @@ -1303,21 +1303,21 @@ int get_lisp_indent(void)
parencount--;
}
if ((ci.value == '\\') && (*(that + 1) != NUL)) {
amount += win_charsize(cstype, amount, that, ci.value, &arg).width;
amount += win_charsize(cstype, amount, that, ci.value, &csarg).width;
StrCharInfo next_sci = utfc_next((StrCharInfo){ that, ci });
that = next_sci.ptr;
ci = next_sci.chr;
}

amount += win_charsize(cstype, amount, that, ci.value, &arg).width;
amount += win_charsize(cstype, amount, that, ci.value, &csarg).width;
StrCharInfo next_sci = utfc_next((StrCharInfo){ that, ci });
that = next_sci.ptr;
ci = next_sci.chr;
}
}

while (ascii_iswhite(*that)) {
amount += win_charsize(cstype, amount, that, (uint8_t)(*that), &arg).width;
amount += win_charsize(cstype, amount, that, (uint8_t)(*that), &csarg).width;
that++;
}

Expand Down
6 changes: 3 additions & 3 deletions src/nvim/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -1755,12 +1755,12 @@ colnr_T vcol2col(win_T *wp, linenr_T lnum, colnr_T vcol, colnr_T *coladdp)
{
// try to advance to the specified column
char *line = ml_get_buf(wp->w_buffer, lnum);
CharsizeArg arg;
CSType cstype = init_charsize_arg(&arg, wp, lnum, line);
CharsizeArg csarg;
CSType cstype = init_charsize_arg(&csarg, wp, lnum, line);
StrCharInfo ci = utf_ptr2StrCharInfo(line);
int cur_vcol = 0;
while (cur_vcol < vcol && *ci.ptr != NUL) {
int next_vcol = cur_vcol + win_charsize(cstype, cur_vcol, ci.ptr, ci.chr.value, &arg).width;
int next_vcol = cur_vcol + win_charsize(cstype, cur_vcol, ci.ptr, ci.chr.value, &csarg).width;
if (next_vcol > vcol) {
break;
}
Expand Down
36 changes: 18 additions & 18 deletions src/nvim/ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,12 @@ static void shift_block(oparg_T *oap, int amount)
}

// TODO(vim): is passing bd.textstart for start of the line OK?
CharsizeArg arg;
CSType cstype = init_charsize_arg(&arg, curwin, curwin->w_cursor.lnum, bd.textstart);
CharsizeArg csarg;
CSType cstype = init_charsize_arg(&csarg, curwin, curwin->w_cursor.lnum, bd.textstart);
StrCharInfo ci = utf_ptr2StrCharInfo(bd.textstart);
int vcol = bd.start_vcol;
while (ascii_iswhite(ci.chr.value)) {
incr = win_charsize(cstype, vcol, ci.ptr, ci.chr.value, &arg).width;
incr = win_charsize(cstype, vcol, ci.ptr, ci.chr.value, &csarg).width;
ci = utfc_next(ci);
total += incr;
vcol += incr;
Expand Down Expand Up @@ -449,10 +449,10 @@ static void shift_block(oparg_T *oap, int amount)
// The character's column is in "bd.start_vcol".
colnr_T non_white_col = bd.start_vcol;

CharsizeArg arg;
CSType cstype = init_charsize_arg(&arg, curwin, curwin->w_cursor.lnum, bd.textstart);
CharsizeArg csarg;
CSType cstype = init_charsize_arg(&csarg, curwin, curwin->w_cursor.lnum, bd.textstart);
while (ascii_iswhite(*non_white)) {
incr = win_charsize(cstype, non_white_col, non_white, (uint8_t)(*non_white), &arg).width;
incr = win_charsize(cstype, non_white_col, non_white, (uint8_t)(*non_white), &csarg).width;
non_white_col += incr;
non_white++;
}
Expand All @@ -476,10 +476,10 @@ static void shift_block(oparg_T *oap, int amount)
if (bd.startspaces) {
verbatim_copy_width -= bd.start_char_vcols;
}
cstype = init_charsize_arg(&arg, curwin, 0, bd.textstart);
cstype = init_charsize_arg(&csarg, curwin, 0, bd.textstart);
StrCharInfo ci = utf_ptr2StrCharInfo(verbatim_copy_end);
while (verbatim_copy_width < destination_col) {
incr = win_charsize(cstype, verbatim_copy_width, ci.ptr, ci.chr.value, &arg).width;
incr = win_charsize(cstype, verbatim_copy_width, ci.ptr, ci.chr.value, &csarg).width;
if (verbatim_copy_width + incr > destination_col) {
break;
}
Expand Down Expand Up @@ -3247,12 +3247,12 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
// get the old line and advance to the position to insert at
char *oldp = get_cursor_line_ptr();

CharsizeArg arg;
CSType cstype = init_charsize_arg(&arg, curwin, curwin->w_cursor.lnum, oldp);
CharsizeArg csarg;
CSType cstype = init_charsize_arg(&csarg, curwin, curwin->w_cursor.lnum, oldp);
StrCharInfo ci = utf_ptr2StrCharInfo(oldp);
vcol = 0;
while (vcol < col && *ci.ptr != NUL) {
incr = win_charsize(cstype, vcol, ci.ptr, ci.chr.value, &arg).width;
incr = win_charsize(cstype, vcol, ci.ptr, ci.chr.value, &csarg).width;
vcol += incr;
ci = utfc_next(ci);
}
Expand Down Expand Up @@ -3285,10 +3285,10 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags)
// calculate number of spaces required to fill right side of block
spaces = y_width + 1;

cstype = init_charsize_arg(&arg, curwin, 0, y_array[i]);
cstype = init_charsize_arg(&csarg, curwin, 0, y_array[i]);
ci = utf_ptr2StrCharInfo(y_array[i]);
while (*ci.ptr != NUL) {
spaces -= win_charsize(cstype, 0, ci.ptr, ci.chr.value, &arg).width;
spaces -= win_charsize(cstype, 0, ci.ptr, ci.chr.value, &csarg).width;
ci = utfc_next(ci);
}
if (spaces < 0) {
Expand Down Expand Up @@ -4223,12 +4223,12 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool
char *line = ml_get(lnum);
char *prev_pstart = line;

CharsizeArg arg;
CSType cstype = init_charsize_arg(&arg, curwin, lnum, line);
CharsizeArg csarg;
CSType cstype = init_charsize_arg(&csarg, curwin, lnum, line);
StrCharInfo ci = utf_ptr2StrCharInfo(line);
int vcol = bdp->start_vcol;
while (vcol < oap->start_vcol && *ci.ptr != NUL) {
incr = win_charsize(cstype, vcol, ci.ptr, ci.chr.value, &arg).width;
incr = win_charsize(cstype, vcol, ci.ptr, ci.chr.value, &csarg).width;
vcol += incr;
if (ascii_iswhite(ci.chr.value)) {
bdp->pre_whitesp += incr;
Expand Down Expand Up @@ -4278,13 +4278,13 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool
}
}
} else {
cstype = init_charsize_arg(&arg, curwin, lnum, line);
cstype = init_charsize_arg(&csarg, curwin, lnum, line);
ci = utf_ptr2StrCharInfo(pend);
vcol = bdp->end_vcol;
char *prev_pend = pend;
while (vcol <= oap->end_vcol && *ci.ptr != NUL) {
prev_pend = ci.ptr;
incr = win_charsize(cstype, vcol, ci.ptr, ci.chr.value, &arg).width;
incr = win_charsize(cstype, vcol, ci.ptr, ci.chr.value, &csarg).width;
vcol += incr;
ci = utfc_next(ci);
}
Expand Down
Loading

0 comments on commit e68deca

Please sign in to comment.