From fb1edb2f5728d74ae811c6ab32395598cea5609b Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/ops.c | 203 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 101 insertions(+), 102 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 4f2b84d20f..adb071b754 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -272,7 +272,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount) // Set "'[" and "']" marks. curbuf->b_op_start = oap->start; curbuf->b_op_end.lnum = oap->end.lnum; - curbuf->b_op_end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); + curbuf->b_op_end.col = (colnr_T)strlen(ml_get(oap->end.lnum)); if (curbuf->b_op_end.col > 0) { curbuf->b_op_end.col--; } @@ -382,7 +382,7 @@ static void shift_block(oparg_T *oap, int amount) // TODO(vim): is passing bd.textstart for start of the line OK? chartabsize_T cts; init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, - bd.start_vcol, bd.textstart, bd.textstart); + bd.start_vcol, (char *)bd.textstart, (char *)bd.textstart); while (ascii_iswhite(*cts.cts_ptr)) { incr = lbr_chartabsize_adv(&cts); total += incr; @@ -448,7 +448,7 @@ static void shift_block(oparg_T *oap, int amount) chartabsize_T cts; init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, - non_white_col, bd.textstart, non_white); + non_white_col, (char *)bd.textstart, (char *)non_white); while (ascii_iswhite(*cts.cts_ptr)) { incr = lbr_chartabsize_adv(&cts); cts.cts_vcol += incr; @@ -477,7 +477,7 @@ static void shift_block(oparg_T *oap, int amount) verbatim_copy_width -= bd.start_char_vcols; } init_chartabsize_arg(&cts, curwin, 0, verbatim_copy_width, - bd.textstart, verbatim_copy_end); + (char *)bd.textstart, (char *)verbatim_copy_end); while (cts.cts_vcol < destination_col) { incr = lbr_chartabsize(&cts); if (cts.cts_vcol + incr > destination_col) { @@ -543,7 +543,7 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def continue; // OP_INSERT, line ends before block start } - oldp = ml_get(lnum); + oldp = (char_u *)ml_get(lnum); if (b_insert) { ts_val = bdp->start_char_vcols; @@ -572,7 +572,7 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def if (spaces > 0) { // avoid copying part of a multi-byte character - offset -= utf_head_off(oldp, oldp + offset); + offset -= utf_head_off((char *)oldp, (char *)oldp + offset); } if (spaces < 0) { // can happen when the cursor was moved spaces = 0; @@ -1014,7 +1014,7 @@ static int stuff_yank(int regname, char_u *p) yankreg_T *reg = get_yank_register(regname, YREG_YANK); if (is_append_register(regname) && reg->y_array != NULL) { char **pp = &(reg->y_array[reg->y_size - 1]); - char_u *lp = xmalloc(STRLEN(*pp) + STRLEN(p) + 1); + char_u *lp = xmalloc(strlen(*pp) + STRLEN(p) + 1); STRCPY(lp, *pp); // TODO(philix): use xstpcpy() in stuff_yank() STRCAT(lp, p); @@ -1513,7 +1513,7 @@ int op_delete(oparg_T *oap) && oap->line_count > 1 && oap->motion_force == NUL && oap->op_type == OP_DELETE) { - ptr = ml_get(oap->end.lnum) + oap->end.col; + ptr = (char_u *)ml_get(oap->end.lnum) + oap->end.col; if (*ptr != NUL) { ptr += oap->inclusive; } @@ -1617,7 +1617,7 @@ int op_delete(oparg_T *oap) // If we delete a TAB, it may be replaced by several characters. // Thus the number of characters may increase! n = bd.textlen - bd.startspaces - bd.endspaces; - oldp = ml_get(lnum); + oldp = (char_u *)ml_get(lnum); newp = (char_u *)xmalloc(STRLEN(oldp) - (size_t)n + 1); // copy up to deleted part memmove(newp, oldp, (size_t)bd.textcol); @@ -1662,7 +1662,7 @@ int op_delete(oparg_T *oap) beginline(0); // cursor in column 0 } - int old_len = (int)STRLEN(ml_get(curwin->w_cursor.lnum)); + int old_len = (int)strlen(ml_get(curwin->w_cursor.lnum)); truncate_line(false); // delete the rest of the line extmark_splice_cols(curbuf, @@ -1816,7 +1816,7 @@ setmarks: static void mb_adjust_opend(oparg_T *oap) { if (oap->inclusive) { - char *p = (char *)ml_get(oap->end.lnum); + char *p = ml_get(oap->end.lnum); oap->end.col += utf_cp_tail_off(p, p + oap->end.col); } } @@ -1990,7 +1990,7 @@ static int op_replace(oparg_T *oap, int c) if (oap->motion_type == kMTLineWise) { oap->start.col = 0; curwin->w_cursor.col = 0; - oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); + oap->end.col = (colnr_T)strlen(ml_get(oap->end.lnum)); if (oap->end.col) { oap->end.col--; } @@ -2104,7 +2104,7 @@ void op_tilde(oparg_T *oap) if (oap->motion_type == kMTLineWise) { oap->start.col = 0; pos.col = 0; - oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); + oap->end.col = (colnr_T)strlen(ml_get(oap->end.lnum)); if (oap->end.col) { oap->end.col--; } @@ -2281,7 +2281,7 @@ void op_insert(oparg_T *oap, long count1) // Get indent information ind_pre_col = (colnr_T)getwhitecols_curline(); ind_pre_vcol = get_indent(); - firstline = ml_get(oap->start.lnum) + bd.textcol; + firstline = (char_u *)ml_get(oap->start.lnum) + bd.textcol; if (oap->op_type == OP_APPEND) { firstline += bd.textlen; @@ -2413,7 +2413,7 @@ void op_insert(oparg_T *oap, long count1) * Subsequent calls to ml_get() flush the firstline data - take a * copy of the required string. */ - firstline = ml_get(oap->start.lnum); + firstline = (char_u *)ml_get(oap->start.lnum); const size_t len = STRLEN(firstline); colnr_T add = bd.textcol; colnr_T offset = 0; // offset when cursor was moved in insert mode @@ -2498,7 +2498,7 @@ int op_change(oparg_T *oap) || gchar_cursor() == NUL)) { coladvance_force(getviscol()); } - firstline = ml_get(oap->start.lnum); + firstline = (char_u *)ml_get(oap->start.lnum); pre_textlen = (long)STRLEN(firstline); pre_indent = (long)getwhitecols((char *)firstline); bd.textcol = curwin->w_cursor.col; @@ -2519,7 +2519,7 @@ int op_change(oparg_T *oap) && oap->start.lnum != oap->end.lnum && !got_int) { // Auto-indenting may have changed the indent. If the cursor was past // the indent, exclude that indent change from the inserted text. - firstline = ml_get(oap->start.lnum); + firstline = (char_u *)ml_get(oap->start.lnum); if (bd.textcol > (colnr_T)pre_indent) { long new_indent = (long)getwhitecols((char *)firstline); @@ -2547,7 +2547,7 @@ int op_change(oparg_T *oap) } else { vpos.coladd = 0; } - oldp = ml_get(linenr); + oldp = (char_u *)ml_get(linenr); newp = xmalloc(STRLEN(oldp) + (size_t)vpos.coladd + (size_t)ins_len + 1); // copy up to block start @@ -2691,14 +2691,14 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) break; case kMTLineWise: - reg->y_array[y_idx] = (char *)vim_strsave(ml_get(lnum)); + reg->y_array[y_idx] = xstrdup(ml_get(lnum)); break; case kMTCharWise: { colnr_T startcol = 0, endcol = MAXCOL; int is_oneChar = false; colnr_T cs, ce; - p = ml_get(lnum); + p = (char_u *)ml_get(lnum); bd.startspaces = 0; bd.endspaces = 0; @@ -2724,7 +2724,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) // Don't add space for double-wide // char; endcol will be on last byte // of multi-byte char. - && utf_head_off(p, p + endcol) == 0)) { + && utf_head_off((char *)p, (char *)p + endcol) == 0)) { if (oap->start.lnum == oap->end.lnum && oap->start.col == oap->end.col) { // Special case: inside a single char @@ -2776,8 +2776,8 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) // the new block, unless being Vi compatible. if (curr->y_type == kMTCharWise && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) { - pnew = xmalloc(STRLEN(curr->y_array[curr->y_size - 1]) - + STRLEN(reg->y_array[0]) + 1); + pnew = xmalloc(strlen(curr->y_array[curr->y_size - 1]) + + strlen(reg->y_array[0]) + 1); STRCPY(pnew, curr->y_array[--j]); STRCAT(pnew, reg->y_array[0]); xfree(curr->y_array[j]); @@ -2857,7 +2857,7 @@ static void yank_copy_line(yankreg_T *reg, struct block_def *bd, size_t y_idx, int s = bd->textlen + bd->endspaces; while (s > 0 && ascii_iswhite(*(bd->textstart + s - 1))) { - s = s - utf_head_off(bd->textstart, bd->textstart + s - 1) - 1; + s = s - utf_head_off((char *)bd->textstart, (char *)bd->textstart + s - 1) - 1; pnew--; } } @@ -3299,7 +3299,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) oldlen = STRLEN(oldp); chartabsize_T cts; init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, 0, - oldp, oldp); + (char *)oldp, (char *)oldp); while (cts.cts_vcol < col && *cts.cts_ptr != NUL) { // Count a tab for what it's worth (if list mode not on) @@ -3320,7 +3320,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) bd.startspaces = incr - bd.endspaces; bd.textcol--; delcount = 1; - bd.textcol -= utf_head_off(oldp, oldp + bd.textcol); + bd.textcol -= utf_head_off((char *)oldp, (char *)oldp + bd.textcol); if (oldp[bd.textcol] != TAB) { /* Only a Tab can be split into spaces. Other * characters will have to be moved to after the @@ -3336,8 +3336,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // calculate number of spaces required to fill right side of // block spaces = y_width + 1; - init_chartabsize_arg(&cts, curwin, 0, 0, - (char_u *)y_array[i], (char_u *)y_array[i]); + init_chartabsize_arg(&cts, curwin, 0, 0, y_array[i], y_array[i]); for (int j = 0; j < yanklen; j++) { spaces -= lbr_chartabsize(&cts); cts.cts_ptr++; @@ -3483,7 +3482,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } else { totlen = (size_t)(count * yanklen); do { - oldp = ml_get(lnum); + oldp = (char_u *)ml_get(lnum); oldlen = STRLEN(oldp); if (lnum > start_lnum) { pos_T pos = { @@ -3510,7 +3509,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) ml_replace(lnum, (char *)newp, false); // compute the byte offset for the last character - first_byte_off = utf_head_off(newp, ptr - 1); + first_byte_off = utf_head_off((char *)newp, (char *)ptr - 1); // Place cursor on last putted char. if (lnum == curwin->w_cursor.lnum) { @@ -3554,7 +3553,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // First insert y_array[size - 1] in front of second line. // Then append y_array[0] to first line. lnum = new_cursor.lnum; - ptr = ml_get(lnum) + col; + ptr = (char_u *)ml_get(lnum) + col; totlen = STRLEN(y_array[y_size - 1]); newp = (char_u *)xmalloc((size_t)(STRLEN(ptr) + totlen + 1)); STRCPY(newp, y_array[y_size - 1]); @@ -3564,7 +3563,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) new_lnum++; xfree(newp); - oldp = ml_get(lnum); + oldp = (char_u *)ml_get(lnum); newp = (char_u *)xmalloc((size_t)col + (size_t)yanklen + 1); // copy first part of line memmove(newp, oldp, (size_t)col); @@ -3588,7 +3587,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (flags & PUT_FIXINDENT) { old_pos = curwin->w_cursor; curwin->w_cursor.lnum = lnum; - ptr = ml_get(lnum); + ptr = (char_u *)ml_get(lnum); if (cnt == count && i == y_size - 1) { lendiff = (int)STRLEN(ptr); } @@ -3668,8 +3667,8 @@ error: if (col > 1) { curbuf->b_op_end.col = col - 1; if (len > 0) { - curbuf->b_op_end.col -= utf_head_off((char_u *)y_array[y_size - 1], - (char_u *)y_array[y_size - 1] + len - 1); + curbuf->b_op_end.col -= utf_head_off(y_array[y_size - 1], + y_array[y_size - 1] + len - 1); } } else { curbuf->b_op_end.col = 0; @@ -3878,14 +3877,14 @@ void ex_display(exarg_T *eap) && (arg == NULL || vim_strchr((char *)arg, '.') != NULL) && !got_int && !message_filtered((char *)p)) { msg_puts("\n c \". "); - dis_msg(p, true); + dis_msg((char *)p, true); } // display last command line if (last_cmdline != NULL && (arg == NULL || vim_strchr((char *)arg, ':') != NULL) && !got_int && !message_filtered(last_cmdline)) { msg_puts("\n c \": "); - dis_msg((char_u *)last_cmdline, false); + dis_msg(last_cmdline, false); } // display current file name @@ -3893,7 +3892,7 @@ void ex_display(exarg_T *eap) && (arg == NULL || vim_strchr((char *)arg, '%') != NULL) && !got_int && !message_filtered(curbuf->b_fname)) { msg_puts("\n c \"% "); - dis_msg((char_u *)curbuf->b_fname, false); + dis_msg(curbuf->b_fname, false); } // display alternate file name @@ -3903,7 +3902,7 @@ void ex_display(exarg_T *eap) if (buflist_name_nr(0, &fname, &dummy) != FAIL && !message_filtered(fname)) { msg_puts("\n c \"# "); - dis_msg((char_u *)fname, false); + dis_msg(fname, false); } } @@ -3912,14 +3911,14 @@ void ex_display(exarg_T *eap) && (arg == NULL || vim_strchr((char *)arg, '/') != NULL) && !got_int && !message_filtered((char *)last_search_pat())) { msg_puts("\n c \"/ "); - dis_msg(last_search_pat(), false); + dis_msg((char *)last_search_pat(), false); } // display last used expression if (expr_line != NULL && (arg == NULL || vim_strchr((char *)arg, '=') != NULL) && !got_int && !message_filtered((char *)expr_line)) { msg_puts("\n c \"= "); - dis_msg(expr_line, false); + dis_msg((char *)expr_line, false); } } @@ -3927,7 +3926,7 @@ void ex_display(exarg_T *eap) /// truncate at end of screen line /// /// @param skip_esc if true, ignore trailing ESC -static void dis_msg(const char_u *p, bool skip_esc) +static void dis_msg(const char *p, bool skip_esc) FUNC_ATTR_NONNULL_ALL { int n; @@ -3936,12 +3935,12 @@ static void dis_msg(const char_u *p, bool skip_esc) n = Columns - 6; while (*p != NUL && !(*p == ESC && skip_esc && *(p + 1) == NUL) - && (n -= ptr2cells((char *)p)) >= 0) { - if ((l = utfc_ptr2len((char *)p)) > 1) { - msg_outtrans_len((char *)p, l); + && (n -= ptr2cells(p)) >= 0) { + if ((l = utfc_ptr2len(p)) > 1) { + msg_outtrans_len(p, l); p += l; } else { - msg_outtrans_len((char *)p++, 1); + msg_outtrans_len(p++, 1); } } os_breakcheck(); @@ -3958,11 +3957,11 @@ static void dis_msg(const char_u *p, bool skip_esc) /// @param include_space - whether to skip space following the comment leader /// @param[out] is_comment - whether the current line ends with an unclosed /// comment. -char_u *skip_comment(char_u *line, bool process, bool include_space, bool *is_comment) +char *skip_comment(char *line, bool process, bool include_space, bool *is_comment) { char *comment_flags = NULL; int lead_len; - int leader_offset = get_last_leader_offset((char *)line, &comment_flags); + int leader_offset = get_last_leader_offset(line, &comment_flags); *is_comment = false; if (leader_offset != -1) { @@ -3984,7 +3983,7 @@ char_u *skip_comment(char_u *line, bool process, bool include_space, bool *is_co return line; } - lead_len = get_leader_len((char *)line, &comment_flags, false, include_space); + lead_len = get_leader_len(line, &comment_flags, false, include_space); if (lead_len == 0) { return line; @@ -4022,11 +4021,11 @@ char_u *skip_comment(char_u *line, bool process, bool include_space, bool *is_co /// @return FAIL for failure, OK otherwise int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions, bool setmark) { - char_u *curr = NULL; - char_u *curr_start = NULL; - char_u *cend; - char_u *newp; - char_u *spaces; // number of spaces inserted before a line + char *curr = NULL; + char *curr_start = NULL; + char *cend; + char *newp; + char *spaces; // number of spaces inserted before a line int endcurr1 = NUL; int endcurr2 = NUL; int currsize = 0; // size of the current line @@ -4055,7 +4054,8 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions // Don't move anything, just compute the final line length // and setup the array of space strings lengths for (t = 0; t < (linenr_T)count; t++) { - curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); + curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); + curr = curr_start; if (t == 0 && setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { // Set the '[ mark. curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; @@ -4065,8 +4065,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions // We don't want to remove the comment leader if the // previous line is not a comment. if (t > 0 && prev_was_comment) { - char_u *new_curr = skip_comment(curr, true, insert_space, - &prev_was_comment); + char *new_curr = skip_comment(curr, true, insert_space, &prev_was_comment); comments[t] = (int)(new_curr - curr); curr = new_curr; } else { @@ -4075,17 +4074,17 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions } if (insert_space && t > 0) { - curr = (char_u *)skipwhite((char *)curr); + curr = skipwhite(curr); if (*curr != NUL && *curr != ')' && sumsize != 0 && endcurr1 != TAB && (!has_format_option(FO_MBYTE_JOIN) - || (utf_ptr2char((char *)curr) < 0x100 && endcurr1 < 0x100)) + || (utf_ptr2char(curr) < 0x100 && endcurr1 < 0x100)) && (!has_format_option(FO_MBYTE_JOIN2) - || (utf_ptr2char((char *)curr) < 0x100 && !utf_eat_space(endcurr1)) + || (utf_ptr2char(curr) < 0x100 && !utf_eat_space(endcurr1)) || (endcurr1 < 0x100 - && !utf_eat_space(utf_ptr2char((char *)curr))))) { + && !utf_eat_space(utf_ptr2char(curr))))) { // don't add a space if the line is ending in a space if (endcurr1 == ' ') { endcurr1 = endcurr2; @@ -4112,10 +4111,10 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions if (insert_space && currsize > 0) { cend = curr + currsize; MB_PTR_BACK(curr, cend); - endcurr1 = utf_ptr2char((char *)cend); + endcurr1 = utf_ptr2char(cend); if (cend > curr) { MB_PTR_BACK(curr, cend); - endcurr2 = utf_ptr2char((char *)cend); + endcurr2 = utf_ptr2char(cend); } } line_breakcheck(); @@ -4129,7 +4128,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions col = sumsize - currsize - spaces[count - 1]; // allocate the space for the new line - newp = (char_u *)xmalloc((size_t)sumsize + 1); + newp = xmalloc((size_t)sumsize + 1); cend = newp + sumsize; *cend = 0; @@ -4165,17 +4164,18 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions break; } - curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); + curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); + curr = curr_start; if (remove_comments) { curr += comments[t - 1]; } if (insert_space && t > 1) { - curr = (char_u *)skipwhite((char *)curr); + curr = skipwhite(curr); } currsize = (int)STRLEN(curr); } - ml_replace(curwin->w_cursor.lnum, (char *)newp, false); + ml_replace(curwin->w_cursor.lnum, newp, false); if (setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { // Set the '] mark. @@ -4234,11 +4234,11 @@ theend: static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool is_del) { int incr = 0; - char_u *pend; - char_u *pstart; - char_u *line; - char_u *prev_pstart; - char_u *prev_pend; + char *pend; + char *pstart; + char *line; + char *prev_pstart; + char *prev_pend; const int lbr_saved = curwin->w_p_lbr; // Avoid a problem with unwanted linebreaks in block mode. @@ -4271,11 +4271,11 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool bdp->pre_whitesp = 0; bdp->pre_whitesp_c = 0; } - prev_pstart = (char_u *)cts.cts_ptr; + prev_pstart = cts.cts_ptr; MB_PTR_ADV(cts.cts_ptr); } bdp->start_vcol = cts.cts_vcol; - pstart = (char_u *)cts.cts_ptr; + pstart = cts.cts_ptr; clear_chartabsize_arg(&cts); bdp->start_char_vcols = incr; @@ -4313,17 +4313,16 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool } } } else { - init_chartabsize_arg(&cts, curwin, lnum, bdp->end_vcol, - line, pend); + init_chartabsize_arg(&cts, curwin, lnum, bdp->end_vcol, line, pend); prev_pend = pend; while (cts.cts_vcol <= oap->end_vcol && *cts.cts_ptr != NUL) { // Count a tab for what it's worth (if list mode not on) - prev_pend = (char_u *)cts.cts_ptr; + prev_pend = cts.cts_ptr; incr = lbr_chartabsize_adv(&cts); cts.cts_vcol += incr; } bdp->end_vcol = cts.cts_vcol; - pend = (char_u *)cts.cts_ptr; + pend = cts.cts_ptr; clear_chartabsize_arg(&cts); if (bdp->end_vcol <= oap->end_vcol @@ -4356,7 +4355,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool bdp->textlen = (int)(pend - pstart); } bdp->textcol = (colnr_T)(pstart - line); - bdp->textstart = pstart; + bdp->textstart = (char_u *)pstart; curwin->w_p_lbr = lbr_saved; } @@ -4511,7 +4510,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) } curwin->w_cursor = *pos; - ptr = ml_get(pos->lnum); + ptr = (char_u *)ml_get(pos->lnum); col = pos->col; if (*ptr == NUL || col + !!save_coladd >= (int)STRLEN(ptr)) { @@ -4523,14 +4522,14 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) if (do_bin) { while (col > 0 && ascii_isbdigit(ptr[col])) { col--; - col -= utf_head_off(ptr, ptr + col); + col -= utf_head_off((char *)ptr, (char *)ptr + col); } } if (do_hex) { while (col > 0 && ascii_isxdigit(ptr[col])) { col--; - col -= utf_head_off(ptr, ptr + col); + col -= utf_head_off((char *)ptr, (char *)ptr + col); } } if (do_bin @@ -4538,7 +4537,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) && !((col > 0 && (ptr[col] == 'X' || ptr[col] == 'x') && ptr[col - 1] == '0' - && !utf_head_off(ptr, ptr + col - 1) + && !utf_head_off((char *)ptr, (char *)ptr + col - 1) && ascii_isxdigit(ptr[col + 1])))) { // In case of binary/hexadecimal pattern overlap match, rescan @@ -4546,7 +4545,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) while (col > 0 && ascii_isdigit(ptr[col])) { col--; - col -= utf_head_off(ptr, ptr + col); + col -= utf_head_off((char *)ptr, (char *)ptr + col); } } @@ -4554,17 +4553,17 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) && col > 0 && (ptr[col] == 'X' || ptr[col] == 'x') && ptr[col - 1] == '0' - && !utf_head_off(ptr, ptr + col - 1) + && !utf_head_off((char *)ptr, (char *)ptr + col - 1) && ascii_isxdigit(ptr[col + 1])) || (do_bin && col > 0 && (ptr[col] == 'B' || ptr[col] == 'b') && ptr[col - 1] == '0' - && !utf_head_off(ptr, ptr + col - 1) + && !utf_head_off((char *)ptr, (char *)ptr + col - 1) && ascii_isbdigit(ptr[col + 1]))) { // Found hexadecimal or binary number, move to its start. col--; - col -= utf_head_off(ptr, ptr + col); + col -= utf_head_off((char *)ptr, (char *)ptr + col); } else { // Search forward and then backward to find the start of number. col = pos->col; @@ -4597,7 +4596,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) } if (col > pos->col && ptr[col - 1] == '-' - && !utf_head_off(ptr, ptr + col - 1) + && !utf_head_off((char *)ptr, (char *)ptr + col - 1) && !do_unsigned) { negative = true; was_positive = false; @@ -4643,7 +4642,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) curwin->w_cursor.col = col; } else { if (col > 0 && ptr[col - 1] == '-' - && !utf_head_off(ptr, ptr + col - 1) + && !utf_head_off((char *)ptr, (char *)ptr + col - 1) && !visual && !do_unsigned) { // negative number @@ -5036,7 +5035,7 @@ static void finish_write_reg(int name, yankreg_T *reg, yankreg_T *old_y_previous /// store `str` in register `name` /// /// @see write_reg_contents_ex -void write_reg_contents(int name, const char_u *str, ssize_t len, int must_append) +void write_reg_contents(int name, const char *str, ssize_t len, int must_append) { write_reg_contents_ex(name, str, len, must_append, kMTUnknown, 0L); } @@ -5045,9 +5044,9 @@ void write_reg_contents_lst(int name, char **strings, bool must_append, MotionTy colnr_T block_len) { if (name == '/' || name == '=') { - char_u *s = (char_u *)strings[0]; + char *s = strings[0]; if (strings[0] == NULL) { - s = (char_u *)""; + s = ""; } else if (strings[1] != NULL) { emsg(_("E883: search pattern and expression register may not " "contain two or more lines")); @@ -5067,7 +5066,7 @@ void write_reg_contents_lst(int name, char **strings, bool must_append, MotionTy return; } - str_to_reg(reg, yank_type, (char *)strings, STRLEN((char_u *)strings), + str_to_reg(reg, yank_type, (char *)strings, STRLEN(strings), block_len, true); finish_write_reg(name, reg, old_y_previous); } @@ -5090,7 +5089,7 @@ void write_reg_contents_lst(int name, char **strings, bool must_append, MotionTy /// is an uppercase letter. /// @param yank_type The motion type (kMTUnknown to auto detect) /// @param block_len width of visual block -void write_reg_contents_ex(int name, const char_u *str, ssize_t len, bool must_append, +void write_reg_contents_ex(int name, const char *str, ssize_t len, bool must_append, MotionType yank_type, colnr_T block_len) { if (len < 0) { @@ -5099,7 +5098,7 @@ void write_reg_contents_ex(int name, const char_u *str, ssize_t len, bool must_a // Special case: '/' search pattern if (name == '/') { - set_last_search_pat(str, RE_SEARCH, true, true); + set_last_search_pat((char_u *)str, RE_SEARCH, true, true); return; } @@ -5107,14 +5106,14 @@ void write_reg_contents_ex(int name, const char_u *str, ssize_t len, bool must_a buf_T *buf; if (ascii_isdigit(*str)) { - int num = atoi((char *)str); + int num = atoi(str); buf = buflist_findnr(num); if (buf == NULL) { semsg(_(e_nobufnr), (int64_t)num); } } else { - buf = buflist_findnr(buflist_findpat((char *)str, (char *)str + STRLEN(str), + buf = buflist_findnr(buflist_findpat(str, str + STRLEN(str), true, false, false)); } if (buf == NULL) { @@ -5155,7 +5154,7 @@ void write_reg_contents_ex(int name, const char_u *str, ssize_t len, bool must_a if (!(reg = init_write_reg(name, &old_y_previous, must_append))) { return; } - str_to_reg(reg, yank_type, (char *)str, (size_t)len, block_len, false); + str_to_reg(reg, yank_type, str, (size_t)len, block_len, false); finish_write_reg(name, reg, old_y_previous); } @@ -5425,7 +5424,7 @@ void cursor_pos_info(dict_T *dict) len = (long)bd.textlen; break; case 'V': - s = ml_get(lnum); + s = (char_u *)ml_get(lnum); len = MAXCOL; break; case 'v': { @@ -5434,7 +5433,7 @@ void cursor_pos_info(dict_T *dict) colnr_T end_col = (lnum == max_pos.lnum) ? max_pos.col - start_col + 1 : MAXCOL; - s = ml_get(lnum) + start_col; + s = (char_u *)ml_get(lnum) + start_col; len = end_col; } break; @@ -5455,14 +5454,14 @@ void cursor_pos_info(dict_T *dict) word_count_cursor += word_count; char_count_cursor += char_count; byte_count_cursor = byte_count - + line_count_info(ml_get(lnum), &word_count_cursor, + + line_count_info((char_u *)ml_get(lnum), &word_count_cursor, &char_count_cursor, (varnumber_T)curwin->w_cursor.col + 1, eol_size); } } // Add to the running totals - byte_count += line_count_info(ml_get(lnum), &word_count, &char_count, + byte_count += line_count_info((char_u *)ml_get(lnum), &word_count, &char_count, (varnumber_T)MAXCOL, eol_size); } -- cgit From 5f92d9b345e11adb73df33dc22a8e656aca73b6c Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 1 Sep 2022 09:44:01 +0200 Subject: perf(messages): don't call ui_flush() per message line in various places When msgsep is used, message scrolling is emulated. To make message output fast, inhibit emulated scrolling until the full message text is known --- src/nvim/ops.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index adb071b754..d2321be4a4 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3866,7 +3866,6 @@ void ex_display(exarg_T *eap) if (n > 1 && yb->y_type == kMTLineWise) { msg_puts_attr("^J", attr); } - ui_flush(); // show one line at a time } os_breakcheck(); } -- cgit From 49e893f296bca9eef5ff45a3d746c261d055bf10 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/ops.c | 82 ++++++++++++++++++++++++++++------------------------------ 1 file changed, 40 insertions(+), 42 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d2321be4a4..01fd4bb9a7 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -225,7 +225,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount) } for (i = oap->line_count - 1; i >= 0; i--) { - first_char = *get_cursor_line_ptr(); + first_char = (uint8_t)(*get_cursor_line_ptr()); if (first_char == NUL) { // empty line curwin->w_cursor.col = 0; } else if (oap->motion_type == kMTBlockWise) { @@ -356,7 +356,7 @@ static void shift_block(oparg_T *oap, int amount) return; // multiplication overflow } - char_u *const oldp = get_cursor_line_ptr(); + char_u *const oldp = (char_u *)get_cursor_line_ptr(); int startcol, oldlen, newlen; @@ -668,7 +668,7 @@ void op_reindent(oparg_T *oap, Indenter how) // indented, unless there is only one line. if (i != oap->line_count - 1 || oap->line_count == 1 || how != get_lisp_indent) { - l = (char_u *)skipwhite((char *)get_cursor_line_ptr()); + l = (char_u *)skipwhite(get_cursor_line_ptr()); if (*l == NUL) { // empty or blank line amount = 0; } else { @@ -1735,7 +1735,7 @@ int op_delete(oparg_T *oap) if (virtual_op) { // fix up things for virtualedit-delete: // break the tabs which are going to get in our way - char_u *curline = get_cursor_line_ptr(); + char_u *curline = (char_u *)get_cursor_line_ptr(); int len = (int)STRLEN(curline); if (oap->end.coladd != 0 @@ -1926,7 +1926,7 @@ static int op_replace(oparg_T *oap, int c) num_chars = numc; numc *= utf_char2len(c); - oldp = get_cursor_line_ptr(); + oldp = (char_u *)get_cursor_line_ptr(); oldlen = (int)STRLEN(oldp); size_t newp_size = (size_t)bd.textcol + (size_t)bd.startspaces; @@ -2240,7 +2240,7 @@ bool swapchar(int op_type, pos_T *pos) void op_insert(oparg_T *oap, long count1) { long ins_len, pre_textlen = 0; - char_u *firstline, *ins_text; + char *firstline, *ins_text; colnr_T ind_pre_col = 0, ind_post_col; int ind_pre_vcol = 0, ind_post_vcol = 0; struct block_def bd; @@ -2281,7 +2281,7 @@ void op_insert(oparg_T *oap, long count1) // Get indent information ind_pre_col = (colnr_T)getwhitecols_curline(); ind_pre_vcol = get_indent(); - firstline = (char_u *)ml_get(oap->start.lnum) + bd.textcol; + firstline = ml_get(oap->start.lnum) + bd.textcol; if (oap->op_type == OP_APPEND) { firstline += bd.textlen; @@ -2413,7 +2413,7 @@ void op_insert(oparg_T *oap, long count1) * Subsequent calls to ml_get() flush the firstline data - take a * copy of the required string. */ - firstline = (char_u *)ml_get(oap->start.lnum); + firstline = ml_get(oap->start.lnum); const size_t len = STRLEN(firstline); colnr_T add = bd.textcol; colnr_T offset = 0; // offset when cursor was moved in insert mode @@ -2438,10 +2438,10 @@ void op_insert(oparg_T *oap, long count1) } ins_len = (long)STRLEN(firstline) - pre_textlen - offset; if (pre_textlen >= 0 && ins_len > 0) { - ins_text = vim_strnsave(firstline, (size_t)ins_len); + ins_text = xstrnsave(firstline, (size_t)ins_len); // block handled here if (u_save(oap->start.lnum, (linenr_T)(oap->end.lnum + 1)) == OK) { - block_insert(oap, ins_text, (oap->op_type == OP_INSERT), &bd); + block_insert(oap, (char_u *)ins_text, (oap->op_type == OP_INSERT), &bd); } curwin->w_cursor.col = oap->start.col; @@ -2934,9 +2934,9 @@ static void do_autocmd_textyankpost(oparg_T *oap, yankreg_T *reg) /// @param dir BACKWARD for 'P', FORWARD for 'p' void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) { - char_u *ptr; - char_u *newp; - char_u *oldp; + char *ptr; + char *newp; + char *oldp; int yanklen; size_t totlen = 0; // init for gcc linenr_T lnum = 0; @@ -3082,13 +3082,13 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) * Loop twice: count the number of lines and save them. */ for (;;) { y_size = 0; - ptr = (char_u *)insert_string; + ptr = insert_string; while (ptr != NULL) { if (y_array != NULL) { - y_array[y_size] = (char *)ptr; + y_array[y_size] = ptr; } y_size++; - ptr = (char_u *)vim_strchr((char *)ptr, '\n'); + ptr = vim_strchr(ptr, '\n'); if (ptr != NULL) { if (y_array != NULL) { *ptr = NUL; @@ -3136,12 +3136,12 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (u_save_cursor() == FAIL) { goto end; } - char_u *p = get_cursor_pos_ptr(); + char *p = (char *)get_cursor_pos_ptr(); if (dir == FORWARD && *p != NUL) { MB_PTR_ADV(p); } - ptr = vim_strsave(p); - ml_append(curwin->w_cursor.lnum, (char *)ptr, (colnr_T)0, false); + ptr = xstrdup(p); + ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, false); xfree(ptr); oldp = get_cursor_line_ptr(); @@ -3149,8 +3149,8 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (dir == FORWARD && *p != NUL) { MB_PTR_ADV(p); } - ptr = vim_strnsave(oldp, (size_t)(p - oldp)); - ml_replace(curwin->w_cursor.lnum, (char *)ptr, false); + ptr = xstrnsave(oldp, (size_t)(p - oldp)); + ml_replace(curwin->w_cursor.lnum, ptr, false); nr_lines++; dir = FORWARD; } @@ -3298,8 +3298,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) oldp = get_cursor_line_ptr(); oldlen = STRLEN(oldp); chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, 0, - (char *)oldp, (char *)oldp); + init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, 0, oldp, oldp); while (cts.cts_vcol < col && *cts.cts_ptr != NUL) { // Count a tab for what it's worth (if list mode not on) @@ -3307,7 +3306,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) cts.cts_vcol += incr; } vcol = cts.cts_vcol; - ptr = (char_u *)cts.cts_ptr; + ptr = cts.cts_ptr; bd.textcol = (colnr_T)(ptr - oldp); clear_chartabsize_arg(&cts); @@ -3320,7 +3319,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) bd.startspaces = incr - bd.endspaces; bd.textcol--; delcount = 1; - bd.textcol -= utf_head_off((char *)oldp, (char *)oldp + bd.textcol); + bd.textcol -= utf_head_off(oldp, oldp + bd.textcol); if (oldp[bd.textcol] != TAB) { /* Only a Tab can be split into spaces. Other * characters will have to be moved to after the @@ -3356,9 +3355,8 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) break; } - totlen = (size_t)(count * (yanklen + spaces) - + bd.startspaces + bd.endspaces); - newp = (char_u *)xmalloc(totlen + oldlen + 1); + totlen = (size_t)(count * (yanklen + spaces) + bd.startspaces + bd.endspaces); + newp = xmalloc(totlen + oldlen + 1); // copy part up to cursor to new line ptr = newp; @@ -3391,7 +3389,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) int columns = (int)oldlen - bd.textcol - delcount + 1; assert(columns >= 0); memmove(ptr, oldp + bd.textcol + delcount, (size_t)columns); - ml_replace(curwin->w_cursor.lnum, (char *)newp, false); + ml_replace(curwin->w_cursor.lnum, newp, false); extmark_splice_cols(curbuf, (int)curwin->w_cursor.lnum - 1, bd.textcol, delcount, (int)totlen + lines_appended, kExtmarkUndo); @@ -3482,7 +3480,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } else { totlen = (size_t)(count * yanklen); do { - oldp = (char_u *)ml_get(lnum); + oldp = ml_get(lnum); oldlen = STRLEN(oldp); if (lnum > start_lnum) { pos_T pos = { @@ -3498,7 +3496,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) lnum++; continue; } - newp = (char_u *)xmalloc(totlen + oldlen + 1); + newp = xmalloc(totlen + oldlen + 1); memmove(newp, oldp, (size_t)col); ptr = newp + col; for (i = 0; i < (size_t)count; i++) { @@ -3506,10 +3504,10 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) ptr += yanklen; } STRMOVE(ptr, oldp + col); - ml_replace(lnum, (char *)newp, false); + ml_replace(lnum, newp, false); // compute the byte offset for the last character - first_byte_off = utf_head_off((char *)newp, (char *)ptr - 1); + first_byte_off = utf_head_off(newp, ptr - 1); // Place cursor on last putted char. if (lnum == curwin->w_cursor.lnum) { @@ -3553,23 +3551,23 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // First insert y_array[size - 1] in front of second line. // Then append y_array[0] to first line. lnum = new_cursor.lnum; - ptr = (char_u *)ml_get(lnum) + col; + ptr = ml_get(lnum) + col; totlen = STRLEN(y_array[y_size - 1]); - newp = (char_u *)xmalloc((size_t)(STRLEN(ptr) + totlen + 1)); + newp = xmalloc((size_t)(STRLEN(ptr) + totlen + 1)); STRCPY(newp, y_array[y_size - 1]); STRCAT(newp, ptr); // insert second line - ml_append(lnum, (char *)newp, (colnr_T)0, false); + ml_append(lnum, newp, (colnr_T)0, false); new_lnum++; xfree(newp); - oldp = (char_u *)ml_get(lnum); - newp = (char_u *)xmalloc((size_t)col + (size_t)yanklen + 1); + oldp = ml_get(lnum); + newp = xmalloc((size_t)col + (size_t)yanklen + 1); // copy first part of line memmove(newp, oldp, (size_t)col); // append to first line memmove(newp + col, y_array[0], (size_t)yanklen + 1); - ml_replace(lnum, (char *)newp, false); + ml_replace(lnum, newp, false); curwin->w_cursor.lnum = lnum; i = 1; @@ -3587,7 +3585,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (flags & PUT_FIXINDENT) { old_pos = curwin->w_cursor; curwin->w_cursor.lnum = lnum; - ptr = (char_u *)ml_get(lnum); + ptr = ml_get(lnum); if (cnt == count && i == y_size - 1) { lendiff = (int)STRLEN(ptr); } @@ -4656,7 +4654,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) : length); } - vim_str2nr(ptr + col, &pre, &length, + vim_str2nr((char *)ptr + col, &pre, &length, 0 + (do_bin ? STR2NR_BIN : 0) + (do_oct ? STR2NR_OCT : 0) + (do_hex ? STR2NR_HEX : 0), @@ -5504,7 +5502,7 @@ void cursor_pos_info(dict_T *dict) (int64_t)byte_count_cursor, (int64_t)byte_count); } } else { - p = get_cursor_line_ptr(); + p = (char_u *)get_cursor_line_ptr(); validate_virtcol(); col_print((char *)buf1, sizeof(buf1), (int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1); -- cgit From 1ffd527c837fb2465c9659273bbe5447a1352db2 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 2 Sep 2022 17:39:49 +0100 Subject: refactor: migrate comment style (#20012) Done automatically using the following perl command: perl -pi -0777pe 's#\n\K */\*\n(.+?)\s*\*/\n#join("\n", map { $_ =~ s:^\s*\K \*://:; $_ } split("\n", $1)) . "\n"#sge' src/nvim/**/*.c Co-authored-by: zeertzjq Co-authored-by: zeertzjq --- src/nvim/ops.c | 166 ++++++++++++++++++++------------------------------------- 1 file changed, 58 insertions(+), 108 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 01fd4bb9a7..25b957e3b9 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1,10 +1,8 @@ // This is an open source non-commercial project. Dear PVS-Studio, please check // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com -/* - * ops.c: implementation of various operators: op_shift, op_delete, op_tilde, - * op_change, op_yank, do_put, do_join - */ +// ops.c: implementation of various operators: op_shift, op_delete, op_tilde, +// op_change, op_yank, do_put, do_join #include #include @@ -67,10 +65,8 @@ static bool clipboard_delay_update = false; // delay clipboard update static bool clipboard_needs_update = false; // clipboard was updated static bool clipboard_didwarn = false; -/* - * structure used by block_prep, op_delete and op_yank for blockwise operators - * also op_change, op_shift, op_insert, op_replace - AKelly - */ +// structure used by block_prep, op_delete and op_yank for blockwise operators +// also op_change, op_shift, op_insert, op_replace - AKelly struct block_def { int startspaces; // 'extra' cols before first char int endspaces; // 'extra' cols after last char @@ -96,11 +92,9 @@ struct block_def { #define OPF_LINES 1 // operator always works on lines #define OPF_CHANGE 2 // operator changes text -/* - * The names of operators. - * IMPORTANT: Index must correspond with defines in vim.h!!! - * The third field indicates whether the operator always works on lines. - */ +// The names of operators. +// IMPORTANT: Index must correspond with defines in vim.h!!! +// The third field indicates whether the operator always works on lines. static char opchars[][3] = { { NUL, NUL, 0 }, // OP_NOP @@ -361,12 +355,10 @@ static void shift_block(oparg_T *oap, int amount) int startcol, oldlen, newlen; if (!left) { - /* - * 1. Get start vcol - * 2. Total ws vcols - * 3. Divvy into TABs & spp - * 4. Construct new string - */ + // 1. Get start vcol + // 2. Total ws vcols + // 3. Divvy into TABs & spp + // 4. Construct new string total += bd.pre_whitesp; // all virtual WS up to & incl a split TAB colnr_T ws_vcol = bd.start_vcol - bd.pre_whitesp; char_u *old_textstart = bd.textstart; @@ -428,13 +420,11 @@ static void shift_block(oparg_T *oap, int amount) // block shift char_u *non_white = bd.textstart; - /* - * Firstly, let's find the first non-whitespace character that is - * displayed after the block's start column and the character's column - * number. Also, let's calculate the width of all the whitespace - * characters that are displayed in the block and precede the searched - * non-whitespace character. - */ + // Firstly, let's find the first non-whitespace character that is + // displayed after the block's start column and the character's column + // number. Also, let's calculate the width of all the whitespace + // characters that are displayed in the block and precede the searched + // non-whitespace character. // If "bd.startspaces" is set, "bd.textstart" points to the character, // the part of which is displayed at the block's beginning. Let's start @@ -715,9 +705,7 @@ void op_reindent(oparg_T *oap, Indenter how) } } -/* - * Keep the last expression line here, for repeating. - */ +// Keep the last expression line here, for repeating. static char_u *expr_line = NULL; /// Get an expression for the "\"=expr1" or "CTRL-R =expr1" @@ -1165,9 +1153,7 @@ int do_execreg(int regname, int colon, int addcr, int silent) // Disallow remapping for ":@r". int remap = colon ? REMAP_NONE : REMAP_YES; - /* - * Insert lines into typeahead buffer, from last one to first one. - */ + // Insert lines into typeahead buffer, from last one to first one. put_reedit_in_typebuf(silent); char *escaped; for (size_t i = reg->y_size; i-- > 0;) { // from y_size - 1 to 0 included @@ -1277,11 +1263,9 @@ int insert_reg(int regname, bool literally_arg) bool allocated; const bool literally = literally_arg || is_literal_register(regname); - /* - * It is possible to get into an endless loop by having CTRL-R a in - * register a and then, in insert mode, doing CTRL-R a. - * If you hit CTRL-C, the loop will be broken here. - */ + // It is possible to get into an endless loop by having CTRL-R a in + // register a and then, in insert mode, doing CTRL-R a. + // If you hit CTRL-C, the loop will be broken here. os_breakcheck(); if (got_int) { return FAIL; @@ -1503,11 +1487,9 @@ int op_delete(oparg_T *oap) mb_adjust_opend(oap); - /* - * Imitate the strange Vi behaviour: If the delete spans more than one - * line and motion_type == kMTCharWise and the result is a blank line, make the - * delete linewise. Don't do this for the change command or Visual mode. - */ + // Imitate the strange Vi behaviour: If the delete spans more than one + // line and motion_type == kMTCharWise and the result is a blank line, make the + // delete linewise. Don't do this for the change command or Visual mode. if (oap->motion_type == kMTCharWise && !oap->is_VIsual && oap->line_count > 1 @@ -1523,10 +1505,8 @@ int op_delete(oparg_T *oap) } } - /* - * Check for trying to delete (e.g. "D") in an empty line. - * Note: For the change operator it is ok. - */ + // Check for trying to delete (e.g. "D") in an empty line. + // Note: For the change operator it is ok. if (oap->motion_type != kMTLineWise && oap->line_count == 1 && oap->op_type == OP_DELETE @@ -1544,11 +1524,9 @@ int op_delete(oparg_T *oap) return OK; } - /* - * Do a yank of whatever we're about to delete. - * If a yank register was specified, put the deleted text into that - * register. For the black hole register '_' don't yank anything. - */ + // Do a yank of whatever we're about to delete. + // If a yank register was specified, put the deleted text into that + // register. For the black hole register '_' don't yank anything. if (oap->regname != '_') { yankreg_T *reg = NULL; int did_yank = false; @@ -1592,9 +1570,7 @@ int op_delete(oparg_T *oap) } } - /* - * block mode delete - */ + // block mode delete if (oap->motion_type == kMTBlockWise) { if (u_save((linenr_T)(oap->start.lnum - 1), (linenr_T)(oap->end.lnum + 1)) == FAIL) { @@ -1873,9 +1849,7 @@ static int op_replace(oparg_T *oap, int c) return FAIL; } - /* - * block mode replace - */ + // block mode replace if (oap->motion_type == kMTBlockWise) { bd.is_MAX = (curwin->w_curswant == MAXCOL); for (; curwin->w_cursor.lnum <= oap->end.lnum; curwin->w_cursor.lnum++) { @@ -2409,10 +2383,8 @@ void op_insert(oparg_T *oap, long count1) bd.textlen = bd2.textlen; } - /* - * Subsequent calls to ml_get() flush the firstline data - take a - * copy of the required string. - */ + // Subsequent calls to ml_get() flush the firstline data - take a + // copy of the required string. firstline = ml_get(oap->start.lnum); const size_t len = STRLEN(firstline); colnr_T add = bd.textcol; @@ -2510,11 +2482,9 @@ int op_change(oparg_T *oap) retval = edit(NUL, false, (linenr_T)1); - /* - * In Visual block mode, handle copying the new text to all lines of the - * block. - * Don't repeat the insert when Insert mode ended with CTRL-C. - */ + // In Visual block mode, handle copying the new text to all lines of the + // block. + // Don't repeat the insert when Insert mode ended with CTRL-C. if (oap->motion_type == kMTBlockWise && oap->start.lnum != oap->end.lnum && !got_int) { // Auto-indenting may have changed the indent. If the cursor was past @@ -2973,10 +2943,8 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) curbuf->b_op_start = curwin->w_cursor; // default for '[ mark curbuf->b_op_end = curwin->w_cursor; // default for '] mark - /* - * Using inserted text works differently, because the register includes - * special characters (newlines, etc.). - */ + // Using inserted text works differently, because the register includes + // special characters (newlines, etc.). if (regname == '.' && !reg) { bool non_linewise_vis = (VIsual_active && VIsual_mode != 'V'); @@ -3056,10 +3024,8 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) return; } - /* - * For special registers '%' (file name), '#' (alternate file name) and - * ':' (last command line), etc. we have to create a fake yank register. - */ + // For special registers '%' (file name), '#' (alternate file name) and + // ':' (last command line), etc. we have to create a fake yank register. if (!reg && get_spec_reg(regname, &insert_string, &allocated, true)) { if (insert_string == NULL) { return; @@ -3232,9 +3198,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) lnum = curwin->w_cursor.lnum; col = curwin->w_cursor.col; - /* - * Block mode - */ + // Block mode if (y_type == kMTBlockWise) { int c = gchar_cursor(); colnr_T endcol2 = 0; @@ -4129,13 +4093,11 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions cend = newp + sumsize; *cend = 0; - /* - * Move affected lines to the new long one. - * - * Move marks from each deleted line to the joined line, adjusting the - * column. This is not Vi compatible, but Vi deletes the marks, thus that - * should not really be a problem. - */ + // Move affected lines to the new long one. + // + // Move marks from each deleted line to the joined line, adjusting the + // column. This is not Vi compatible, but Vi deletes the marks, thus that + // should not really be a problem. curbuf_splice_pending++; @@ -4185,11 +4147,9 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions changed_lines(curwin->w_cursor.lnum, currsize, curwin->w_cursor.lnum + 1, 0L, true); - /* - * Delete following lines. To do this we move the cursor there - * briefly, and then move it back. After del_lines() the cursor may - * have moved up (last line deleted), so the current lnum is kept in t. - */ + // Delete following lines. To do this we move the cursor there + // briefly, and then move it back. After del_lines() the cursor may + // have moved up (last line deleted), so the current lnum is kept in t. t = curwin->w_cursor.lnum; curwin->w_cursor.lnum++; del_lines((long)count - 1, false); @@ -4197,11 +4157,9 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions curbuf_splice_pending--; curbuf->deleted_bytes2 = 0; - /* - * Set the cursor column: - * Vi compatible: use the column of the first join - * vim: use the column of the last join - */ + // Set the cursor column: + // Vi compatible: use the column of the first join + // vim: use the column of the last join curwin->w_cursor.col = (vim_strchr(p_cpo, CPO_JOINCOL) != NULL ? currsize : col); check_cursor_col(); @@ -4963,16 +4921,12 @@ void *get_reg_contents(int regname, int flags) return list; } - /* - * Compute length of resulting string. - */ + // Compute length of resulting string. size_t len = 0; for (size_t i = 0; i < reg->y_size; i++) { len += STRLEN(reg->y_array[i]); - /* - * Insert a newline between lines and after last line if - * y_type is kMTLineWise. - */ + // Insert a newline between lines and after last line if + // y_type is kMTLineWise. if (reg->y_type == kMTLineWise || i < reg->y_size - 1) { len++; } @@ -4980,18 +4934,14 @@ void *get_reg_contents(int regname, int flags) retval = xmalloc(len + 1); - /* - * Copy the lines of the yank register into the string. - */ + // Copy the lines of the yank register into the string. len = 0; for (size_t i = 0; i < reg->y_size; i++) { STRCPY(retval + len, reg->y_array[i]); len += STRLEN(retval + len); - /* - * Insert a NL between lines and after the last line if y_type is - * kMTLineWise. - */ + // Insert a NL between lines and after the last line if y_type is + // kMTLineWise. if (reg->y_type == kMTLineWise || i < reg->y_size - 1) { retval[len++] = '\n'; } -- cgit From 12afc344deb2df3973904fe55813d700da985dbf Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 6 Sep 2022 16:23:00 +0200 Subject: refactor: migrate comment style 2 #20080 --- src/nvim/ops.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 25b957e3b9..5d505f41a2 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -681,9 +681,9 @@ void op_reindent(oparg_T *oap, Indenter how) curwin->w_cursor.lnum = start_lnum; beginline(BL_SOL | BL_FIX); - /* Mark changed lines so that they will be redrawn. When Visual - * highlighting was present, need to continue until the last line. When - * there is no change still need to remove the Visual highlighting. */ + // Mark changed lines so that they will be redrawn. When Visual + // highlighting was present, need to continue until the last line. When + // there is no change still need to remove the Visual highlighting. if (last_changed != 0) { changed_lines(first_changed, 0, oap->is_VIsual ? start_lnum + (linenr_T)oap->line_count : @@ -748,12 +748,12 @@ char_u *get_expr_line(void) return NULL; } - /* Make a copy of the expression, because evaluating it may cause it to be - * changed. */ + // Make a copy of the expression, because evaluating it may cause it to be + // changed. expr_copy = vim_strsave(expr_line); - /* When we are invoked recursively limit the evaluation to 10 levels. - * Then return the string as-is. */ + // When we are invoked recursively limit the evaluation to 10 levels. + // Then return the string as-is. if (nested >= 10) { return expr_copy; } @@ -1431,8 +1431,8 @@ bool cmdline_paste_reg(int regname, bool literally_arg, bool remcr) cmdline_paste_str((char_u *)"\r", literally); } - /* Check for CTRL-C, in case someone tries to paste a few thousand - * lines and gets bored. */ + // Check for CTRL-C, in case someone tries to paste a few thousand + // lines and gets bored. os_breakcheck(); if (got_int) { return FAIL; @@ -2677,8 +2677,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) if (virtual_op) { getvcol(curwin, &oap->start, &cs, NULL, &ce); if (ce != cs && oap->start.coladd > 0) { - /* Part of a tab selected -- but don't - * double-count it. */ + // Part of a tab selected -- but don't double-count it. bd.startspaces = (ce - cs + 1) - oap->start.coladd; startcol++; @@ -3043,9 +3042,9 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (insert_string != NULL) { y_type = kMTCharWise; if (regname == '=') { - /* For the = register we need to split the string at NL - * characters. - * Loop twice: count the number of lines and save them. */ + // For the = register we need to split the string at NL + // characters. + // Loop twice: count the number of lines and save them. for (;;) { y_size = 0; ptr = insert_string; @@ -3285,9 +3284,9 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) delcount = 1; bd.textcol -= utf_head_off(oldp, oldp + bd.textcol); if (oldp[bd.textcol] != TAB) { - /* Only a Tab can be split into spaces. Other - * characters will have to be moved to after the - * block, causing misalignment. */ + // Only a Tab can be split into spaces. Other + // characters will have to be moved to after the + // block, causing misalignment. delcount = 0; bd.endspaces = 0; } -- cgit From 73207cae611a1efb8cd17139e8228772daeb9866 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/ops.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 5d505f41a2..10e957287e 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -722,26 +722,26 @@ int get_expr_register(void) if (*new_line == NUL) { // use previous line xfree(new_line); } else { - set_expr_line(new_line); + set_expr_line((char *)new_line); } return '='; } /// Set the expression for the '=' register. /// Argument must be an allocated string. -void set_expr_line(char_u *new_line) +void set_expr_line(char *new_line) { xfree(expr_line); - expr_line = new_line; + expr_line = (char_u *)new_line; } /// Get the result of the '=' register expression. /// /// @return a pointer to allocated memory, or NULL for failure. -char_u *get_expr_line(void) +char *get_expr_line(void) { - char_u *expr_copy; - char_u *rv; + char *expr_copy; + char *rv; static int nested = 0; if (expr_line == NULL) { @@ -750,7 +750,7 @@ char_u *get_expr_line(void) // Make a copy of the expression, because evaluating it may cause it to be // changed. - expr_copy = vim_strsave(expr_line); + expr_copy = xstrdup((char *)expr_line); // When we are invoked recursively limit the evaluation to 10 levels. // Then return the string as-is. @@ -759,19 +759,19 @@ char_u *get_expr_line(void) } nested++; - rv = (char_u *)eval_to_string((char *)expr_copy, NULL, true); + rv = eval_to_string(expr_copy, NULL, true); nested--; xfree(expr_copy); return rv; } /// Get the '=' register expression itself, without evaluating it. -char_u *get_expr_line_src(void) +char *get_expr_line_src(void) { if (expr_line == NULL) { return NULL; } - return vim_strsave(expr_line); + return xstrdup((char *)expr_line); } /// @return whether `regname` is a valid name of a yank register. @@ -1070,11 +1070,11 @@ static char_u *execreg_line_continuation(char **lines, size_t *idx) } } ga_append(&ga, NUL); - char_u *str = vim_strsave(ga.ga_data); + char *str = xstrdup(ga.ga_data); ga_clear(&ga); *idx = i; - return str; + return (char_u *)str; } /// Execute a yank register: copy it into the stuff buffer @@ -1130,7 +1130,7 @@ int do_execreg(int regname, int colon, int addcr, int silent) } xfree(p); } else if (regname == '=') { - p = get_expr_line(); + p = (char_u *)get_expr_line(); if (p == NULL) { return FAIL; } @@ -1338,7 +1338,7 @@ bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg) return true; case '=': // result of expression - *argp = (char *)get_expr_line(); + *argp = get_expr_line(); *allocated = true; return true; @@ -1392,7 +1392,7 @@ bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg) return false; } - *argp = (char *)ml_get_buf(curwin->w_buffer, curwin->w_cursor.lnum, false); + *argp = ml_get_buf(curwin->w_buffer, curwin->w_cursor.lnum, false); return true; case '_': // black hole: always empty @@ -1801,7 +1801,7 @@ static void mb_adjust_opend(oparg_T *oap) static inline void pbyte(pos_T lp, int c) { assert(c <= UCHAR_MAX); - *(ml_get_buf(curbuf, lp.lnum, true) + lp.col) = (char_u)c; + *(ml_get_buf(curbuf, lp.lnum, true) + lp.col) = (char)c; if (!curbuf_splice_pending) { extmark_splice_cols(curbuf, (int)lp.lnum - 1, lp.col, 1, 1, kExtmarkUndo); } @@ -1978,7 +1978,7 @@ static int op_replace(oparg_T *oap, int c) n = gchar_cursor(); if (n != NUL) { int new_byte_len = utf_char2len(c); - int old_byte_len = utfc_ptr2len((char *)get_cursor_pos_ptr()); + int old_byte_len = utfc_ptr2len(get_cursor_pos_ptr()); if (new_byte_len > 1 || old_byte_len > 1) { // This is slow, but it handles replacing a single-byte @@ -2199,7 +2199,7 @@ bool swapchar(int op_type, pos_T *pos) curwin->w_cursor = *pos; // don't use del_char(), it also removes composing chars - del_bytes(utf_ptr2len((char *)get_cursor_pos_ptr()), false, false); + del_bytes(utf_ptr2len(get_cursor_pos_ptr()), false, false); ins_char(nc); curwin->w_cursor = sp; } else { @@ -2995,7 +2995,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // STRLEN(ml_get(curwin->w_cursor.lnum)). With 'virtualedit' and the // cursor past the end of the line, curwin->w_cursor.coladd is // incremented instead of curwin->w_cursor.col. - char_u *cursor_pos = get_cursor_pos_ptr(); + char_u *cursor_pos = (char_u *)get_cursor_pos_ptr(); bool one_past_line = (*cursor_pos == NUL); bool eol = false; if (!one_past_line) { @@ -3101,7 +3101,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (u_save_cursor() == FAIL) { goto end; } - char *p = (char *)get_cursor_pos_ptr(); + char *p = get_cursor_pos_ptr(); if (dir == FORWARD && *p != NUL) { MB_PTR_ADV(p); } @@ -3210,7 +3210,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } // move to start of next multi-byte character - curwin->w_cursor.col += utfc_ptr2len((char *)get_cursor_pos_ptr()); + curwin->w_cursor.col += utfc_ptr2len(get_cursor_pos_ptr()); col++; } else { getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); @@ -3393,7 +3393,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // if type is kMTCharWise, FORWARD is the same as BACKWARD on the next // char if (dir == FORWARD && gchar_cursor() != NUL) { - int bytelen = utfc_ptr2len((char *)get_cursor_pos_ptr()); + int bytelen = utfc_ptr2len(get_cursor_pos_ptr()); // put it on the next of the multi-byte character. col += bytelen; @@ -4853,13 +4853,13 @@ void format_reg_type(MotionType reg_type, colnr_T reg_width, char *buf, size_t b /// Otherwise just return `s`. /// /// @return a void * for use in get_reg_contents(). -static void *get_reg_wrap_one_line(char_u *s, int flags) +static void *get_reg_wrap_one_line(char *s, int flags) { if (!(flags & kGRegList)) { return s; } list_T *const list = tv_list_alloc(1); - tv_list_append_allocated_string(list, (char *)s); + tv_list_append_allocated_string(list, s); return list; } @@ -4901,9 +4901,9 @@ void *get_reg_contents(int regname, int flags) return NULL; } if (allocated) { - return get_reg_wrap_one_line((char_u *)retval, flags); + return get_reg_wrap_one_line(retval, flags); } - return get_reg_wrap_one_line(vim_strsave((char_u *)retval), flags); + return get_reg_wrap_one_line(xstrdup(retval), flags); } yankreg_T *reg = get_yank_register(regname, YREG_PASTE); @@ -5574,7 +5574,7 @@ static Callback opfunc_cb; /// @return OK or FAIL int set_operatorfunc_option(void) { - return option_set_callback_func((char_u *)p_opfunc, &opfunc_cb); + return option_set_callback_func(p_opfunc, &opfunc_cb); } #if defined(EXITFREE) -- cgit From 3ff46544c9872b4161fd098569c30b55fe3abd36 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/ops.c | 78 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 10e957287e..420f6cf840 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2260,7 +2260,7 @@ void op_insert(oparg_T *oap, long count1) if (oap->op_type == OP_APPEND) { firstline += bd.textlen; } - pre_textlen = (long)STRLEN(firstline); + pre_textlen = (long)strlen(firstline); } if (oap->op_type == OP_APPEND) { @@ -2386,7 +2386,7 @@ void op_insert(oparg_T *oap, long count1) // Subsequent calls to ml_get() flush the firstline data - take a // copy of the required string. firstline = ml_get(oap->start.lnum); - const size_t len = STRLEN(firstline); + const size_t len = strlen(firstline); colnr_T add = bd.textcol; colnr_T offset = 0; // offset when cursor was moved in insert mode if (oap->op_type == OP_APPEND) { @@ -2408,7 +2408,7 @@ void op_insert(oparg_T *oap, long count1) } else { firstline += add; } - ins_len = (long)STRLEN(firstline) - pre_textlen - offset; + ins_len = (long)strlen(firstline) - pre_textlen - offset; if (pre_textlen >= 0 && ins_len > 0) { ins_text = xstrnsave(firstline, (size_t)ins_len); // block handled here @@ -2992,7 +2992,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // curwin->w_cursor.col marks the byte position of the cursor in the // currunt line. It increases up to a max of - // STRLEN(ml_get(curwin->w_cursor.lnum)). With 'virtualedit' and the + // strlen(ml_get(curwin->w_cursor.lnum)). With 'virtualedit' and the // cursor past the end of the line, curwin->w_cursor.coladd is // incremented instead of curwin->w_cursor.col. char_u *cursor_pos = (char_u *)get_cursor_pos_ptr(); @@ -3174,7 +3174,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) goto end; } - yanklen = (int)STRLEN(y_array[0]); + yanklen = (int)strlen(y_array[0]); if (cur_ve_flags == VE_ALL && y_type == kMTCharWise) { if (gchar_cursor() == TAB) { @@ -3259,7 +3259,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } // get the old line and advance to the position to insert at oldp = get_cursor_line_ptr(); - oldlen = STRLEN(oldp); + oldlen = strlen(oldp); chartabsize_T cts; init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, 0, oldp, oldp); @@ -3292,7 +3292,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } } - yanklen = (int)STRLEN(y_array[i]); + yanklen = (int)strlen(y_array[i]); if ((flags & PUT_BLOCK_INNER) == 0) { // calculate number of spaces required to fill right side of @@ -3380,7 +3380,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) curwin->w_cursor.col++; // in Insert mode we might be after the NUL, correct for that - len = (colnr_T)STRLEN(get_cursor_line_ptr()); + len = (colnr_T)strlen(get_cursor_line_ptr()); if (curwin->w_cursor.col > len) { curwin->w_cursor.col = len; } @@ -3444,7 +3444,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) totlen = (size_t)(count * yanklen); do { oldp = ml_get(lnum); - oldlen = STRLEN(oldp); + oldlen = strlen(oldp); if (lnum > start_lnum) { pos_T pos = { .lnum = lnum, @@ -3515,8 +3515,8 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // Then append y_array[0] to first line. lnum = new_cursor.lnum; ptr = ml_get(lnum) + col; - totlen = STRLEN(y_array[y_size - 1]); - newp = xmalloc((size_t)(STRLEN(ptr) + totlen + 1)); + totlen = strlen(y_array[y_size - 1]); + newp = xmalloc((size_t)(strlen(ptr) + totlen + 1)); STRCPY(newp, y_array[y_size - 1]); STRCAT(newp, ptr); // insert second line @@ -3550,7 +3550,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) curwin->w_cursor.lnum = lnum; ptr = ml_get(lnum); if (cnt == count && i == y_size - 1) { - lendiff = (int)STRLEN(ptr); + lendiff = (int)strlen(ptr); } if (*ptr == '#' && preprocs_left()) { indent = 0; // Leave # lines at start @@ -3567,7 +3567,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) curwin->w_cursor = old_pos; // remember how many chars were removed if (cnt == count && i == y_size - 1) { - lendiff -= (int)STRLEN(ml_get(lnum)); + lendiff -= (int)strlen(ml_get(lnum)); } } } @@ -3577,9 +3577,9 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (y_type == kMTCharWise || (y_type == kMTLineWise && flags & PUT_LINE_SPLIT)) { for (i = 0; i < y_size - 1; i++) { - totsize += (bcount_t)STRLEN(y_array[i]) + 1; + totsize += (bcount_t)strlen(y_array[i]) + 1; } - lastsize = (int)STRLEN(y_array[y_size - 1]); + lastsize = (int)strlen(y_array[y_size - 1]); totsize += lastsize; } if (y_type == kMTCharWise) { @@ -3623,7 +3623,7 @@ error: // Put the '] mark on the first byte of the last inserted character. // Correct the length for change in indent. curbuf->b_op_end.lnum = new_lnum; - len = STRLEN(y_array[y_size - 1]); + len = strlen(y_array[y_size - 1]); col = (colnr_T)len - lendiff; if (col > 1) { curbuf->b_op_end.col = col - 1; @@ -4019,7 +4019,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions if (t == 0 && setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { // Set the '[ mark. curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; - curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); + curwin->w_buffer->b_op_start.col = (colnr_T)strlen(curr); } if (remove_comments) { // We don't want to remove the comment leader if the @@ -4065,7 +4065,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions 0, spaces[t], spaces[t], kExtmarkUndo); } - currsize = (int)STRLEN(curr); + currsize = (int)strlen(curr); sumsize += currsize + spaces[t]; endcurr1 = endcurr2 = NUL; if (insert_space && currsize > 0) { @@ -4130,7 +4130,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions if (insert_space && t > 1) { curr = skipwhite(curr); } - currsize = (int)STRLEN(curr); + currsize = (int)strlen(curr); } ml_replace(curwin->w_cursor.lnum, newp, false); @@ -4362,20 +4362,20 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) } else if (oap->motion_type == kMTLineWise) { curwin->w_cursor.col = 0; pos.col = 0; - length = (colnr_T)STRLEN(ml_get(pos.lnum)); + length = (colnr_T)strlen(ml_get(pos.lnum)); } else { // oap->motion_type == kMTCharWise if (pos.lnum == oap->start.lnum && !oap->inclusive) { dec(&(oap->end)); } - length = (colnr_T)STRLEN(ml_get(pos.lnum)); + length = (colnr_T)strlen(ml_get(pos.lnum)); pos.col = 0; if (pos.lnum == oap->start.lnum) { pos.col += oap->start.col; length -= oap->start.col; } if (pos.lnum == oap->end.lnum) { - length = (int)STRLEN(ml_get(oap->end.lnum)); + length = (int)strlen(ml_get(oap->end.lnum)); if (oap->end.col >= length) { oap->end.col = length - 1; } @@ -4923,7 +4923,7 @@ void *get_reg_contents(int regname, int flags) // Compute length of resulting string. size_t len = 0; for (size_t i = 0; i < reg->y_size; i++) { - len += STRLEN(reg->y_array[i]); + len += strlen(reg->y_array[i]); // Insert a newline between lines and after last line if // y_type is kMTLineWise. if (reg->y_type == kMTLineWise || i < reg->y_size - 1) { @@ -4937,7 +4937,7 @@ void *get_reg_contents(int regname, int flags) len = 0; for (size_t i = 0; i < reg->y_size; i++) { STRCPY(retval + len, reg->y_array[i]); - len += STRLEN(retval + len); + len += strlen(retval + len); // Insert a NL between lines and after the last line if y_type is // kMTLineWise. @@ -5039,7 +5039,7 @@ void write_reg_contents_ex(int name, const char *str, ssize_t len, bool must_app MotionType yank_type, colnr_T block_len) { if (len < 0) { - len = (ssize_t)STRLEN(str); + len = (ssize_t)strlen(str); } // Special case: '/' search pattern @@ -5059,7 +5059,7 @@ void write_reg_contents_ex(int name, const char *str, ssize_t len, bool must_app semsg(_(e_nobufnr), (int64_t)num); } } else { - buf = buflist_findnr(buflist_findpat(str, str + STRLEN(str), + buf = buflist_findnr(buflist_findpat(str, str + strlen(str), true, false, false)); } if (buf == NULL) { @@ -5186,7 +5186,7 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str, } // When appending, copy the previous line and free it after. - size_t extra = append ? STRLEN(pp[--lnum]) : 0; + size_t extra = append ? strlen(pp[--lnum]) : 0; char *s = xmallocz(line_len + extra); if (extra > 0) { memcpy(s, pp[lnum], extra); @@ -5486,7 +5486,7 @@ void cursor_pos_info(dict_T *dict) bom_count = bomb_size(); if (dict == NULL && bom_count > 0) { - const size_t len = STRLEN(IObuff); + const size_t len = strlen(IObuff); vim_snprintf((char *)IObuff + len, IOSIZE - len, _("(+%" PRId64 " for BOM)"), (int64_t)bom_count); } @@ -5845,10 +5845,10 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) if (lt(VIsual, curwin->w_cursor)) { VIsual.col = 0; curwin->w_cursor.col = - (colnr_T)STRLEN(ml_get(curwin->w_cursor.lnum)); + (colnr_T)strlen(ml_get(curwin->w_cursor.lnum)); } else { curwin->w_cursor.col = 0; - VIsual.col = (colnr_T)STRLEN(ml_get(VIsual.lnum)); + VIsual.col = (colnr_T)strlen(ml_get(VIsual.lnum)); } VIsual_mode = 'v'; } else if (VIsual_mode == 'v') { @@ -5878,7 +5878,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) || oap->motion_type == kMTLineWise) && hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) { - curwin->w_cursor.col = (colnr_T)STRLEN(get_cursor_line_ptr()); + curwin->w_cursor.col = (colnr_T)strlen(get_cursor_line_ptr()); } } oap->end = curwin->w_cursor; @@ -5896,7 +5896,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) curwin->w_cursor.col = 0; } if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) { - oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum)); + oap->start.col = (colnr_T)strlen(ml_get(oap->start.lnum)); } } oap->end = oap->start; @@ -6080,7 +6080,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) if (inindent(0)) { oap->motion_type = kMTLineWise; } else { - oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); + oap->end.col = (colnr_T)strlen(ml_get(oap->end.lnum)); if (oap->end.col) { oap->end.col--; oap->inclusive = true; @@ -6474,7 +6474,7 @@ bool prepare_yankreg_from_object(yankreg_T *reg, String regtype, size_t lines) void finish_yankreg_from_object(yankreg_T *reg, bool clipboard_adjust) { - if (reg->y_size > 0 && STRLEN(reg->y_array[reg->y_size - 1]) == 0) { + if (reg->y_size > 0 && strlen(reg->y_array[reg->y_size - 1]) == 0) { // a known-to-be charwise yank might have a final linebreak // but otherwise there is no line after the final newline if (reg->y_type != kMTCharWise) { @@ -6495,7 +6495,7 @@ void finish_yankreg_from_object(yankreg_T *reg, bool clipboard_adjust) if (reg->y_type == kMTBlockWise) { size_t maxlen = 0; for (size_t i = 0; i < reg->y_size; i++) { - size_t rowlen = STRLEN(reg->y_array[i]); + size_t rowlen = strlen(reg->y_array[i]); if (rowlen > maxlen) { maxlen = rowlen; } @@ -6582,7 +6582,7 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet) reg->y_array[tv_idx++] = xstrdupnul((const char *)TV_LIST_ITEM_TV(li)->vval.v_string); }); - if (reg->y_size > 0 && STRLEN(reg->y_array[reg->y_size - 1]) == 0) { + if (reg->y_size > 0 && strlen(reg->y_array[reg->y_size - 1]) == 0) { // a known-to-be charwise yank might have a final linebreak // but otherwise there is no line after the final newline if (reg->y_type != kMTCharWise) { @@ -6601,7 +6601,7 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet) if (reg->y_type == kMTBlockWise) { size_t maxlen = 0; for (size_t i = 0; i < reg->y_size; i++) { - size_t rowlen = STRLEN(reg->y_array[i]); + size_t rowlen = strlen(reg->y_array[i]); if (rowlen > maxlen) { maxlen = rowlen; } @@ -6851,13 +6851,13 @@ bcount_t get_region_bytecount(buf_T *buf, linenr_T start_lnum, linenr_T end_lnum return end_col - start_col; } const char *first = (const char *)ml_get_buf(buf, start_lnum, false); - bcount_t deleted_bytes = (bcount_t)STRLEN(first) - start_col + 1; + bcount_t deleted_bytes = (bcount_t)strlen(first) - start_col + 1; for (linenr_T i = 1; i <= end_lnum - start_lnum - 1; i++) { if (start_lnum + i > max_lnum) { return deleted_bytes; } - deleted_bytes += (bcount_t)STRLEN(ml_get_buf(buf, start_lnum + i, false)) + 1; + deleted_bytes += (bcount_t)strlen(ml_get_buf(buf, start_lnum + i, false)) + 1; } if (end_lnum > max_lnum) { return deleted_bytes; -- cgit From 708bd686516b420c2b65f4bc4d2c58fe43fb945e Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 13 Sep 2022 12:56:30 +0200 Subject: feat(ui): use msg_grid based implementation for cmdheight=0 --- src/nvim/ops.c | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 420f6cf840..83484859ed 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -896,7 +896,6 @@ int do_record(int c) { char_u *p; static int regname; - static bool changed_cmdheight = false; yankreg_T *old_y_previous; int retval; @@ -907,18 +906,11 @@ int do_record(int c) retval = FAIL; } else { reg_recording = c; + // TODO(bfredl): showmode based messaging is currently missing with cmdheight=0 showmode(); regname = c; retval = OK; - if (!ui_has_messages()) { - // Enable macro indicator temporarily - set_option_value("ch", 1L, NULL, 0); - update_screen(UPD_VALID); - - changed_cmdheight = true; - } - apply_autocmds(EVENT_RECORDINGENTER, NULL, NULL, false, curbuf); } } else { // stop recording @@ -948,7 +940,7 @@ int do_record(int c) restore_v_event(dict, &save_v_event); reg_recorded = reg_recording; reg_recording = 0; - if (ui_has(kUIMessages)) { + if (p_ch == 0 || ui_has(kUIMessages)) { showmode(); } else { msg(""); @@ -964,12 +956,6 @@ int do_record(int c) y_previous = old_y_previous; } - - if (changed_cmdheight) { - // Restore cmdheight - set_option_value("ch", 0L, NULL, 0); - redraw_all_later(UPD_CLEAR); - } } return retval; } -- cgit From 72e1041429565c3a592dedc36e8b3004a24cdcc4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 17 Sep 2022 10:20:06 +0800 Subject: vim-patch:9.0.0483: illegal memory access when replacing in virtualedit mode (#20225) Problem: Illegal memory access when replacing in virtualedit mode. Solution: Check for replacing NUL after Tab. https://github.com/vim/vim/commit/c249913edc35c0e666d783bfc21595cf9f7d9e0d Cherry-pick Test_virtualedit_mouse() from patch 9.0.0177. --- src/nvim/ops.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 83484859ed..6391644f83 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1961,6 +1961,8 @@ static int op_replace(oparg_T *oap, int c) // TODO(bfredl): we could batch all the splicing // done on the same line, at least while (ltoreq(curwin->w_cursor, oap->end)) { + bool done = false; + n = gchar_cursor(); if (n != NUL) { int new_byte_len = utf_char2len(c); @@ -1973,6 +1975,7 @@ static int op_replace(oparg_T *oap, int c) oap->end.col += new_byte_len - old_byte_len; } replace_character(c); + done = true; } else { if (n == TAB) { int end_vcol = 0; @@ -1988,9 +1991,14 @@ static int op_replace(oparg_T *oap, int c) getvpos(&oap->end, end_vcol); } } - pbyte(curwin->w_cursor, c); + // with "coladd" set may move to just after a TAB + if (gchar_cursor() != NUL) { + pbyte(curwin->w_cursor, c); + done = true; + } } - } else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum) { + } + if (!done && virtual_op && curwin->w_cursor.lnum == oap->end.lnum) { int virtcols = oap->end.coladd; if (curwin->w_cursor.lnum == oap->start.lnum -- cgit From 91e912f8d40284c74d4a997c8c95961eebb35d91 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 25 Sep 2022 15:26:37 +0200 Subject: refactor: move klib out of src/nvim/ #20341 It's confusing to mix vendored dependencies with neovim source code. A clean separation is simpler to keep track of and simpler to document. --- src/nvim/ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 6391644f83..dee23e9193 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -9,6 +9,7 @@ #include #include +#include "klib/kvec.h" #include "nvim/ascii.h" #include "nvim/assert.h" #include "nvim/buffer.h" @@ -28,7 +29,6 @@ #include "nvim/globals.h" #include "nvim/indent.h" #include "nvim/indent_c.h" -#include "nvim/lib/kvec.h" #include "nvim/log.h" #include "nvim/macros.h" #include "nvim/mark.h" -- cgit From 6679687bb3909f853ae97dfa01ae08ea2baf7f97 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 26 Sep 2022 15:17:10 +0200 Subject: refactor(redraw): no type argument in update_screen() This was used in the past with assumption that curwin/curbuf is "special" but this has not been true since basically forever at this point. Reduce NOT_VALID/CLEAR panic in options.lua . These should not be set if an effect of the option is causing something which by itself invokes redraw_later(). --- src/nvim/ops.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index dee23e9193..7fbf495922 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2220,7 +2220,8 @@ void op_insert(oparg_T *oap, long count1) // vis block is still marked. Get rid of it now. curwin->w_cursor.lnum = oap->start.lnum; - update_screen(UPD_INVERTED); + redraw_curbuf_later(UPD_INVERTED); + update_screen(); if (oap->motion_type == kMTBlockWise) { // When 'virtualedit' is used, need to insert the extra spaces before @@ -2772,7 +2773,10 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) } // redisplay now, so message is not deleted - update_topline_redraw(); + update_topline(curwin); + if (must_redraw) { + update_screen(); + } if (yank_type == kMTBlockWise) { smsg(NGETTEXT("block of %" PRId64 " line yanked%s", "block of %" PRId64 " lines yanked%s", yanklines), -- cgit From c93fd83df206c2438a735d6d99e640db1976f2f0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 9 Oct 2022 18:48:32 +0800 Subject: vim-patch:9.0.0697: cursor in wrong position with Visual substitute Problem: Cursor in wrong position with Visual substitute. Solution: When restoring 'linebreak' mark the virtual column as invalid. (closes vim/vim#11309, closes vim/vim#11311) https://github.com/vim/vim/commit/16dab41537ae206f4cab676ad53edbae5fd5fb45 N/A patches for version.c: vim-patch:9.0.0699: tiny build fails Problem: Tiny build fails. Solution: Add #ifdef. https://github.com/vim/vim/commit/bf499c0e6f30a94fe062f83ea0190f93178d0d74 --- src/nvim/ops.c | 60 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 21 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 7fbf495922..d3a47d77a2 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4172,6 +4172,29 @@ theend: return ret; } +/// Reset 'linebreak' and take care of side effects. +/// @return the previous value, to be passed to restore_lbr(). +static bool reset_lbr(void) +{ + if (!curwin->w_p_lbr) { + return false; + } + // changing 'linebreak' may require w_virtcol to be updated + curwin->w_p_lbr = false; + curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL); + return true; +} + +/// Restore 'linebreak' and take care of side effects. +static void restore_lbr(bool lbr_saved) +{ + if (!curwin->w_p_lbr && lbr_saved) { + // changing 'linebreak' may require w_virtcol to be updated + curwin->w_p_lbr = true; + curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL); + } +} + /// prepare a few things for block mode yank/delete/tilde /// /// for delete: @@ -4191,10 +4214,9 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool char *line; char *prev_pstart; char *prev_pend; - const int lbr_saved = curwin->w_p_lbr; - // Avoid a problem with unwanted linebreaks in block mode. - curwin->w_p_lbr = false; + const bool lbr_saved = reset_lbr(); + bdp->startspaces = 0; bdp->endspaces = 0; bdp->textlen = 0; @@ -4308,7 +4330,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool } bdp->textcol = (colnr_T)(pstart - line); bdp->textstart = (char_u *)pstart; - curwin->w_p_lbr = lbr_saved; + restore_lbr(lbr_saved); } /// Handle the add/subtract operator. @@ -5733,10 +5755,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) const bool redo_yank = vim_strchr(p_cpo, CPO_YANK) != NULL && !gui_yank; // Avoid a problem with unwanted linebreaks in block mode - if (curwin->w_p_lbr) { - curwin->w_valid &= ~VALID_VIRTCOL; - } - curwin->w_p_lbr = false; + (void)reset_lbr(); oap->is_VIsual = VIsual_active; if (oap->motion_force == 'V') { oap->motion_type = kMTLineWise; @@ -6025,7 +6044,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) || oap->op_type == OP_FILTER) && oap->motion_force == NUL) { // Make sure redrawing is correct. - curwin->w_p_lbr = lbr_saved; + restore_lbr(lbr_saved); redraw_curbuf_later(UPD_INVERTED); } } @@ -6057,7 +6076,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) // 'modifiable is off or creating a fold. if (oap->is_VIsual && (oap->empty || !MODIFIABLE(curbuf) || oap->op_type == OP_FOLD)) { - curwin->w_p_lbr = lbr_saved; + restore_lbr(lbr_saved); redraw_curbuf_later(UPD_INVERTED); } @@ -6133,7 +6152,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) CancelRedo(); } } else { - curwin->w_p_lbr = lbr_saved; + restore_lbr(lbr_saved); oap->excl_tr_ws = cap->cmdchar == 'z'; (void)op_yank(oap, !gui_yank); } @@ -6157,7 +6176,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) restart_edit = 0; // Restore linebreak, so that when the user edits it looks as before. - curwin->w_p_lbr = lbr_saved; + restore_lbr(lbr_saved); // Reset finish_op now, don't want it set inside edit(). finish_op = false; @@ -6228,9 +6247,8 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) case OP_FUNCTION: { redo_VIsual_T save_redo_VIsual = redo_VIsual; - // Restore linebreak, so that when the user edits it looks as - // before. - curwin->w_p_lbr = lbr_saved; + // Restore linebreak, so that when the user edits it looks as before. + restore_lbr(lbr_saved); // call 'operatorfunc' op_function(oap); @@ -6254,12 +6272,12 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) restart_edit = 0; // Restore linebreak, so that when the user edits it looks as before. - curwin->w_p_lbr = lbr_saved; + restore_lbr(lbr_saved); op_insert(oap, cap->count1); // Reset linebreak, so that formatting works correctly. - curwin->w_p_lbr = false; + (void)reset_lbr(); // TODO(brammool): when inserting in several lines, should format all // the lines. @@ -6280,7 +6298,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) CancelRedo(); } else { // Restore linebreak, so that when the user edits it looks as before. - curwin->w_p_lbr = lbr_saved; + restore_lbr(lbr_saved); op_replace(oap, cap->nchar); } @@ -6318,7 +6336,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) CancelRedo(); } else { VIsual_active = true; - curwin->w_p_lbr = lbr_saved; + restore_lbr(lbr_saved); op_addsub(oap, (linenr_T)cap->count1, redo_VIsual.rv_arg); VIsual_active = false; } @@ -6333,7 +6351,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) if (!p_sol && oap->motion_type == kMTLineWise && !oap->end_adjusted && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT || oap->op_type == OP_DELETE)) { - curwin->w_p_lbr = false; + (void)reset_lbr(); coladvance(curwin->w_curswant = old_col); } } else { @@ -6342,7 +6360,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) clearop(oap); motion_force = NUL; } - curwin->w_p_lbr = lbr_saved; + restore_lbr(lbr_saved); } /// Check if the default register (used in an unnamed paste) should be a -- cgit From 0ef6aaa3a73d5089bf53e804364950c81784574c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 12 Oct 2022 14:53:40 +0100 Subject: refactor: clint (#20600) --- src/nvim/ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d3a47d77a2..3bb397fdd8 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2239,7 +2239,7 @@ void op_insert(oparg_T *oap, long count1) } curwin->w_ve_flags = VE_ALL; coladvance_force(oap->op_type == OP_APPEND - ? oap->end_vcol + 1 : getviscol()); + ? oap->end_vcol + 1 : getviscol()); if (oap->op_type == OP_APPEND) { curwin->w_cursor.col--; } -- cgit From 04cdea5f4ac49fa62cc4091a5c26791b80b4cc4c Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/ops.c | 180 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 90 insertions(+), 90 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 3bb397fdd8..8b2fea9535 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -418,7 +418,7 @@ static void shift_block(oparg_T *oap, int amount) size_t fill; // nr of spaces that replace a TAB size_t new_line_len; // the length of the line after the // block shift - char_u *non_white = bd.textstart; + char *non_white = (char *)bd.textstart; // Firstly, let's find the first non-whitespace character that is // displayed after the block's start column and the character's column @@ -438,13 +438,13 @@ static void shift_block(oparg_T *oap, int amount) chartabsize_T cts; init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, - non_white_col, (char *)bd.textstart, (char *)non_white); + non_white_col, (char *)bd.textstart, non_white); while (ascii_iswhite(*cts.cts_ptr)) { incr = lbr_chartabsize_adv(&cts); cts.cts_vcol += incr; } non_white_col = cts.cts_vcol; - non_white = (char_u *)cts.cts_ptr; + non_white = cts.cts_ptr; clear_chartabsize_arg(&cts); const colnr_T block_space_width = non_white_col - oap->start_vcol; @@ -492,11 +492,11 @@ static void shift_block(oparg_T *oap, int amount) // - the beginning of the original line up to "verbatim_copy_end", // - "fill" number of spaces, // - the rest of the line, pointed to by non_white. - new_line_len = verbatim_diff + fill + STRLEN(non_white) + 1; + new_line_len = verbatim_diff + fill + strlen(non_white) + 1; newp = (char_u *)xmalloc(new_line_len); startcol = (int)verbatim_diff; - oldlen = bd.textcol + (int)(non_white - bd.textstart) - (int)verbatim_diff; + oldlen = bd.textcol + (int)(non_white - (char *)bd.textstart) - (int)verbatim_diff; newlen = (int)fill; memmove(newp, oldp, verbatim_diff); memset(newp + verbatim_diff, ' ', fill); @@ -515,14 +515,14 @@ static void shift_block(oparg_T *oap, int amount) /// Insert string "s" (b_insert ? before : after) block :AKelly /// Caller must prepare for undo. -static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def *bdp) +static void block_insert(oparg_T *oap, char *s, int b_insert, struct block_def *bdp) { int ts_val; int count = 0; // extra spaces to replace a cut TAB int spaces = 0; // non-zero if cutting a TAB colnr_T offset; // pointer along new line - size_t s_len = STRLEN(s); - char_u *newp, *oldp; // new, old lines + size_t s_len = strlen(s); + char *newp, *oldp; // new, old lines linenr_T lnum; // loop var int oldstate = State; State = MODE_INSERT; // don't want MODE_REPLACE for State @@ -533,7 +533,7 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def continue; // OP_INSERT, line ends before block start } - oldp = (char_u *)ml_get(lnum); + oldp = ml_get(lnum); if (b_insert) { ts_val = bdp->start_char_vcols; @@ -562,7 +562,7 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def if (spaces > 0) { // avoid copying part of a multi-byte character - offset -= utf_head_off((char *)oldp, (char *)oldp + offset); + offset -= utf_head_off(oldp, oldp + offset); } if (spaces < 0) { // can happen when the cursor was moved spaces = 0; @@ -570,7 +570,7 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def assert(count >= 0); // Make sure the allocated size matches what is actually copied below. - newp = xmalloc(STRLEN(oldp) + (size_t)spaces + s_len + newp = xmalloc(strlen(oldp) + (size_t)spaces + s_len + (spaces > 0 && !bdp->is_short ? (size_t)ts_val - (size_t)spaces : 0) + (size_t)count + 1); @@ -607,7 +607,7 @@ static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def } STRMOVE(newp + offset, oldp); - ml_replace(lnum, (char *)newp, false); + ml_replace(lnum, newp, false); extmark_splice_cols(curbuf, (int)lnum - 1, startcol, skipped, offset - startcol, kExtmarkUndo); @@ -706,7 +706,7 @@ void op_reindent(oparg_T *oap, Indenter how) } // Keep the last expression line here, for repeating. -static char_u *expr_line = NULL; +static char *expr_line = NULL; /// Get an expression for the "\"=expr1" or "CTRL-R =expr1" /// @@ -732,7 +732,7 @@ int get_expr_register(void) void set_expr_line(char *new_line) { xfree(expr_line); - expr_line = (char_u *)new_line; + expr_line = new_line; } /// Get the result of the '=' register expression. @@ -750,7 +750,7 @@ char *get_expr_line(void) // Make a copy of the expression, because evaluating it may cause it to be // changed. - expr_copy = xstrdup((char *)expr_line); + expr_copy = xstrdup(expr_line); // When we are invoked recursively limit the evaluation to 10 levels. // Then return the string as-is. @@ -771,7 +771,7 @@ char *get_expr_line_src(void) if (expr_line == NULL) { return NULL; } - return xstrdup((char *)expr_line); + return xstrdup(expr_line); } /// @return whether `regname` is a valid name of a yank register. @@ -952,7 +952,7 @@ int do_record(int c) // restore the current register name. old_y_previous = y_previous; - retval = stuff_yank(regname, p); + retval = stuff_yank(regname, (char *)p); y_previous = old_y_previous; } @@ -974,7 +974,7 @@ static void set_yreg_additional_data(yankreg_T *reg, dict_T *additional_data) /// uppercase). "p" must have been allocated. /// /// @return FAIL for failure, OK otherwise -static int stuff_yank(int regname, char_u *p) +static int stuff_yank(int regname, char *p) { // check for read-only register if (regname != 0 && !valid_yank_reg(regname, true)) { @@ -988,7 +988,7 @@ static int stuff_yank(int regname, char_u *p) yankreg_T *reg = get_yank_register(regname, YREG_YANK); if (is_append_register(regname) && reg->y_array != NULL) { char **pp = &(reg->y_array[reg->y_size - 1]); - char_u *lp = xmalloc(strlen(*pp) + STRLEN(p) + 1); + char_u *lp = xmalloc(strlen(*pp) + strlen(p) + 1); STRCPY(lp, *pp); // TODO(philix): use xstpcpy() in stuff_yank() STRCAT(lp, p); @@ -999,7 +999,7 @@ static int stuff_yank(int regname, char_u *p) free_register(reg); set_yreg_additional_data(reg, NULL); reg->y_array = xmalloc(sizeof(char_u *)); - reg->y_array[0] = (char *)p; + reg->y_array[0] = p; reg->y_size = 1; reg->y_type = kMTCharWise; } @@ -1448,7 +1448,7 @@ int op_delete(oparg_T *oap) int n; linenr_T lnum; char_u *ptr; - char_u *newp, *oldp; + char *newp, *oldp; struct block_def bd = { 0 }; linenr_T old_lcount = curbuf->b_ml.ml_line_count; @@ -1579,8 +1579,8 @@ int op_delete(oparg_T *oap) // If we delete a TAB, it may be replaced by several characters. // Thus the number of characters may increase! n = bd.textlen - bd.startspaces - bd.endspaces; - oldp = (char_u *)ml_get(lnum); - newp = (char_u *)xmalloc(STRLEN(oldp) - (size_t)n + 1); + oldp = ml_get(lnum); + newp = xmalloc(strlen(oldp) - (size_t)n + 1); // copy up to deleted part memmove(newp, oldp, (size_t)bd.textcol); // insert spaces @@ -1590,7 +1590,7 @@ int op_delete(oparg_T *oap) oldp += bd.textcol + bd.textlen; STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); // replace the line - ml_replace(lnum, (char *)newp, false); + ml_replace(lnum, newp, false); extmark_splice_cols(curbuf, (int)lnum - 1, bd.textcol, bd.textlen, bd.startspaces + bd.endspaces, @@ -1697,8 +1697,8 @@ int op_delete(oparg_T *oap) if (virtual_op) { // fix up things for virtualedit-delete: // break the tabs which are going to get in our way - char_u *curline = (char_u *)get_cursor_line_ptr(); - int len = (int)STRLEN(curline); + char *curline = get_cursor_line_ptr(); + int len = (int)strlen(curline); if (oap->end.coladd != 0 && (int)oap->end.col >= len - 1 @@ -1811,7 +1811,7 @@ static int op_replace(oparg_T *oap, int c) { int n, numc; int num_chars; - char_u *newp, *oldp; + char *newp, *oldp; colnr_T oldlen; struct block_def bd; char_u *after_p = NULL; @@ -1886,8 +1886,8 @@ static int op_replace(oparg_T *oap, int c) num_chars = numc; numc *= utf_char2len(c); - oldp = (char_u *)get_cursor_line_ptr(); - oldlen = (int)STRLEN(oldp); + oldp = get_cursor_line_ptr(); + oldlen = (int)strlen(oldp); size_t newp_size = (size_t)bd.textcol + (size_t)bd.startspaces; if (had_ctrl_v_cr || (c != '\r' && c != '\n')) { @@ -1913,7 +1913,7 @@ static int op_replace(oparg_T *oap, int c) // strlen(newp) at this point int newp_len = bd.textcol + bd.startspaces; while (--num_chars >= 0) { - newp_len += utf_char2bytes(c, (char *)newp + newp_len); + newp_len += utf_char2bytes(c, newp + newp_len); } if (!bd.is_short) { // insert post-spaces @@ -1931,7 +1931,7 @@ static int op_replace(oparg_T *oap, int c) newrows = 1; } // replace the line - ml_replace(curwin->w_cursor.lnum, (char *)newp, false); + ml_replace(curwin->w_cursor.lnum, newp, false); curbuf_splice_pending++; linenr_T baselnum = curwin->w_cursor.lnum; if (after_p != NULL) { @@ -2408,7 +2408,7 @@ void op_insert(oparg_T *oap, long count1) ins_text = xstrnsave(firstline, (size_t)ins_len); // block handled here if (u_save(oap->start.lnum, (linenr_T)(oap->end.lnum + 1)) == OK) { - block_insert(oap, (char_u *)ins_text, (oap->op_type == OP_INSERT), &bd); + block_insert(oap, ins_text, (oap->op_type == OP_INSERT), &bd); } curwin->w_cursor.col = oap->start.col; @@ -2431,9 +2431,9 @@ int op_change(oparg_T *oap) long pre_textlen = 0; long pre_indent = 0; char_u *newp; - char_u *firstline; + char *firstline; char_u *ins_text; - char_u *oldp; + char *oldp; struct block_def bd; l = oap->start.col; @@ -2465,9 +2465,9 @@ int op_change(oparg_T *oap) || gchar_cursor() == NUL)) { coladvance_force(getviscol()); } - firstline = (char_u *)ml_get(oap->start.lnum); - pre_textlen = (long)STRLEN(firstline); - pre_indent = (long)getwhitecols((char *)firstline); + firstline = ml_get(oap->start.lnum); + pre_textlen = (long)strlen(firstline); + pre_indent = (long)getwhitecols(firstline); bd.textcol = curwin->w_cursor.col; } @@ -2484,15 +2484,15 @@ int op_change(oparg_T *oap) && oap->start.lnum != oap->end.lnum && !got_int) { // Auto-indenting may have changed the indent. If the cursor was past // the indent, exclude that indent change from the inserted text. - firstline = (char_u *)ml_get(oap->start.lnum); + firstline = ml_get(oap->start.lnum); if (bd.textcol > (colnr_T)pre_indent) { - long new_indent = (long)getwhitecols((char *)firstline); + long new_indent = (long)getwhitecols(firstline); pre_textlen += new_indent - pre_indent; bd.textcol += (colnr_T)(new_indent - pre_indent); } - ins_len = (long)STRLEN(firstline) - pre_textlen; + ins_len = (long)strlen(firstline) - pre_textlen; if (ins_len > 0) { // Subsequent calls to ml_get() flush the firstline data - take a // copy of the inserted text. @@ -2512,8 +2512,8 @@ int op_change(oparg_T *oap) } else { vpos.coladd = 0; } - oldp = (char_u *)ml_get(linenr); - newp = xmalloc(STRLEN(oldp) + (size_t)vpos.coladd + oldp = ml_get(linenr); + newp = xmalloc(strlen(oldp) + (size_t)vpos.coladd + (size_t)ins_len + 1); // copy up to block start memmove(newp, oldp, (size_t)bd.textcol); @@ -2604,7 +2604,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) MotionType yank_type = oap->motion_type; size_t yanklines = (size_t)oap->line_count; linenr_T yankendlnum = oap->end.lnum; - char_u *p; + char *p; char_u *pnew; struct block_def bd; @@ -2663,7 +2663,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) colnr_T startcol = 0, endcol = MAXCOL; int is_oneChar = false; colnr_T cs, ce; - p = (char_u *)ml_get(lnum); + p = ml_get(lnum); bd.startspaces = 0; bd.endspaces = 0; @@ -2688,7 +2688,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) // Don't add space for double-wide // char; endcol will be on last byte // of multi-byte char. - && utf_head_off((char *)p, (char *)p + endcol) == 0)) { + && utf_head_off(p, p + endcol) == 0)) { if (oap->start.lnum == oap->end.lnum && oap->start.col == oap->end.col) { // Special case: inside a single char @@ -2705,7 +2705,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) } } if (endcol == MAXCOL) { - endcol = (colnr_T)STRLEN(p); + endcol = (colnr_T)strlen(p); } if (startcol > endcol || is_oneChar) { @@ -2713,7 +2713,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) } else { bd.textlen = endcol - startcol + oap->inclusive; } - bd.textstart = p + startcol; + bd.textstart = (char_u *)p + startcol; yank_copy_line(reg, &bd, y_idx, false); break; } @@ -3874,9 +3874,9 @@ void ex_display(exarg_T *eap) // display last used expression if (expr_line != NULL && (arg == NULL || vim_strchr((char *)arg, '=') != NULL) - && !got_int && !message_filtered((char *)expr_line)) { + && !got_int && !message_filtered(expr_line)) { msg_puts("\n c \"= "); - dis_msg((char *)expr_line, false); + dis_msg(expr_line, false); } } @@ -4452,12 +4452,12 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) { int col; char_u *buf1 = NULL; - char_u buf2[NUMBUFLEN]; + char buf2[NUMBUFLEN]; int pre; // 'X' or 'x': hex; '0': octal; 'B' or 'b': bin static bool hexupper = false; // 0xABC uvarnumber_T n; uvarnumber_T oldn; - char_u *ptr; + char *ptr; int c; int todel; int firstdigit; @@ -4484,10 +4484,10 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) } curwin->w_cursor = *pos; - ptr = (char_u *)ml_get(pos->lnum); + ptr = ml_get(pos->lnum); col = pos->col; - if (*ptr == NUL || col + !!save_coladd >= (int)STRLEN(ptr)) { + if (*ptr == NUL || col + !!save_coladd >= (int)strlen(ptr)) { goto theend; } @@ -4496,14 +4496,14 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) if (do_bin) { while (col > 0 && ascii_isbdigit(ptr[col])) { col--; - col -= utf_head_off((char *)ptr, (char *)ptr + col); + col -= utf_head_off(ptr, ptr + col); } } if (do_hex) { while (col > 0 && ascii_isxdigit(ptr[col])) { col--; - col -= utf_head_off((char *)ptr, (char *)ptr + col); + col -= utf_head_off(ptr, ptr + col); } } if (do_bin @@ -4511,7 +4511,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) && !((col > 0 && (ptr[col] == 'X' || ptr[col] == 'x') && ptr[col - 1] == '0' - && !utf_head_off((char *)ptr, (char *)ptr + col - 1) + && !utf_head_off(ptr, ptr + col - 1) && ascii_isxdigit(ptr[col + 1])))) { // In case of binary/hexadecimal pattern overlap match, rescan @@ -4519,7 +4519,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) while (col > 0 && ascii_isdigit(ptr[col])) { col--; - col -= utf_head_off((char *)ptr, (char *)ptr + col); + col -= utf_head_off(ptr, ptr + col); } } @@ -4527,17 +4527,17 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) && col > 0 && (ptr[col] == 'X' || ptr[col] == 'x') && ptr[col - 1] == '0' - && !utf_head_off((char *)ptr, (char *)ptr + col - 1) + && !utf_head_off(ptr, ptr + col - 1) && ascii_isxdigit(ptr[col + 1])) || (do_bin && col > 0 && (ptr[col] == 'B' || ptr[col] == 'b') && ptr[col - 1] == '0' - && !utf_head_off((char *)ptr, (char *)ptr + col - 1) + && !utf_head_off(ptr, ptr + col - 1) && ascii_isbdigit(ptr[col + 1]))) { // Found hexadecimal or binary number, move to its start. col--; - col -= utf_head_off((char *)ptr, (char *)ptr + col); + col -= utf_head_off(ptr, ptr + col); } else { // Search forward and then backward to find the start of number. col = pos->col; @@ -4559,7 +4559,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) if (visual) { while (ptr[col] != NUL && length > 0 && !ascii_isdigit(ptr[col]) && !(do_alpha && ASCII_ISALPHA(ptr[col]))) { - int mb_len = utfc_ptr2len((char *)ptr + col); + int mb_len = utfc_ptr2len(ptr + col); col += mb_len; length -= mb_len; @@ -4570,7 +4570,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) } if (col > pos->col && ptr[col - 1] == '-' - && !utf_head_off((char *)ptr, (char *)ptr + col - 1) + && !utf_head_off(ptr, ptr + col - 1) && !do_unsigned) { negative = true; was_positive = false; @@ -4578,7 +4578,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) } // If a number was found, and saving for undo works, replace the number. - firstdigit = ptr[col]; + firstdigit = (uint8_t)ptr[col]; if (!ascii_isdigit(firstdigit) && !(do_alpha && ASCII_ISALPHA(firstdigit))) { beep_flush(); goto theend; @@ -4616,7 +4616,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) curwin->w_cursor.col = col; } else { if (col > 0 && ptr[col - 1] == '-' - && !utf_head_off((char *)ptr, (char *)ptr + col - 1) + && !utf_head_off(ptr, ptr + col - 1) && !visual && !do_unsigned) { // negative number @@ -4627,11 +4627,11 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) // get the number value (unsigned) if (visual && VIsual_mode != 'V') { maxlen = (curbuf->b_visual.vi_curswant == MAXCOL - ? (int)STRLEN(ptr) - col + ? (int)strlen(ptr) - col : length); } - vim_str2nr((char *)ptr + col, &pre, &length, + vim_str2nr(ptr + col, &pre, &length, 0 + (do_bin ? STR2NR_BIN : 0) + (do_oct ? STR2NR_OCT : 0) + (do_hex ? STR2NR_HEX : 0), @@ -4723,7 +4723,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) // When there are many leading zeros it could be very long. // Allocate a bit too much. buf1 = xmalloc((size_t)length + NUMBUFLEN); - ptr = buf1; + ptr = (char *)buf1; if (negative && (!visual || was_positive)) { *ptr++ = '-'; } @@ -4732,7 +4732,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) length--; } if (pre == 'b' || pre == 'B' || pre == 'x' || pre == 'X') { - *ptr++ = (char_u)pre; + *ptr++ = (char)pre; length--; } @@ -4754,15 +4754,15 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) buf2[i] = '\0'; } else if (pre == 0) { - vim_snprintf((char *)buf2, ARRAY_SIZE(buf2), "%" PRIu64, (uint64_t)n); + vim_snprintf(buf2, ARRAY_SIZE(buf2), "%" PRIu64, (uint64_t)n); } else if (pre == '0') { - vim_snprintf((char *)buf2, ARRAY_SIZE(buf2), "%" PRIo64, (uint64_t)n); + vim_snprintf(buf2, ARRAY_SIZE(buf2), "%" PRIo64, (uint64_t)n); } else if (hexupper) { - vim_snprintf((char *)buf2, ARRAY_SIZE(buf2), "%" PRIX64, (uint64_t)n); + vim_snprintf(buf2, ARRAY_SIZE(buf2), "%" PRIX64, (uint64_t)n); } else { - vim_snprintf((char *)buf2, ARRAY_SIZE(buf2), "%" PRIx64, (uint64_t)n); + vim_snprintf(buf2, ARRAY_SIZE(buf2), "%" PRIx64, (uint64_t)n); } - length -= (int)STRLEN(buf2); + length -= (int)strlen(buf2); // Adjust number of zeros to the new number of digits, so the // total length of the number remains the same. @@ -5032,7 +5032,7 @@ void write_reg_contents_lst(int name, char **strings, bool must_append, MotionTy return; } - str_to_reg(reg, yank_type, (char *)strings, STRLEN(strings), + str_to_reg(reg, yank_type, (char *)strings, strlen((char *)strings), block_len, true); finish_write_reg(name, reg, old_y_previous); } @@ -5096,7 +5096,7 @@ void write_reg_contents_ex(int name, const char *str, ssize_t len, bool must_app if (must_append && expr_line) { // append has been specified and expr_line already exists, so we'll // append the new string to expr_line. - size_t exprlen = STRLEN(expr_line); + size_t exprlen = strlen(expr_line); totlen += exprlen; offset = exprlen; @@ -5186,8 +5186,8 @@ static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str, // Find the end of each line and save it into the array. if (str_list) { - for (char_u **ss = (char_u **)str; *ss != NULL; ss++, lnum++) { - size_t ss_len = STRLEN(*ss); + for (char **ss = (char **)str; *ss != NULL; ss++, lnum++) { + size_t ss_len = strlen(*ss); pp[lnum] = xmemdupz(*ss, ss_len); if (ss_len > maxlen) { maxlen = ss_len; @@ -5294,7 +5294,7 @@ static varnumber_T line_count_info(char_u *line, varnumber_T *wc, varnumber_T *c /// @param dict when not NULL, store the info there instead of showing it. void cursor_pos_info(dict_T *dict) { - char_u *p; + char *p; char_u buf1[50]; char_u buf2[40]; linenr_T lnum; @@ -5378,7 +5378,7 @@ void cursor_pos_info(dict_T *dict) // Do extra processing for VIsual mode. if (l_VIsual_active && lnum >= min_pos.lnum && lnum <= max_pos.lnum) { - char_u *s = NULL; + char *s = NULL; long len = 0L; switch (l_VIsual_mode) { @@ -5386,11 +5386,11 @@ void cursor_pos_info(dict_T *dict) virtual_op = virtual_active(); block_prep(&oparg, &bd, lnum, false); virtual_op = kNone; - s = bd.textstart; + s = (char *)bd.textstart; len = (long)bd.textlen; break; case 'V': - s = (char_u *)ml_get(lnum); + s = ml_get(lnum); len = MAXCOL; break; case 'v': { @@ -5399,18 +5399,18 @@ void cursor_pos_info(dict_T *dict) colnr_T end_col = (lnum == max_pos.lnum) ? max_pos.col - start_col + 1 : MAXCOL; - s = (char_u *)ml_get(lnum) + start_col; + s = ml_get(lnum) + start_col; len = end_col; } break; } if (s != NULL) { - byte_count_cursor += line_count_info(s, &word_count_cursor, + byte_count_cursor += line_count_info((char_u *)s, &word_count_cursor, &char_count_cursor, len, eol_size); if (lnum == curbuf->b_ml.ml_line_count && !curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol) - && (long)STRLEN(s) < len) { + && (long)strlen(s) < len) { byte_count_cursor -= eol_size; } } @@ -5471,11 +5471,11 @@ void cursor_pos_info(dict_T *dict) (int64_t)byte_count_cursor, (int64_t)byte_count); } } else { - p = (char_u *)get_cursor_line_ptr(); + p = get_cursor_line_ptr(); validate_virtcol(); col_print((char *)buf1, sizeof(buf1), (int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1); - col_print((char *)buf2, sizeof(buf2), (int)STRLEN(p), linetabsize(p)); + col_print((char *)buf2, sizeof(buf2), (int)strlen(p), linetabsize((char_u *)p)); if (char_count_cursor == byte_count_cursor && char_count == byte_count) { @@ -5512,14 +5512,14 @@ void cursor_pos_info(dict_T *dict) } if (dict == NULL) { // Don't shorten this message, the user asked for it. - p = (char_u *)p_shm; + p = p_shm; p_shm = ""; if (p_ch < 1) { msg_start(); msg_scroll = true; } msg((char *)IObuff); - p_shm = (char *)p; + p_shm = p; } } @@ -6554,8 +6554,8 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet) if (TV_LIST_ITEM_TV(tv_list_last(res))->v_type != VAR_STRING) { goto err; } - char_u *regtype = (char_u *)TV_LIST_ITEM_TV(tv_list_last(res))->vval.v_string; - if (regtype == NULL || STRLEN(regtype) > 1) { + char *regtype = TV_LIST_ITEM_TV(tv_list_last(res))->vval.v_string; + if (regtype == NULL || strlen(regtype) > 1) { goto err; } switch (regtype[0]) { -- cgit From bc798dfd8cea9a5f93461e05dcb8409b6d96afc0 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 16 Oct 2022 08:01:44 +0800 Subject: vim-patch:9.0.0765: with a Visual block a put command column may go negative (#20676) Problem: With a Visual block a put command column may go negative. Solution: Check that the column does not become negative. https://github.com/vim/vim/commit/36343ae0fb7247e060abfd35fb8e4337b33abb4b --- src/nvim/ops.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 8b2fea9535..71e754537d 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3370,6 +3370,9 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // adjust '] mark curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1; curbuf->b_op_end.col = bd.textcol + (colnr_T)totlen - 1; + if (curbuf->b_op_end.col < 0) { + curbuf->b_op_end.col = 0; + } curbuf->b_op_end.coladd = 0; if (flags & PUT_CURSEND) { colnr_T len; -- cgit From c8fbf39d474b1140bee10edbcf36305ea49bf863 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 16 Oct 2022 08:34:09 +0800 Subject: vim-patch:9.0.0764: indent and option tests fail Problem: Indent and option tests fail. Solution: Change OP_INDENT. Add entry to options test table. https://github.com/vim/vim/commit/c8b673557390e5cd20bc0a4c2786d0db1d77a24c --- src/nvim/ops.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 71e754537d..29008200a7 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -6206,7 +6206,11 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) // If 'equalprg' is empty, do the indenting internally. if (oap->op_type == OP_INDENT && *get_equalprg() == NUL) { if (curbuf->b_p_lisp) { - op_reindent(oap, get_lisp_indent); + if (use_indentexpr_for_lisp()) { + op_reindent(oap, get_expr_indent); + } else { + op_reindent(oap, get_lisp_indent); + } break; } op_reindent(oap, -- cgit From b05d1943f063c382ea96b76d250877bc58297314 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 1 Nov 2022 15:39:49 +0100 Subject: build(lint): remove clint.py rules for braces #20880 Uncrustify is the source of truth where possible. Remove any redundant checks from clint.py. See also https://github.com/neovim/neovim/pull/18563 --- src/nvim/ops.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 29008200a7..7f8a5b6f2e 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -95,8 +95,7 @@ struct block_def { // The names of operators. // IMPORTANT: Index must correspond with defines in vim.h!!! // The third field indicates whether the operator always works on lines. -static char opchars[][3] = -{ +static char opchars[][3] = { { NUL, NUL, 0 }, // OP_NOP { 'd', NUL, OPF_CHANGE }, // OP_DELETE { 'y', NUL, 0 }, // OP_YANK -- cgit From 4716a578ae0c3516d685495bb55e40c939a4ac87 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 23 Oct 2022 10:17:45 +0200 Subject: docs: fix typos --- src/nvim/ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 7f8a5b6f2e..2d53918ded 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3272,7 +3272,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) shortline = (vcol < col) || (vcol == col && !*ptr); - if (vcol < col) { // line too short, padd with spaces + if (vcol < col) { // line too short, pad with spaces bd.startspaces = col - vcol; } else if (vcol > col) { bd.endspaces = vcol - col; -- cgit From c00d241981f292a6529242bb98ed16cfc8c53ae4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 7 Nov 2022 13:37:22 +0800 Subject: vim-patch:8.2.3788: lambda for option that is a function may be freed Problem: Lambda for option that is a function may be garbage collected. Solution: Set a reference in the funcref. (Yegappan Lakshmanan, closes vim/vim#9330) https://github.com/vim/vim/commit/6ae8fae8696623b527c7fb22567f6a3705b2f0dd Co-authored-by: Yegappan Lakshmanan --- src/nvim/ops.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 2d53918ded..65fc42bc08 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5606,6 +5606,13 @@ void free_operatorfunc_option(void) } #endif +/// Mark the global 'operatorfunc' callback with "copyID" so that it is not +/// garbage collected. +bool set_ref_in_opfunc(int copyID) +{ + return set_ref_in_callback(&opfunc_cb, copyID, NULL, NULL); +} + /// Handle the "g@" operator: call 'operatorfunc'. static void op_function(const oparg_T *oap) FUNC_ATTR_NONNULL_ALL -- cgit From eee956051637a5dff02ba6c6083fbffc87c0c96e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 12 Nov 2022 07:43:36 +0800 Subject: vim-patch:9.0.0861: solution for "!!sort" in closed fold is not optimal (#21027) Problem: Solution for "!!sort" in closed fold is not optimal. Solution: Use a different range instead of the subtle difference in handling a range with an offset. (issue vim/vim#11487) https://github.com/vim/vim/commit/9954dc39ea090cee6bf41c888c41e60d9f52c3b8 Co-authored-by: Bram Moolenaar --- src/nvim/ops.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 65fc42bc08..8656b4265d 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5555,13 +5555,22 @@ static void op_colon(oparg_T *oap) } else { stuffnumReadbuff((long)oap->start.lnum); } - if (oap->end.lnum != oap->start.lnum) { + + // When using !! on a closed fold the range ".!" works best to operate + // on, it will be made the whole closed fold later. + linenr_T endOfStartFold = oap->start.lnum; + (void)hasFolding(oap->start.lnum, NULL, &endOfStartFold); + if (oap->end.lnum != oap->start.lnum && oap->end.lnum != endOfStartFold) { + // Make it a range with the end line. stuffcharReadbuff(','); if (oap->end.lnum == curwin->w_cursor.lnum) { stuffcharReadbuff('.'); } else if (oap->end.lnum == curbuf->b_ml.ml_line_count) { stuffcharReadbuff('$'); - } else if (oap->start.lnum == curwin->w_cursor.lnum) { + } else if (oap->start.lnum == curwin->w_cursor.lnum + // do not use ".+number" for a closed fold, it would count + // folded lines twice + && !hasFolding(oap->end.lnum, NULL, NULL)) { stuffReadbuff(".+"); stuffnumReadbuff(oap->line_count - 1); } else { -- cgit From 66360675cf4d091b7460e4a8e1435c13216c1929 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 11 Sep 2022 17:12:44 +0200 Subject: build: allow IWYU to fix includes for all .c files Allow Include What You Use to remove unnecessary includes and only include what is necessary. This helps with reducing compilation times and makes it easier to visualise which dependencies are actually required. Work on https://github.com/neovim/neovim/issues/549, but doesn't close it since this only works fully for .c files and not headers. --- src/nvim/ops.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 8656b4265d..f61c978f3c 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5,13 +5,18 @@ // op_change, op_yank, do_put, do_join #include +#include #include +#include #include +#include +#include #include -#include "klib/kvec.h" +#include "nvim/api/private/defs.h" #include "nvim/ascii.h" #include "nvim/assert.h" +#include "nvim/autocmd.h" #include "nvim/buffer.h" #include "nvim/change.h" #include "nvim/charset.h" @@ -20,16 +25,19 @@ #include "nvim/edit.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" -#include "nvim/ex_cmds.h" #include "nvim/ex_cmds2.h" +#include "nvim/ex_cmds_defs.h" #include "nvim/ex_getln.h" #include "nvim/extmark.h" #include "nvim/fold.h" +#include "nvim/garray.h" #include "nvim/getchar.h" +#include "nvim/gettext.h" #include "nvim/globals.h" +#include "nvim/highlight_defs.h" #include "nvim/indent.h" #include "nvim/indent_c.h" -#include "nvim/log.h" +#include "nvim/keycodes.h" #include "nvim/macros.h" #include "nvim/mark.h" #include "nvim/mbyte.h" @@ -43,13 +51,14 @@ #include "nvim/option.h" #include "nvim/os/input.h" #include "nvim/os/time.h" -#include "nvim/path.h" #include "nvim/plines.h" +#include "nvim/screen.h" #include "nvim/search.h" #include "nvim/state.h" #include "nvim/strings.h" #include "nvim/terminal.h" #include "nvim/textformat.h" +#include "nvim/types.h" #include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/vim.h" -- cgit From c70d90dbfdf67bb009d2976a5d0760be4010e533 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 15 Nov 2022 23:02:48 +0800 Subject: vim-patch:9.0.0884: mouse shape remains in op-pending mode after failed change (#21066) Problem: Mouse shape remains in op-pending mode after failed change. Solution: Reset finish_op and restore it. (closes vim/vim#11545) https://github.com/vim/vim/commit/cdeb65729d96c90320b9009e583ade305c396f29 --- src/nvim/ops.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index f61c978f3c..f1814291b8 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2483,8 +2483,14 @@ int op_change(oparg_T *oap) fix_indent(); } + // Reset finish_op now, don't want it set inside edit(). + const bool save_finish_op = finish_op; + finish_op = false; + retval = edit(NUL, false, (linenr_T)1); + finish_op = save_finish_op; + // In Visual block mode, handle copying the new text to all lines of the // block. // Don't repeat the insert when Insert mode ended with CTRL-C. @@ -5635,8 +5641,6 @@ bool set_ref_in_opfunc(int copyID) static void op_function(const oparg_T *oap) FUNC_ATTR_NONNULL_ALL { - const TriState save_virtual_op = virtual_op; - const bool save_finish_op = finish_op; const pos_T orig_start = curbuf->b_op_start; const pos_T orig_end = curbuf->b_op_end; @@ -5663,9 +5667,11 @@ static void op_function(const oparg_T *oap) // Reset virtual_op so that 'virtualedit' can be changed in the // function. + const TriState save_virtual_op = virtual_op; virtual_op = kNone; // Reset finish_op so that mode() returns the right value. + const bool save_finish_op = finish_op; finish_op = false; typval_T rettv; @@ -6205,8 +6211,6 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) // Restore linebreak, so that when the user edits it looks as before. restore_lbr(lbr_saved); - // Reset finish_op now, don't want it set inside edit(). - finish_op = false; if (op_change(oap)) { // will call edit() cap->retval |= CA_COMMAND_BUSY; } -- cgit From 40f3f75867bf03abfd90e0389a38197a00d37af1 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/ops.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index f1814291b8..0cae0e854f 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -80,7 +80,7 @@ struct block_def { int startspaces; // 'extra' cols before first char int endspaces; // 'extra' cols after last char int textlen; // chars in block - char_u *textstart; // pointer to 1st char (partially) in block + char *textstart; // pointer to 1st char (partially) in block colnr_T textcol; // index of chars (partially) in block colnr_T start_vcol; // start col of 1st char wholly inside block colnr_T end_vcol; // start col of 1st char wholly after block @@ -90,7 +90,7 @@ struct block_def { int pre_whitesp; // screen cols of ws before block int pre_whitesp_c; // chars of ws before block colnr_T end_char_vcols; // number of vcols of post-block char - colnr_T start_char_vcols; // number of vcols of pre-block char + colnr_T start_char_vcols; // number of vcols of pre-block char }; #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -358,7 +358,7 @@ static void shift_block(oparg_T *oap, int amount) return; // multiplication overflow } - char_u *const oldp = (char_u *)get_cursor_line_ptr(); + char *const oldp = get_cursor_line_ptr(); int startcol, oldlen, newlen; @@ -369,9 +369,9 @@ static void shift_block(oparg_T *oap, int amount) // 4. Construct new string total += bd.pre_whitesp; // all virtual WS up to & incl a split TAB colnr_T ws_vcol = bd.start_vcol - bd.pre_whitesp; - char_u *old_textstart = bd.textstart; + char *old_textstart = bd.textstart; if (bd.startspaces) { - if (utfc_ptr2len((char *)bd.textstart) == 1) { + if (utfc_ptr2len(bd.textstart) == 1) { bd.textstart++; } else { ws_vcol = 0; @@ -382,13 +382,13 @@ static void shift_block(oparg_T *oap, int amount) // TODO(vim): is passing bd.textstart for start of the line OK? chartabsize_T cts; init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, - bd.start_vcol, (char *)bd.textstart, (char *)bd.textstart); + bd.start_vcol, bd.textstart, bd.textstart); while (ascii_iswhite(*cts.cts_ptr)) { incr = lbr_chartabsize_adv(&cts); total += incr; cts.cts_vcol += incr; } - bd.textstart = (char_u *)cts.cts_ptr; + bd.textstart = cts.cts_ptr; bd.start_vcol = cts.cts_vcol; clear_chartabsize_arg(&cts); @@ -403,7 +403,7 @@ static void shift_block(oparg_T *oap, int amount) // if we're splitting a TAB, allow for it int col_pre = bd.pre_whitesp_c - (bd.startspaces != 0); bd.textcol -= col_pre; - const int len = (int)STRLEN(bd.textstart) + 1; + const int len = (int)strlen(bd.textstart) + 1; int col = bd.textcol + i + j + len; assert(col >= 0); newp = (char_u *)xmalloc((size_t)col); @@ -419,14 +419,14 @@ static void shift_block(oparg_T *oap, int amount) } else { // left colnr_T destination_col; // column to which text in block will // be shifted - char_u *verbatim_copy_end; // end of the part of the line which is + char *verbatim_copy_end; // end of the part of the line which is // copied verbatim colnr_T verbatim_copy_width; // the (displayed) width of this part // of line size_t fill; // nr of spaces that replace a TAB size_t new_line_len; // the length of the line after the // block shift - char *non_white = (char *)bd.textstart; + char *non_white = bd.textstart; // Firstly, let's find the first non-whitespace character that is // displayed after the block's start column and the character's column @@ -446,7 +446,7 @@ static void shift_block(oparg_T *oap, int amount) chartabsize_T cts; init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, - non_white_col, (char *)bd.textstart, non_white); + non_white_col, bd.textstart, non_white); while (ascii_iswhite(*cts.cts_ptr)) { incr = lbr_chartabsize_adv(&cts); cts.cts_vcol += incr; @@ -475,7 +475,7 @@ static void shift_block(oparg_T *oap, int amount) verbatim_copy_width -= bd.start_char_vcols; } init_chartabsize_arg(&cts, curwin, 0, verbatim_copy_width, - (char *)bd.textstart, (char *)verbatim_copy_end); + bd.textstart, verbatim_copy_end); while (cts.cts_vcol < destination_col) { incr = lbr_chartabsize(&cts); if (cts.cts_vcol + incr > destination_col) { @@ -485,7 +485,7 @@ static void shift_block(oparg_T *oap, int amount) MB_PTR_ADV(cts.cts_ptr); } verbatim_copy_width = cts.cts_vcol; - verbatim_copy_end = (char_u *)cts.cts_ptr; + verbatim_copy_end = cts.cts_ptr; clear_chartabsize_arg(&cts); // If "destination_col" is different from the width of the initial @@ -504,7 +504,7 @@ static void shift_block(oparg_T *oap, int amount) newp = (char_u *)xmalloc(new_line_len); startcol = (int)verbatim_diff; - oldlen = bd.textcol + (int)(non_white - (char *)bd.textstart) - (int)verbatim_diff; + oldlen = bd.textcol + (int)(non_white - bd.textstart) - (int)verbatim_diff; newlen = (int)fill; memmove(newp, oldp, verbatim_diff); memset(newp + verbatim_diff, ' ', fill); @@ -2095,7 +2095,7 @@ void op_tilde(oparg_T *oap) for (;;) { did_change |= swapchars(oap->op_type, &pos, pos.lnum == oap->end.lnum ? oap->end.col + 1 : - (int)STRLEN(ml_get_pos(&pos))); + (int)strlen(ml_get_pos(&pos))); if (ltoreq(oap->end, pos) || inc(&pos) == -1) { break; } @@ -2138,7 +2138,7 @@ static int swapchars(int op_type, pos_T *pos, int length) int did_change = 0; for (int todo = length; todo > 0; todo--) { - const int len = utfc_ptr2len((char *)ml_get_pos(pos)); + const int len = utfc_ptr2len(ml_get_pos(pos)); // we're counting bytes, not characters if (len > 0) { @@ -2727,7 +2727,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) } else { bd.textlen = endcol - startcol + oap->inclusive; } - bd.textstart = (char_u *)p + startcol; + bd.textstart = p + startcol; yank_copy_line(reg, &bd, y_idx, false); break; } @@ -2838,7 +2838,7 @@ static void yank_copy_line(yankreg_T *reg, struct block_def *bd, size_t y_idx, int s = bd->textlen + bd->endspaces; while (s > 0 && ascii_iswhite(*(bd->textstart + s - 1))) { - s = s - utf_head_off((char *)bd->textstart, (char *)bd->textstart + s - 1) - 1; + s = s - utf_head_off(bd->textstart, bd->textstart + s - 1) - 1; pnew--; } } @@ -4346,7 +4346,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool bdp->textlen = (int)(pend - pstart); } bdp->textcol = (colnr_T)(pstart - line); - bdp->textstart = (char_u *)pstart; + bdp->textstart = pstart; restore_lbr(lbr_saved); } @@ -5403,7 +5403,7 @@ void cursor_pos_info(dict_T *dict) virtual_op = virtual_active(); block_prep(&oparg, &bd, lnum, false); virtual_op = kNone; - s = (char *)bd.textstart; + s = bd.textstart; len = (long)bd.textlen; break; case 'V': @@ -6085,7 +6085,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) // Include the trailing byte of a multi-byte char. if (oap->inclusive) { - const int l = utfc_ptr2len((char *)ml_get_pos(&oap->end)); + const int l = utfc_ptr2len(ml_get_pos(&oap->end)); if (l > 1) { oap->end.col += l - 1; } -- cgit From 3b96ccf7d35be90e49029dec76344d3d92ad91dc Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 26 Nov 2022 18:57:46 +0100 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/ops.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 0cae0e854f..d2dba41959 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1080,7 +1080,7 @@ static char_u *execreg_line_continuation(char **lines, size_t *idx) /// @return FAIL for failure, OK otherwise int do_execreg(int regname, int colon, int addcr, int silent) { - char_u *p; + char *p; int retval = OK; if (regname == '@') { // repeat previous one @@ -1109,34 +1109,34 @@ int do_execreg(int regname, int colon, int addcr, int silent) // don't keep the cmdline containing @: XFREE_CLEAR(new_last_cmdline); // Escape all control characters with a CTRL-V - p = vim_strsave_escaped_ext((char_u *)last_cmdline, - (char_u *)"\001\002\003\004\005\006\007" - "\010\011\012\013\014\015\016\017" - "\020\021\022\023\024\025\026\027" - "\030\031\032\033\034\035\036\037", - Ctrl_V, false); + p = (char *)vim_strsave_escaped_ext((char_u *)last_cmdline, + (char_u *)"\001\002\003\004\005\006\007" + "\010\011\012\013\014\015\016\017" + "\020\021\022\023\024\025\026\027" + "\030\031\032\033\034\035\036\037", + Ctrl_V, false); // When in Visual mode "'<,'>" will be prepended to the command. // Remove it when it's already there. - if (VIsual_active && STRNCMP(p, "'<,'>", 5) == 0) { - retval = put_in_typebuf(p + 5, true, true, silent); + if (VIsual_active && strncmp(p, "'<,'>", 5) == 0) { + retval = put_in_typebuf((char_u *)p + 5, true, true, silent); } else { - retval = put_in_typebuf(p, true, true, silent); + retval = put_in_typebuf((char_u *)p, true, true, silent); } xfree(p); } else if (regname == '=') { - p = (char_u *)get_expr_line(); + p = get_expr_line(); if (p == NULL) { return FAIL; } - retval = put_in_typebuf(p, true, colon, silent); + retval = put_in_typebuf((char_u *)p, true, colon, silent); xfree(p); } else if (regname == '.') { // use last inserted text - p = get_last_insert_save(); + p = (char *)get_last_insert_save(); if (p == NULL) { emsg(_(e_noinstext)); return FAIL; } - retval = put_in_typebuf(p, false, colon, silent); + retval = put_in_typebuf((char_u *)p, false, colon, silent); xfree(p); } else { yankreg_T *reg = get_yank_register(regname, YREG_PASTE); @@ -1162,7 +1162,7 @@ int do_execreg(int regname, int colon, int addcr, int silent) char_u *str = (char_u *)reg->y_array[i]; bool free_str = false; if (colon && i > 0) { - p = (char_u *)skipwhite((char *)str); + p = skipwhite((char *)str); if (*p == '\\' || (p[0] == '"' && p[1] == '\\' && p[2] == ' ')) { str = execreg_line_continuation(reg->y_array, &i); free_str = true; -- cgit From 5529b07316b75913188c44698aed6c0f866c5da9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 4 Jan 2023 07:17:54 +0800 Subject: fix(clipboard): show provider warning when not during batch changes #21451 It is strange that Ex commands that explicitly interact with the clipboard show provider warning, but Normal mode commands do not. --- src/nvim/ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d2dba41959..ccfd3ab834 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -6433,7 +6433,7 @@ static yankreg_T *adjust_clipboard_name(int *name, bool quiet, bool writing) } if (!eval_has_provider("clipboard")) { - if (batch_change_count == 1 && !quiet + if (batch_change_count <= 1 && !quiet && (!clipboard_didwarn || (explicit_cb_reg && !redirecting()))) { clipboard_didwarn = true; // Do NOT error (emsg()) here--if it interrupts :redir we get into -- cgit From 149209400383c673fdb4fdd1c9a7639139f17936 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 9 Jan 2023 14:13:06 +0100 Subject: refactor: replace char_u with char 17 - remove STRLCPY (#21235) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/ops.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index ccfd3ab834..2566108618 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2440,7 +2440,7 @@ int op_change(oparg_T *oap) long pre_indent = 0; char_u *newp; char *firstline; - char_u *ins_text; + char *ins_text; char *oldp; struct block_def bd; @@ -2510,8 +2510,8 @@ int op_change(oparg_T *oap) if (ins_len > 0) { // Subsequent calls to ml_get() flush the firstline data - take a // copy of the inserted text. - ins_text = (char_u *)xmalloc((size_t)(ins_len + 1)); - STRLCPY(ins_text, firstline + bd.textcol, ins_len + 1); + ins_text = xmalloc((size_t)(ins_len + 1)); + xstrlcpy(ins_text, firstline + bd.textcol, (size_t)ins_len + 1); for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; linenr++) { block_prep(oap, &bd, linenr, true); -- cgit From 50f03773f4b9f4638489ccfd0503dc9e39e5de78 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 9 Jan 2023 15:37:34 +0100 Subject: refactor: replace char_u with char 18 (#21237) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/ops.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 2566108618..ec3ceca5bc 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -264,10 +264,10 @@ void op_shift(oparg_T *oap, int curs_top, int amount) "%" PRId64 " line %sed %d times", amount); char *msg_line_plural = NGETTEXT("%" PRId64 " lines %sed %d time", "%" PRId64 " lines %sed %d times", amount); - vim_snprintf((char *)IObuff, IOSIZE, + vim_snprintf(IObuff, IOSIZE, NGETTEXT(msg_line_single, msg_line_plural, oap->line_count), (int64_t)oap->line_count, op, amount); - msg_attr_keep((char *)IObuff, 0, true, false); + msg_attr_keep(IObuff, 0, true, false); } if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { @@ -5467,7 +5467,7 @@ void cursor_pos_info(dict_T *dict) if (char_count_cursor == byte_count_cursor && char_count == byte_count) { - vim_snprintf((char *)IObuff, IOSIZE, + vim_snprintf(IObuff, IOSIZE, _("Selected %s%" PRId64 " of %" PRId64 " Lines;" " %" PRId64 " of %" PRId64 " Words;" " %" PRId64 " of %" PRId64 " Bytes"), @@ -5476,7 +5476,7 @@ void cursor_pos_info(dict_T *dict) (int64_t)word_count_cursor, (int64_t)word_count, (int64_t)byte_count_cursor, (int64_t)byte_count); } else { - vim_snprintf((char *)IObuff, IOSIZE, + vim_snprintf(IObuff, IOSIZE, _("Selected %s%" PRId64 " of %" PRId64 " Lines;" " %" PRId64 " of %" PRId64 " Words;" " %" PRId64 " of %" PRId64 " Chars;" @@ -5496,7 +5496,7 @@ void cursor_pos_info(dict_T *dict) if (char_count_cursor == byte_count_cursor && char_count == byte_count) { - vim_snprintf((char *)IObuff, IOSIZE, + vim_snprintf(IObuff, IOSIZE, _("Col %s of %s; Line %" PRId64 " of %" PRId64 ";" " Word %" PRId64 " of %" PRId64 ";" " Byte %" PRId64 " of %" PRId64 ""), @@ -5506,7 +5506,7 @@ void cursor_pos_info(dict_T *dict) (int64_t)word_count_cursor, (int64_t)word_count, (int64_t)byte_count_cursor, (int64_t)byte_count); } else { - vim_snprintf((char *)IObuff, IOSIZE, + vim_snprintf(IObuff, IOSIZE, _("Col %s of %s; Line %" PRId64 " of %" PRId64 ";" " Word %" PRId64 " of %" PRId64 ";" " Char %" PRId64 " of %" PRId64 ";" @@ -5524,7 +5524,7 @@ void cursor_pos_info(dict_T *dict) bom_count = bomb_size(); if (dict == NULL && bom_count > 0) { const size_t len = strlen(IObuff); - vim_snprintf((char *)IObuff + len, IOSIZE - len, + vim_snprintf(IObuff + len, IOSIZE - len, _("(+%" PRId64 " for BOM)"), (int64_t)bom_count); } if (dict == NULL) { @@ -5535,7 +5535,7 @@ void cursor_pos_info(dict_T *dict) msg_start(); msg_scroll = true; } - msg((char *)IObuff); + msg(IObuff); p_shm = p; } } -- cgit From ef6750332008b7b61dde9eeab0da454bf3323ebb Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 10 Jan 2023 03:28:01 +0100 Subject: refactor: replace char_u with char 19 (#21241) * refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/ops.c | 100 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 50 insertions(+), 50 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index ec3ceca5bc..03ce345b78 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -335,7 +335,7 @@ static void shift_block(oparg_T *oap, int amount) { const bool left = (oap->op_type == OP_LSHIFT); const int oldstate = State; - char_u *newp; + char *newp; const int oldcol = curwin->w_cursor.col; const int sw_val = (int)get_sw_value_indent(curbuf); const int ts_val = (int)curbuf->b_p_ts; @@ -406,7 +406,7 @@ static void shift_block(oparg_T *oap, int amount) const int len = (int)strlen(bd.textstart) + 1; int col = bd.textcol + i + j + len; assert(col >= 0); - newp = (char_u *)xmalloc((size_t)col); + newp = xmalloc((size_t)col); memset(newp, NUL, (size_t)col); memmove(newp, oldp, (size_t)bd.textcol); startcol = bd.textcol; @@ -502,7 +502,7 @@ static void shift_block(oparg_T *oap, int amount) // - the rest of the line, pointed to by non_white. new_line_len = verbatim_diff + fill + strlen(non_white) + 1; - newp = (char_u *)xmalloc(new_line_len); + newp = xmalloc(new_line_len); startcol = (int)verbatim_diff; oldlen = bd.textcol + (int)(non_white - bd.textstart) - (int)verbatim_diff; newlen = (int)fill; @@ -511,7 +511,7 @@ static void shift_block(oparg_T *oap, int amount) STRMOVE(newp + verbatim_diff + fill, non_white); } // replace the line - ml_replace(curwin->w_cursor.lnum, (char *)newp, false); + ml_replace(curwin->w_cursor.lnum, newp, false); changed_bytes(curwin->w_cursor.lnum, bd.textcol); extmark_splice_cols(curbuf, (int)curwin->w_cursor.lnum - 1, startcol, oldlen, newlen, @@ -636,7 +636,7 @@ static void block_insert(oparg_T *oap, char *s, int b_insert, struct block_def * void op_reindent(oparg_T *oap, Indenter how) { long i = 0; - char_u *l; + char *l; int amount; linenr_T first_changed = 0; linenr_T last_changed = 0; @@ -666,7 +666,7 @@ void op_reindent(oparg_T *oap, Indenter how) // indented, unless there is only one line. if (i != oap->line_count - 1 || oap->line_count == 1 || how != get_lisp_indent) { - l = (char_u *)skipwhite(get_cursor_line_ptr()); + l = skipwhite(get_cursor_line_ptr()); if (*l == NUL) { // empty or blank line amount = 0; } else { @@ -721,16 +721,16 @@ static char *expr_line = NULL; /// @return '=' when OK, NUL otherwise. int get_expr_register(void) { - char_u *new_line; + char *new_line; - new_line = getcmdline('=', 0L, 0, true); + new_line = (char *)getcmdline('=', 0L, 0, true); if (new_line == NULL) { return NUL; } if (*new_line == NUL) { // use previous line xfree(new_line); } else { - set_expr_line((char *)new_line); + set_expr_line(new_line); } return '='; } @@ -902,7 +902,7 @@ bool yank_register_mline(int regname) /// @return FAIL for failure, OK otherwise. int do_record(int c) { - char_u *p; + char *p; static int regname; yankreg_T *old_y_previous; int retval; @@ -927,10 +927,10 @@ int do_record(int c) dict_T *dict = get_v_event(&save_v_event); // The recorded text contents. - p = get_recorded(); + p = (char *)get_recorded(); if (p != NULL) { // Remove escaping for K_SPECIAL in multi-byte chars. - vim_unescape_ks(p); + vim_unescape_ks((char_u *)p); (void)tv_dict_add_str(dict, S_LEN("regcontents"), (const char *)p); } @@ -960,7 +960,7 @@ int do_record(int c) // restore the current register name. old_y_previous = y_previous; - retval = stuff_yank(regname, (char *)p); + retval = stuff_yank(regname, p); y_previous = old_y_previous; } @@ -996,13 +996,13 @@ static int stuff_yank(int regname, char *p) yankreg_T *reg = get_yank_register(regname, YREG_YANK); if (is_append_register(regname) && reg->y_array != NULL) { char **pp = &(reg->y_array[reg->y_size - 1]); - char_u *lp = xmalloc(strlen(*pp) + strlen(p) + 1); + char *lp = xmalloc(strlen(*pp) + strlen(p) + 1); STRCPY(lp, *pp); // TODO(philix): use xstpcpy() in stuff_yank() STRCAT(lp, p); xfree(p); xfree(*pp); - *pp = (char *)lp; + *pp = lp; } else { free_register(reg); set_yreg_additional_data(reg, NULL); @@ -1037,13 +1037,13 @@ static char_u *execreg_line_continuation(char **lines, size_t *idx) garray_T ga; ga_init(&ga, (int)sizeof(char_u), 400); - char_u *p; + char *p; // search backwards to find the first line of this command. // Any line not starting with \ or "\ is the start of the // command. while (--i > 0) { - p = (char_u *)skipwhite(lines[i]); + p = skipwhite(lines[i]); if (*p != '\\' && (p[0] != '"' || p[1] != '\\' || p[2] != ' ')) { break; } @@ -1053,14 +1053,14 @@ static char_u *execreg_line_continuation(char **lines, size_t *idx) // join all the lines ga_concat(&ga, lines[cmd_start]); for (size_t j = cmd_start + 1; j <= cmd_end; j++) { - p = (char_u *)skipwhite(lines[j]); + p = skipwhite(lines[j]); if (*p == '\\') { // Adjust the growsize to the current length to // speed up concatenating many lines. if (ga.ga_len > 400) { ga_set_growsize(&ga, MIN(ga.ga_len, 8000)); } - ga_concat(&ga, (char *)(p + 1)); + ga_concat(&ga, p + 1); } } ga_append(&ga, NUL); @@ -1159,16 +1159,16 @@ int do_execreg(int regname, int colon, int addcr, int silent) } // Handle line-continuation for :@ - char_u *str = (char_u *)reg->y_array[i]; + char *str = reg->y_array[i]; bool free_str = false; if (colon && i > 0) { - p = skipwhite((char *)str); + p = skipwhite(str); if (*p == '\\' || (p[0] == '"' && p[1] == '\\' && p[2] == ' ')) { - str = execreg_line_continuation(reg->y_array, &i); + str = (char *)execreg_line_continuation(reg->y_array, &i); free_str = true; } } - escaped = vim_strsave_escape_ks((char *)str); + escaped = vim_strsave_escape_ks(str); if (free_str) { xfree(str); } @@ -1822,7 +1822,7 @@ static int op_replace(oparg_T *oap, int c) char *newp, *oldp; colnr_T oldlen; struct block_def bd; - char_u *after_p = NULL; + char *after_p = NULL; int had_ctrl_v_cr = false; if ((curbuf->b_ml.ml_flags & ML_EMPTY) || oap->empty) { @@ -1934,7 +1934,7 @@ static int op_replace(oparg_T *oap, int c) } else { // Replacing with \r or \n means splitting the line. after_p_len = (size_t)col; - after_p = (char_u *)xmalloc(after_p_len); + after_p = xmalloc(after_p_len); memmove(after_p, oldp, after_p_len); newrows = 1; } @@ -1943,7 +1943,7 @@ static int op_replace(oparg_T *oap, int c) curbuf_splice_pending++; linenr_T baselnum = curwin->w_cursor.lnum; if (after_p != NULL) { - ml_append(curwin->w_cursor.lnum++, (char *)after_p, (int)after_p_len, false); + ml_append(curwin->w_cursor.lnum++, after_p, (int)after_p_len, false); appended_lines_mark(curwin->w_cursor.lnum, 1L); oap->end.lnum++; xfree(after_p); @@ -2438,7 +2438,7 @@ int op_change(oparg_T *oap) long ins_len; long pre_textlen = 0; long pre_indent = 0; - char_u *newp; + char *newp; char *firstline; char *ins_text; char *oldp; @@ -2538,7 +2538,7 @@ int op_change(oparg_T *oap) offset += ins_len; oldp += bd.textcol; STRMOVE(newp + offset, oldp); - ml_replace(linenr, (char *)newp, false); + ml_replace(linenr, newp, false); extmark_splice_cols(curbuf, (int)linenr - 1, bd.textcol, 0, vpos.coladd + (int)ins_len, kExtmarkUndo); } @@ -2619,7 +2619,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) size_t yanklines = (size_t)oap->line_count; linenr_T yankendlnum = oap->end.lnum; char *p; - char_u *pnew; + char *pnew; struct block_def bd; yankreg_T *curr = reg; // copy of current register @@ -2760,7 +2760,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) STRCAT(pnew, reg->y_array[0]); xfree(curr->y_array[j]); xfree(reg->y_array[0]); - curr->y_array[j++] = (char *)pnew; + curr->y_array[j++] = pnew; y_idx = 1; } else { y_idx = 0; @@ -2826,8 +2826,8 @@ static void yank_copy_line(yankreg_T *reg, struct block_def *bd, size_t y_idx, } int size = bd->startspaces + bd->endspaces + bd->textlen; assert(size >= 0); - char_u *pnew = xmallocz((size_t)size); - reg->y_array[y_idx] = (char *)pnew; + char *pnew = xmallocz((size_t)size); + reg->y_array[y_idx] = pnew; memset(pnew, ' ', (size_t)bd->startspaces); pnew += bd->startspaces; memmove(pnew, bd->textstart, (size_t)bd->textlen); @@ -3007,11 +3007,11 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // strlen(ml_get(curwin->w_cursor.lnum)). With 'virtualedit' and the // cursor past the end of the line, curwin->w_cursor.coladd is // incremented instead of curwin->w_cursor.col. - char_u *cursor_pos = (char_u *)get_cursor_pos_ptr(); + char *cursor_pos = get_cursor_pos_ptr(); bool one_past_line = (*cursor_pos == NUL); bool eol = false; if (!one_past_line) { - eol = (*(cursor_pos + utfc_ptr2len((char *)cursor_pos)) == NUL); + eol = (*(cursor_pos + utfc_ptr2len(cursor_pos)) == NUL); } bool ve_allows = (cur_ve_flags == VE_ALL || cur_ve_flags == VE_ONEMORE); @@ -3763,10 +3763,10 @@ int get_unname_register(void) /// ":dis" and ":registers": Display the contents of the yank registers. void ex_display(exarg_T *eap) { - char_u *p; + char *p; yankreg_T *yb; int name; - char_u *arg = (char_u *)eap->arg; + char *arg = eap->arg; int clen; int type; @@ -3788,7 +3788,7 @@ void ex_display(exarg_T *eap) type = 'b'; break; } - if (arg != NULL && vim_strchr((char *)arg, name) == NULL) { + if (arg != NULL && vim_strchr(arg, name) == NULL) { continue; // did not ask for this register } @@ -3832,10 +3832,10 @@ void ex_display(exarg_T *eap) msg_puts_attr("^J", attr); n -= 2; } - for (p = (char_u *)yb->y_array[j]; - *p != NUL && (n -= ptr2cells((char *)p)) >= 0; p++) { // -V1019 - clen = utfc_ptr2len((char *)p); - msg_outtrans_len((char *)p, clen); + for (p = yb->y_array[j]; + *p != NUL && (n -= ptr2cells(p)) >= 0; p++) { // -V1019 + clen = utfc_ptr2len(p); + msg_outtrans_len(p, clen); p += clen - 1; } } @@ -3848,15 +3848,15 @@ void ex_display(exarg_T *eap) } // display last inserted text - if ((p = get_last_insert()) != NULL - && (arg == NULL || vim_strchr((char *)arg, '.') != NULL) && !got_int - && !message_filtered((char *)p)) { + if ((p = (char *)get_last_insert()) != NULL + && (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int + && !message_filtered(p)) { msg_puts("\n c \". "); - dis_msg((char *)p, true); + dis_msg(p, true); } // display last command line - if (last_cmdline != NULL && (arg == NULL || vim_strchr((char *)arg, ':') != NULL) + if (last_cmdline != NULL && (arg == NULL || vim_strchr(arg, ':') != NULL) && !got_int && !message_filtered(last_cmdline)) { msg_puts("\n c \": "); dis_msg(last_cmdline, false); @@ -3864,14 +3864,14 @@ void ex_display(exarg_T *eap) // display current file name if (curbuf->b_fname != NULL - && (arg == NULL || vim_strchr((char *)arg, '%') != NULL) && !got_int + && (arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int && !message_filtered(curbuf->b_fname)) { msg_puts("\n c \"% "); dis_msg(curbuf->b_fname, false); } // display alternate file name - if ((arg == NULL || vim_strchr((char *)arg, '%') != NULL) && !got_int) { + if ((arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) { char *fname; linenr_T dummy; @@ -3883,14 +3883,14 @@ void ex_display(exarg_T *eap) // display last search pattern if (last_search_pat() != NULL - && (arg == NULL || vim_strchr((char *)arg, '/') != NULL) && !got_int + && (arg == NULL || vim_strchr(arg, '/') != NULL) && !got_int && !message_filtered((char *)last_search_pat())) { msg_puts("\n c \"/ "); dis_msg((char *)last_search_pat(), false); } // display last used expression - if (expr_line != NULL && (arg == NULL || vim_strchr((char *)arg, '=') != NULL) + if (expr_line != NULL && (arg == NULL || vim_strchr(arg, '=') != NULL) && !got_int && !message_filtered(expr_line)) { msg_puts("\n c \"= "); dis_msg(expr_line, false); -- cgit From f2141de9e462ed8976b2a59337c32a0fcba2a11d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 13 Jan 2023 00:35:39 +0100 Subject: refactor: replace char_u with char 20 (#21714) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/ops.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 03ce345b78..7ec489970d 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1109,12 +1109,12 @@ int do_execreg(int regname, int colon, int addcr, int silent) // don't keep the cmdline containing @: XFREE_CLEAR(new_last_cmdline); // Escape all control characters with a CTRL-V - p = (char *)vim_strsave_escaped_ext((char_u *)last_cmdline, - (char_u *)"\001\002\003\004\005\006\007" - "\010\011\012\013\014\015\016\017" - "\020\021\022\023\024\025\026\027" - "\030\031\032\033\034\035\036\037", - Ctrl_V, false); + p = vim_strsave_escaped_ext(last_cmdline, + "\001\002\003\004\005\006\007" + "\010\011\012\013\014\015\016\017" + "\020\021\022\023\024\025\026\027" + "\030\031\032\033\034\035\036\037", + Ctrl_V, false); // When in Visual mode "'<,'>" will be prepended to the command. // Remove it when it's already there. if (VIsual_active && strncmp(p, "'<,'>", 5) == 0) { -- cgit From e89c39d6f016a4140293755250e968e839009617 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 14 Jan 2023 08:58:28 +0100 Subject: refactor: replace char_u with char 21 (#21779) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 7ec489970d..34432c58db 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5492,7 +5492,7 @@ void cursor_pos_info(dict_T *dict) validate_virtcol(); col_print((char *)buf1, sizeof(buf1), (int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1); - col_print((char *)buf2, sizeof(buf2), (int)strlen(p), linetabsize((char_u *)p)); + col_print((char *)buf2, sizeof(buf2), (int)strlen(p), linetabsize(p)); if (char_count_cursor == byte_count_cursor && char_count == byte_count) { -- cgit