From c8c930ea785aa393ebc819139913a9e05f0ccd45 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:24:46 +0100 Subject: refactor: reduce scope of locals as per the style guide (#22206) --- src/nvim/ops.c | 104 +++++++++++++++++++++++++-------------------------------- 1 file changed, 45 insertions(+), 59 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 435ca106ab..6326130c5a 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -214,7 +214,6 @@ int get_extra_op_char(int optype) void op_shift(oparg_T *oap, int curs_top, int amount) { long i; - int first_char; int block_col = 0; if (u_save((linenr_T)(oap->start.lnum - 1), @@ -227,7 +226,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount) } for (i = oap->line_count - 1; i >= 0; i--) { - first_char = (uint8_t)(*get_cursor_line_ptr()); + int 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) { @@ -289,15 +288,13 @@ void op_shift(oparg_T *oap, int curs_top, int amount) /// @param call_changed_bytes call changed_bytes() void shift_line(int left, int round, int amount, int call_changed_bytes) { - int count; - int i, j; const int sw_val = (int)get_sw_value_indent(curbuf); - count = get_indent(); // get current indent + int count = get_indent(); // get current indent if (round) { // round off indent - i = count / sw_val; // number of 'shiftwidth' rounded down - j = count % sw_val; // extra spaces + int i = count / sw_val; // number of 'shiftwidth' rounded down + int j = count % sw_val; // extra spaces if (j && left) { // first remove extra spaces amount--; } @@ -636,8 +633,6 @@ 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 *l; - int amount; linenr_T first_changed = 0; linenr_T last_changed = 0; linenr_T start_lnum = curwin->w_cursor.lnum; @@ -652,6 +647,8 @@ void op_reindent(oparg_T *oap, Indenter how) // for each line separately, especially when undoing. if (u_savecommon(curbuf, start_lnum - 1, start_lnum + (linenr_T)oap->line_count, start_lnum + (linenr_T)oap->line_count, false) == OK) { + char *l; + int amount; for (i = oap->line_count - 1; i >= 0 && !got_int; i--) { // it's a slow thing to do, so give feedback so there's no worry // that the computer's just hung. @@ -902,7 +899,6 @@ bool yank_register_mline(int regname) /// @return FAIL for failure, OK otherwise. int do_record(int c) { - char *p; static int regname; yankreg_T *old_y_previous; int retval; @@ -927,7 +923,7 @@ int do_record(int c) dict_T *dict = get_v_event(&save_v_event); // The recorded text contents. - p = (char *)get_recorded(); + char *p = (char *)get_recorded(); if (p != NULL) { // Remove escaping for K_SPECIAL in multi-byte chars. vim_unescape_ks((char_u *)p); @@ -1149,7 +1145,6 @@ int do_execreg(int regname, int colon, int addcr, int silent) // 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 // insert NL between lines and after last line if type is kMTLineWise if (reg->y_type == kMTLineWise || i < reg->y_size - 1 || addcr) { @@ -1168,7 +1163,7 @@ int do_execreg(int regname, int colon, int addcr, int silent) free_str = true; } } - escaped = vim_strsave_escape_ks(str); + char *escaped = vim_strsave_escape_ks(str); if (free_str) { xfree(str); } @@ -1651,10 +1646,9 @@ int op_delete(oparg_T *oap) } } else { if (virtual_op) { - int endcol = 0; - // For virtualedit: break the tabs that are partly included. if (gchar_pos(&oap->start) == '\t') { + int endcol = 0; if (u_save_cursor() == FAIL) { // save first line for undo return FAIL; } @@ -1820,10 +1814,7 @@ static void replace_character(int c) /// Replace a whole area with one character. static int op_replace(oparg_T *oap, int c) { - int n, numc; - int num_chars; - char *newp, *oldp; - colnr_T oldlen; + int n; struct block_def bd; char *after_p = NULL; int had_ctrl_v_cr = false; @@ -1848,6 +1839,11 @@ static int op_replace(oparg_T *oap, int c) // block mode replace if (oap->motion_type == kMTBlockWise) { + int numc; + int num_chars; + char *newp; + char *oldp; + colnr_T oldlen; bd.is_MAX = (curwin->w_curswant == MAXCOL); for (; curwin->w_cursor.lnum <= oap->end.lnum; curwin->w_cursor.lnum++) { curwin->w_cursor.col = 0; // make sure cursor position is valid @@ -2218,12 +2214,11 @@ bool swapchar(int op_type, pos_T *pos) /// Insert and append operators for Visual mode. void op_insert(oparg_T *oap, long count1) { - long ins_len, pre_textlen = 0; - char *firstline, *ins_text; - colnr_T ind_pre_col = 0, ind_post_col; - int ind_pre_vcol = 0, ind_post_vcol = 0; + long pre_textlen = 0; + char *firstline; + colnr_T ind_pre_col = 0; + int ind_pre_vcol = 0; struct block_def bd; - int i; pos_T t1; // edit() changes this - record it for OP_APPEND @@ -2284,7 +2279,7 @@ void op_insert(oparg_T *oap, long count1) if (u_save_cursor() == FAIL) { return; } - for (i = 0; i < bd.endspaces; i++) { + for (int i = 0; i < bd.endspaces; i++) { ins_char(' '); } bd.textlen += bd.endspaces; @@ -2321,12 +2316,13 @@ void op_insert(oparg_T *oap, long count1) } if (oap->motion_type == kMTBlockWise) { + int ind_post_vcol = 0; struct block_def bd2; bool did_indent = false; // if indent kicked in, the firstline might have changed // but only do that, if the indent actually increased - ind_post_col = (colnr_T)getwhitecols_curline(); + colnr_T ind_post_col = (colnr_T)getwhitecols_curline(); if (curbuf->b_op_start.col > ind_pre_col && ind_post_col > ind_pre_col) { bd.textcol += ind_post_col - ind_pre_col; ind_post_vcol = get_indent(); @@ -2414,9 +2410,9 @@ void op_insert(oparg_T *oap, long count1) } else { firstline += add; } - ins_len = (long)strlen(firstline) - pre_textlen - offset; + long ins_len = (long)strlen(firstline) - pre_textlen - offset; if (pre_textlen >= 0 && ins_len > 0) { - ins_text = xstrnsave(firstline, (size_t)ins_len); + char *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); @@ -2434,20 +2430,13 @@ void op_insert(oparg_T *oap, long count1) /// @return true if edit() returns because of a CTRL-O command int op_change(oparg_T *oap) { - colnr_T l; int retval; - long offset; - linenr_T linenr; - long ins_len; long pre_textlen = 0; long pre_indent = 0; - char *newp; char *firstline; - char *ins_text; - char *oldp; struct block_def bd; - l = oap->start.col; + colnr_T l = oap->start.col; if (oap->motion_type == kMTLineWise) { l = 0; can_si = may_do_si(); // Like opening a new line, do smart indent @@ -2499,6 +2488,7 @@ int op_change(oparg_T *oap) // 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) { + long ins_len; // 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); @@ -2511,11 +2501,14 @@ int op_change(oparg_T *oap) ins_len = (long)strlen(firstline) - pre_textlen; if (ins_len > 0) { + long offset; + char *newp; + char *oldp; // Subsequent calls to ml_get() flush the firstline data - take a // copy of the inserted text. - ins_text = xmalloc((size_t)(ins_len + 1)); + char *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; + for (linenr_T linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; linenr++) { block_prep(oap, &bd, linenr, true); if (!bd.is_short || virtual_op) { @@ -2619,7 +2612,6 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) yankreg_T newreg; // new yank register when appending char **new_ptr; linenr_T lnum; // current line number - size_t j; MotionType yank_type = oap->motion_type; size_t yanklines = (size_t)oap->line_count; linenr_T yankendlnum = oap->end.lnum; @@ -2743,6 +2735,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) } if (curr != reg) { // append the new block to the old block + size_t j; new_ptr = xmalloc(sizeof(char *) * (curr->y_size + reg->y_size)); for (j = 0; j < curr->y_size; j++) { new_ptr[j] = curr->y_array[j]; @@ -3773,7 +3766,6 @@ void ex_display(exarg_T *eap) { char *p; yankreg_T *yb; - int name; char *arg = eap->arg; int clen; int type; @@ -3786,7 +3778,7 @@ void ex_display(exarg_T *eap) // Highlight title msg_puts_title(_("\nType Name Content")); for (int i = -1; i < NUM_REGISTERS && !got_int; i++) { - name = get_register_name(i); + int name = get_register_name(i); switch (get_reg_type(name, NULL)) { case kMTLineWise: type = 'l'; break; @@ -3912,13 +3904,11 @@ void ex_display(exarg_T *eap) static void dis_msg(const char *p, bool skip_esc) FUNC_ATTR_NONNULL_ALL { - int n; - int l; - - n = Columns - 6; + int n = Columns - 6; while (*p != NUL && !(*p == ESC && skip_esc && *(p + 1) == NUL) && (n -= ptr2cells(p)) >= 0) { + int l; if ((l = utfc_ptr2len(p)) > 1) { msg_outtrans_len(p, l); p += l; @@ -4389,7 +4379,6 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) changed_lines(pos.lnum, 0, pos.lnum + 1, 0L, true); } } else { - int one_change; int length; pos_T startpos; @@ -4429,7 +4418,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) length = oap->end.col - pos.col + 1; } } - one_change = do_addsub(oap->op_type, &pos, length, amount); + int one_change = do_addsub(oap->op_type, &pos, length, amount); if (one_change) { // Remember the start position of the first change. if (change_cnt == 0) { @@ -5323,7 +5312,6 @@ void cursor_pos_info(dict_T *dict) char *p; char buf1[50]; char buf2[40]; - linenr_T lnum; varnumber_T byte_count = 0; varnumber_T bom_count = 0; varnumber_T byte_count_cursor = 0; @@ -5331,9 +5319,6 @@ void cursor_pos_info(dict_T *dict) varnumber_T char_count_cursor = 0; varnumber_T word_count = 0; varnumber_T word_count_cursor = 0; - int eol_size; - varnumber_T last_check = 100000L; - long line_count_selected = 0; pos_T min_pos, max_pos; oparg_T oparg; struct block_def bd; @@ -5347,6 +5332,10 @@ void cursor_pos_info(dict_T *dict) return; } } else { + linenr_T lnum; + int eol_size; + varnumber_T last_check = 100000L; + long line_count_selected = 0; if (get_fileformat(curbuf) == EOL_DOS) { eol_size = 2; } else { @@ -5777,22 +5766,20 @@ typedef struct { void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) { oparg_T *oap = cap->oap; - pos_T old_cursor; - bool empty_region_error; - int restart_edit_save; int lbr_saved = curwin->w_p_lbr; // The visual area is remembered for redo static redo_VIsual_T redo_VIsual = { NUL, 0, 0, 0, 0 }; - bool include_line_break = false; - - old_cursor = curwin->w_cursor; + pos_T old_cursor = curwin->w_cursor; // If an operation is pending, handle it... if ((finish_op || VIsual_active) && oap->op_type != OP_NOP) { + bool empty_region_error; + int restart_edit_save; + bool include_line_break = false; // Yank can be redone when 'y' is in 'cpoptions', but not when yanking // for the clipboard. const bool redo_yank = vim_strchr(p_cpo, CPO_YANK) != NULL && !gui_yank; @@ -5914,8 +5901,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) } else if (VIsual_mode == 'v') { // If 'selection' is "exclusive", backup one character for // charwise selections. - include_line_break = - unadjust_for_sel(); + include_line_break = unadjust_for_sel(); } oap->start = VIsual; -- cgit From 7224c889e0d5d70b99ae377036baa6377c33a568 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:25:24 +0100 Subject: build: enable MSVC level 3 warnings (#21934) MSVC has 4 different warning levels: 1 (severe), 2 (significant), 3 (production quality) and 4 (informational). Enabling level 3 warnings mostly revealed conversion problems, similar to GCC/clang -Wconversion flag. --- 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 6326130c5a..f5f1a456f6 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4127,7 +4127,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions linenr_T lnum = curwin->w_cursor.lnum + t; colnr_T mincol = (colnr_T)0; linenr_T lnum_amount = -t; - long col_amount = (cend - newp - spaces_removed); + colnr_T col_amount = (colnr_T)(cend - newp - spaces_removed); mark_col_adjust(lnum, mincol, lnum_amount, col_amount, spaces_removed); -- cgit From 4be6c6cf0ddf5e31d4103cb5df06651ba6f4897b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:05:57 +0100 Subject: refactor: replace char_u with char (#21901) 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 f5f1a456f6..0fb8a8004b 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -926,7 +926,7 @@ int do_record(int c) char *p = (char *)get_recorded(); if (p != NULL) { // Remove escaping for K_SPECIAL in multi-byte chars. - vim_unescape_ks((char_u *)p); + vim_unescape_ks(p); (void)tv_dict_add_str(dict, S_LEN("regcontents"), (const char *)p); } @@ -3848,7 +3848,7 @@ void ex_display(exarg_T *eap) } // display last inserted text - if ((p = (char *)get_last_insert()) != NULL + if ((p = get_last_insert()) != NULL && (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int && !message_filtered(p)) { msg_puts("\n c \". "); @@ -5490,7 +5490,7 @@ void cursor_pos_info(dict_T *dict) validate_virtcol(); col_print(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(buf2, sizeof(buf2), (int)strlen(p), linetabsize(p)); if (char_count_cursor == byte_count_cursor && char_count == byte_count) { -- cgit From 47638706a37534ae9bc7ac4c57ddb9fb2b44fef0 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 12 Feb 2023 17:41:54 +0100 Subject: build: treat clang-tidy warnings as errors (#22238) --- 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 0fb8a8004b..e89844098b 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -923,7 +923,7 @@ int do_record(int c) dict_T *dict = get_v_event(&save_v_event); // The recorded text contents. - char *p = (char *)get_recorded(); + char *p = get_recorded(); if (p != NULL) { // Remove escaping for K_SPECIAL in multi-byte chars. vim_unescape_ks(p); -- cgit From 446c353a507834a3cbe9007b06e7e0c2c46b5ac7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 4 Mar 2023 08:39:54 +0800 Subject: vim-patch:9.0.1376: accessing invalid memory with put in Visual block mode (#22505) Problem: Accessing invalid memory with put in Visual block mode. Solution: Adjust the cursor column if needed. https://github.com/vim/vim/commit/1c73b65229c25e3c1fd8824ba958f7cc4d604f9c Co-authored-by: Bram Moolenaar --- src/nvim/ops.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index e89844098b..d2a96be5ad 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3346,7 +3346,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) ptr += yanklen; // insert block's trailing spaces only if there's text behind - if ((j < count - 1 || !shortline) && spaces) { + if ((j < count - 1 || !shortline) && spaces > 0) { memset(ptr, ' ', (size_t)spaces); ptr += spaces; } else { @@ -3685,6 +3685,15 @@ error: msgmore(nr_lines); curwin->w_set_curswant = true; + // Make sure the cursor is not after the NUL. + int len = (int)strlen(get_cursor_line_ptr()); + if (curwin->w_cursor.col > len) { + if (cur_ve_flags == VE_ALL) { + curwin->w_cursor.coladd = curwin->w_cursor.col - len; + } + curwin->w_cursor.col = len; + } + end: if (cmdmod.cmod_flags & CMOD_LOCKMARKS) { curbuf->b_op_start = orig_start; -- cgit From 6cab36e5b7b0d741abe6c5a7c0e20bad30361034 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 4 Mar 2023 13:10:00 +0100 Subject: refactor: replace char_u with char or uint8_t (#22400) Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d2a96be5ad..884eeef433 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1186,7 +1186,7 @@ int do_execreg(int regname, int colon, int addcr, int silent) /// used only after other typeahead has been processed. static void put_reedit_in_typebuf(int silent) { - char_u buf[3]; + uint8_t buf[3]; if (restart_edit == NUL) { return; @@ -1197,7 +1197,7 @@ static void put_reedit_in_typebuf(int silent) buf[1] = 'R'; buf[2] = NUL; } else { - buf[0] = (char_u)(restart_edit == 'I' ? 'i' : restart_edit); + buf[0] = (uint8_t)(restart_edit == 'I' ? 'i' : restart_edit); buf[1] = NUL; } if (ins_typebuf((char *)buf, REMAP_NONE, 0, true, silent) == OK) { -- cgit From 089f962d6a18bd91d89998e16834b822ab2adf9f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 5 Mar 2023 08:08:04 +0800 Subject: vim-patch:9.0.1378: illegal memory access when using virtual editing (#22527) Problem: Illegal memory access when using virtual editing. Solution: Make sure "startspaces" is not negative. https://github.com/vim/vim/commit/c99cbf8f289bdda5d4a77d7ec415850a520330ba Co-authored-by: Bram Moolenaar --- src/nvim/ops.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 884eeef433..6929189750 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2684,8 +2684,10 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) 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. - bd.startspaces = (ce - cs + 1) - - oap->start.coladd; + bd.startspaces = (ce - cs + 1) - oap->start.coladd; + if (bd.startspaces < 0) { + bd.startspaces = 0; + } startcol++; } } -- cgit From 419819b6245e120aba8897e3ddea711b2cd0246c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 5 Mar 2023 09:18:42 +0800 Subject: vim-patch:9.0.1380: CTRL-X on 2**64 subtracts two (#22530) Problem: CTRL-X on 2**64 subtracts two. (James McCoy) Solution: Correct computation for large number. (closes vim/vim#12103) https://github.com/vim/vim/commit/5fb78c3fa5c996c08a65431d698bd2c251eef5c7 Co-authored-by: Bram Moolenaar --- src/nvim/ops.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 6929189750..1a33ae8bbf 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4658,11 +4658,12 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) : length); } + bool overflow = false; vim_str2nr(ptr + col, &pre, &length, 0 + (do_bin ? STR2NR_BIN : 0) + (do_oct ? STR2NR_OCT : 0) + (do_hex ? STR2NR_HEX : 0), - NULL, &n, maxlen, false); + NULL, &n, maxlen, false, &overflow); // ignore leading '-' for hex, octal and bin numbers if (pre && negative) { @@ -4682,8 +4683,10 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) oldn = n; - n = subtract ? n - (uvarnumber_T)Prenum1 - : n + (uvarnumber_T)Prenum1; + if (!overflow) { // if number is too big don't add/subtract + n = subtract ? n - (uvarnumber_T)Prenum1 + : n + (uvarnumber_T)Prenum1; + } // handle wraparound for decimal numbers if (!pre) { -- cgit From d6ecead36406233cc56353dd05f3380f0497630f Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 14 Mar 2023 11:49:46 +0100 Subject: refactor(screen): screen.c delenda est drawscreen.c vs screen.c makes absolutely no sense. The screen exists only to draw upon it, therefore helper functions are distributed randomly between screen.c and the file that does the redrawing. In addition screen.c does a lot of drawing on the screen. It made more sense for vim/vim as our grid.c is their screen.c Not sure if we want to dump all the code for option chars into optionstr.c, so keep these in a optionchar.c for now. --- 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 1a33ae8bbf..2edd1772ca 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -52,7 +52,6 @@ #include "nvim/os/input.h" #include "nvim/os/time.h" #include "nvim/plines.h" -#include "nvim/screen.h" #include "nvim/search.h" #include "nvim/state.h" #include "nvim/strings.h" -- cgit From d510bfbc8e447b1a60d5ec7faaa8f440eb4ef56f Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 2 Apr 2023 10:11:42 +0200 Subject: refactor: remove char_u (#22829) Closes 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 2edd1772ca..d66ed9abff 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5162,7 +5162,7 @@ void write_reg_contents_ex(int name, const char *str, ssize_t len, bool must_app /// @param str string or list of strings to put in register /// @param len length of the string (Ignored when str_list=true.) /// @param blocklen width of visual block, or -1 for "I don't know." -/// @param str_list True if str is `char_u **`. +/// @param str_list True if str is `char **`. static void str_to_reg(yankreg_T *y_ptr, MotionType yank_type, const char *str, size_t len, colnr_T blocklen, bool str_list) FUNC_ATTR_NONNULL_ALL -- cgit From 371823d407d7d7519735131bcad4670c62a731a7 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Wed, 5 Apr 2023 21:13:53 +0200 Subject: refactor: make error message definitions const message.c functions now take const char * as a format. Error message definitions can be made const. --- 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 d66ed9abff..d2e9fda7d9 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5628,7 +5628,7 @@ static void op_colon(oparg_T *oap) static Callback opfunc_cb; /// Process the 'operatorfunc' option value. -void set_operatorfunc_option(char **errmsg) +void set_operatorfunc_option(const char **errmsg) { if (option_set_callback_func(p_opfunc, &opfunc_cb) == FAIL) { *errmsg = e_invarg; -- cgit From 824639c7c17c4870cde83dd28fed7ed6be0ed4c9 Mon Sep 17 00:00:00 2001 From: Brandon Simmons <34775764+simmsbra@users.noreply.github.com> Date: Thu, 6 Apr 2023 11:08:46 -0500 Subject: fix(folds): handle visual blockwise indent insertion correctly (#22898) Previously, the fold information was incorrect because it wasn't being updated during the blockwise insertion. (Solution by zeertzjq) --- src/nvim/ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d2e9fda7d9..c6564e427e 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -623,9 +623,9 @@ static void block_insert(oparg_T *oap, char *s, int b_insert, struct block_def * } } // for all lnum - changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L, true); - State = oldstate; + + changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L, true); } /// Handle reindenting a block of lines. -- cgit From 9408f2dcf7cade2631688300e9b58eed6bc5219a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:40:57 +0200 Subject: refactor: remove redundant const char * casts --- src/nvim/ops.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index c6564e427e..9aacfcad30 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -926,7 +926,7 @@ int do_record(int c) if (p != NULL) { // Remove escaping for K_SPECIAL in multi-byte chars. vim_unescape_ks(p); - (void)tv_dict_add_str(dict, S_LEN("regcontents"), (const char *)p); + (void)tv_dict_add_str(dict, S_LEN("regcontents"), p); } // Name of requested register, or empty string for unnamed operation. @@ -1273,7 +1273,7 @@ int insert_reg(int regname, bool literally_arg) if (arg == NULL) { return FAIL; } - stuffescaped((const char *)arg, literally); + stuffescaped(arg, literally); if (allocated) { xfree(arg); } @@ -1288,7 +1288,7 @@ int insert_reg(int regname, bool literally_arg) AppendCharToRedobuff(regname); do_put(regname, NULL, BACKWARD, 1L, PUT_CURSEND); } else { - stuffescaped((const char *)reg->y_array[i], literally); + stuffescaped(reg->y_array[i], literally); } // Insert a newline between lines and after last line if // y_type is kMTLineWise. @@ -2867,7 +2867,7 @@ static void do_autocmd_textyankpost(oparg_T *oap, yankreg_T *reg) // The yanked text contents. list_T *const list = tv_list_alloc((ptrdiff_t)reg->y_size); for (size_t i = 0; i < reg->y_size; i++) { - tv_list_append_string(list, (const char *)reg->y_array[i], -1); + tv_list_append_string(list, reg->y_array[i], -1); } tv_list_set_lock(list, VAR_FIXED); (void)tv_dict_add_list(dict, S_LEN("regcontents"), list); @@ -4963,7 +4963,7 @@ void *get_reg_contents(int regname, int flags) if (flags & kGRegList) { list_T *const list = tv_list_alloc((ptrdiff_t)reg->y_size); for (size_t i = 0; i < reg->y_size; i++) { - tv_list_append_string(list, (const char *)reg->y_array[i], -1); + tv_list_append_string(list, reg->y_array[i], -1); } return list; @@ -5608,13 +5608,13 @@ static void op_colon(oparg_T *oap) stuffReadbuff("!"); } if (oap->op_type == OP_INDENT) { - stuffReadbuff((const char *)get_equalprg()); + stuffReadbuff(get_equalprg()); stuffReadbuff("\n"); } else if (oap->op_type == OP_FORMAT) { if (*curbuf->b_p_fp != NUL) { - stuffReadbuff((const char *)curbuf->b_p_fp); + stuffReadbuff(curbuf->b_p_fp); } else if (*p_fp != NUL) { - stuffReadbuff((const char *)p_fp); + stuffReadbuff(p_fp); } else { stuffReadbuff("fmt"); } @@ -6639,7 +6639,7 @@ static bool get_clipboard(int name, yankreg_T **target, bool quiet) if (TV_LIST_ITEM_TV(li)->v_type != VAR_STRING) { goto err; } - reg->y_array[tv_idx++] = xstrdupnul((const char *)TV_LIST_ITEM_TV(li)->vval.v_string); + reg->y_array[tv_idx++] = xstrdupnul(TV_LIST_ITEM_TV(li)->vval.v_string); }); if (reg->y_size > 0 && strlen(reg->y_array[reg->y_size - 1]) == 0) { @@ -6700,7 +6700,7 @@ static void set_clipboard(int name, yankreg_T *reg) list_T *const lines = tv_list_alloc((ptrdiff_t)reg->y_size + (reg->y_type != kMTCharWise)); for (size_t i = 0; i < reg->y_size; i++) { - tv_list_append_string(lines, (const char *)reg->y_array[i], -1); + tv_list_append_string(lines, reg->y_array[i], -1); } char regtype; @@ -6910,7 +6910,7 @@ bcount_t get_region_bytecount(buf_T *buf, linenr_T start_lnum, linenr_T end_lnum if (start_lnum == end_lnum) { return end_col - start_col; } - const char *first = (const char *)ml_get_buf(buf, start_lnum, false); + const char *first = ml_get_buf(buf, start_lnum, false); bcount_t deleted_bytes = (bcount_t)strlen(first) - start_col + 1; for (linenr_T i = 1; i <= end_lnum - start_lnum - 1; i++) { -- cgit From 8e2903d2fe810cfa3be41fc1e7a4d8394c84cf11 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Apr 2023 09:11:37 +0800 Subject: vim-patch:8.2.1049: Vim9: leaking memory when using continuation line Problem: Vim9: leaking memory when using continuation line. Solution: Keep a pointer to the continuation line in evalarg_T. Centralize checking for a next command. https://github.com/vim/vim/commit/b171fb179053fa631fec74911b5fb9374cb6a8a1 Omit eval_next_line(): Vim9 script only. vim-patch:8.2.1050: missing change in struct Problem: Missing change in struct. Solution: Add missing change. https://github.com/vim/vim/commit/65a8ed37f7bc61fbe5c612a7b0eb0dfc16ad3e11 Co-authored-by: Bram Moolenaar --- 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 9aacfcad30..b2c0dd6c01 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -763,7 +763,7 @@ char *get_expr_line(void) } nested++; - rv = eval_to_string(expr_copy, NULL, true); + rv = eval_to_string(expr_copy, true); nested--; xfree(expr_copy); return rv; -- cgit From a1b045f60a22d366e255dfff1c54ed42ebe49284 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 18:28:49 +0200 Subject: refactor(clang-tidy): remove redundant casts --- src/nvim/ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index b2c0dd6c01..b50ef72058 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4037,7 +4037,7 @@ 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_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); + curr_start = ml_get(curwin->w_cursor.lnum + t); curr = curr_start; if (t == 0 && setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { // Set the '[ mark. @@ -5555,7 +5555,7 @@ void cursor_pos_info(dict_T *dict) // Don't shorten this message, the user asked for it. tv_dict_add_nr(dict, S_LEN("words"), word_count); tv_dict_add_nr(dict, S_LEN("chars"), char_count); - tv_dict_add_nr(dict, S_LEN("bytes"), (varnumber_T)(byte_count + bom_count)); + tv_dict_add_nr(dict, S_LEN("bytes"), byte_count + bom_count); STATIC_ASSERT(sizeof("visual") == sizeof("cursor"), "key_len argument in tv_dict_add_nr is wrong"); -- cgit From 3b0df1780e2c8526bda5dead18ee7cc45925caba Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 26 Apr 2023 23:23:44 +0200 Subject: refactor: uncrustify Notable changes: replace all infinite loops to `while(true)` and remove `int` from `unsigned int`. --- src/nvim/ops.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index b50ef72058..2919b94d41 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2090,7 +2090,7 @@ void op_tilde(oparg_T *oap) did_change = swapchars(oap->op_type, &pos, oap->end.col - pos.col + 1); } else { - for (;;) { + while (true) { did_change |= swapchars(oap->op_type, &pos, pos.lnum == oap->end.lnum ? oap->end.col + 1 : (int)strlen(ml_get_pos(&pos))); @@ -2944,7 +2944,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) long cnt; const pos_T orig_start = curbuf->b_op_start; const pos_T orig_end = curbuf->b_op_end; - unsigned int cur_ve_flags = get_ve_flags(); + unsigned cur_ve_flags = get_ve_flags(); if (flags & PUT_FIXINDENT) { orig_indent = get_indent(); @@ -3056,7 +3056,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // For the = register we need to split the string at NL // characters. // Loop twice: count the number of lines and save them. - for (;;) { + while (true) { y_size = 0; ptr = insert_string; while (ptr != NULL) { @@ -3717,7 +3717,7 @@ end: /// there move it left. void adjust_cursor_eol(void) { - unsigned int cur_ve_flags = get_ve_flags(); + unsigned cur_ve_flags = get_ve_flags(); const bool adj_cursor = (curwin->w_cursor.col > 0 && gchar_cursor() == NUL @@ -6470,7 +6470,7 @@ static yankreg_T *adjust_clipboard_name(int *name, bool quiet, bool writing) } if (cb_flags & CB_UNNAMEDPLUS) { - *name = (cb_flags & CB_UNNAMED && writing) ? '"': '+'; + *name = (cb_flags & CB_UNNAMED && writing) ? '"' : '+'; target = &y_regs[PLUS_REGISTER]; } else { *name = '*'; -- cgit From ff34c91194f9ab9d02808f2880029c38a4655eb5 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 17 Apr 2023 17:23:47 +0100 Subject: vim-patch:9.0.1330: handling new value of an option has a long "else if" chain Problem: Handling new value of an option has a long "else if" chain. Solution: Use a function pointer. (Yegappan Lakshmanan, closes vim/vim#12015) https://github.com/vim/vim/commit/af93691b53f38784efce0b93fe7644c44a7e382e --- src/nvim/ops.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 2919b94d41..89fe9b464d 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5628,11 +5628,12 @@ static void op_colon(oparg_T *oap) static Callback opfunc_cb; /// Process the 'operatorfunc' option value. -void set_operatorfunc_option(const char **errmsg) +const char *did_set_operatorfunc(optset_T *args FUNC_ATTR_UNUSED) { if (option_set_callback_func(p_opfunc, &opfunc_cb) == FAIL) { - *errmsg = e_invarg; + return e_invarg; } + return NULL; } #if defined(EXITFREE) -- cgit From c426f7a6228cb82af0f75ac4f2421543408ff091 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 27 Apr 2023 00:03:46 +0200 Subject: vim-patch:9.0.0751: 'scrolloff' does not work well with 'smoothscroll' Problem: 'scrolloff' does not work well with 'smoothscroll'. Solution: Make positioning the cursor a bit better. Rename functions. https://github.com/vim/vim/commit/c9121f798f49fa71e814912cb186d89c164090c3 Co-authored-by: Bram Moolenaar --- 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 89fe9b464d..d8380303a3 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5503,7 +5503,7 @@ void cursor_pos_info(dict_T *dict) validate_virtcol(); col_print(buf1, sizeof(buf1), (int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1); - col_print(buf2, sizeof(buf2), (int)strlen(p), linetabsize(p)); + col_print(buf2, sizeof(buf2), (int)strlen(p), linetabsize_str(p)); if (char_count_cursor == byte_count_cursor && char_count == byte_count) { -- cgit From 88cfb49bee3c9102082c7010acb92244e4ad1348 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 07:14:39 +0800 Subject: vim-patch:8.2.4890: inconsistent capitalization in error messages Problem: Inconsistent capitalization in error messages. Solution: Make capitalization consistent. (Doug Kearns) https://github.com/vim/vim/commit/cf030578b26460643dca4a40e7f2e3bc19c749aa Co-authored-by: Bram Moolenaar --- src/nvim/ops.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d8380303a3..bb66bb5731 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -96,6 +96,9 @@ struct block_def { # include "ops.c.generated.h" #endif +static const char e_search_pattern_and_expression_register_may_not_contain_two_or_more_lines[] + = N_("E883: Search pattern and expression register may not contain two or more lines"); + // Flags for third item in "opchars". #define OPF_LINES 1 // operator always works on lines #define OPF_CHANGE 2 // operator changes text @@ -5043,8 +5046,7 @@ void write_reg_contents_lst(int name, char **strings, bool must_append, MotionTy if (strings[0] == NULL) { s = ""; } else if (strings[1] != NULL) { - emsg(_("E883: search pattern and expression register may not " - "contain two or more lines")); + emsg(_(e_search_pattern_and_expression_register_may_not_contain_two_or_more_lines)); return; } write_reg_contents_ex(name, s, -1, must_append, yank_type, block_len); -- cgit From 32331378134599ece34298f866889b4b311d7b79 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 7 May 2023 08:34:37 +0800 Subject: vim-patch:9.0.1516: cannot use special keys in mapping Problem: Cannot use special keys in mapping. Solution: Do allow for special keys in and mappings. (closes vim/vim#12326) https://github.com/vim/vim/commit/3ab3a864814f903da8a158c01820e4fbe1013c08 --- 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 bb66bb5731..ef26d5900d 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5858,7 +5858,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) if (repeat_cmdline == NULL) { ResetRedobuff(); } else { - AppendToRedobuffLit(repeat_cmdline, -1); + AppendToRedobuffSpec(repeat_cmdline); AppendToRedobuff(NL_STR); XFREE_CLEAR(repeat_cmdline); } -- cgit From 5844af0d524956b55100e4350934237e4a12a147 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 8 May 2023 00:41:18 +0800 Subject: vim-patch:9.0.1521: failing redo of command with control characters Problem: Failing redo of command with control characters. Solution: Use AppendToRedobuffLit() for colon commands. (closes vim/vim#12354) https://github.com/vim/vim/commit/30b6d6104c3d541c41c868989c020b743e01af08 --- 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 ef26d5900d..c1511ab8da 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5858,7 +5858,11 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) if (repeat_cmdline == NULL) { ResetRedobuff(); } else { - AppendToRedobuffSpec(repeat_cmdline); + if (cap->cmdchar == ':') { + AppendToRedobuffLit(repeat_cmdline, -1); + } else { + AppendToRedobuffSpec(repeat_cmdline); + } AppendToRedobuff(NL_STR); XFREE_CLEAR(repeat_cmdline); } -- cgit From 5ac2e47acc999472042df4f10f8f7b5ffa72ba3e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 10 May 2023 17:42:14 +0800 Subject: fix(redo): make redo of Lua mappings in op-pending mode work (#23566) --- src/nvim/ops.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index c1511ab8da..de77cdd238 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5777,6 +5777,11 @@ typedef struct { int rv_arg; ///< extra argument } redo_VIsual_T; +static bool is_ex_cmdchar(cmdarg_T *cap) +{ + return cap->cmdchar == ':' || cap->cmdchar == K_COMMAND; +} + /// Handle an operator after Visual mode or when the movement is finished. /// "gui_yank" is true when yanking text for the clipboard. void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) @@ -5831,7 +5836,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) if ((redo_yank || oap->op_type != OP_YANK) && ((!VIsual_active || oap->motion_force) // Also redo Operator-pending Visual mode mappings. - || ((cap->cmdchar == ':' || cap->cmdchar == K_COMMAND) + || ((is_ex_cmdchar(cap) || cap->cmdchar == K_LUA) && oap->op_type != OP_COLON)) && cap->cmdchar != 'D' && oap->op_type != OP_FOLD @@ -5851,7 +5856,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) AppendToRedobuffLit(cap->searchbuf, -1); } AppendToRedobuff(NL_STR); - } else if (cap->cmdchar == ':' || cap->cmdchar == K_COMMAND) { + } else if (is_ex_cmdchar(cap)) { // do_cmdline() has stored the first typed line in // "repeat_cmdline". When several lines are typed repeating // won't be possible. @@ -5866,6 +5871,9 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) AppendToRedobuff(NL_STR); XFREE_CLEAR(repeat_cmdline); } + } else if (cap->cmdchar == K_LUA) { + AppendNumberToRedobuff(repeat_luaref); + AppendToRedobuff(NL_STR); } } @@ -6021,7 +6029,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) prep_redo(oap->regname, cap->count0, get_op_char(oap->op_type), get_extra_op_char(oap->op_type), oap->motion_force, cap->cmdchar, cap->nchar); - } else if (cap->cmdchar != ':' && cap->cmdchar != K_COMMAND) { + } else if (!is_ex_cmdchar(cap) && cap->cmdchar != K_LUA) { int opchar = get_op_char(oap->op_type); int extra_opchar = get_extra_op_char(oap->op_type); int nchar = oap->op_type == OP_REPLACE ? cap->nchar : NUL; -- cgit From 55f6a1cab031ecc28c5a7f2558a0cac9df2145e1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 30 May 2023 07:18:12 +0800 Subject: vim-patch:9.0.1588: Incsearch not triggered when pasting clipboard register (#23817) Problem: Incsearch not triggered when pasting clipboard register on the command line. Solution: Also set "literally" when using a clipboard register. (Ken Takata, closes vim/vim#12460) https://github.com/vim/vim/commit/9cf6ab133227ac7e9169941752293bb7178d8e38 Co-authored-by: K.Takata --- src/nvim/ops.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index de77cdd238..c39a3273da 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -854,15 +854,6 @@ static bool is_append_register(int regname) return ASCII_ISUPPER(regname); } -/// @see get_yank_register -/// @returns true when register should be inserted literally -/// (selection or clipboard) -static inline bool is_literal_register(int regname) - FUNC_ATTR_CONST -{ - return regname == '*' || regname == '+'; -} - /// @return a copy of contents in register `name` for use in do_put. Should be /// freed by caller. yankreg_T *copy_register(int name) -- cgit From 9f3c4c152664b21593636a59ce21e74ab7000b20 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 2 Jun 2023 08:48:49 +0800 Subject: vim-patch:9.0.1597: cursor ends up below the window after a put (#23873) Problem: Cursor ends up below the window after a put. Solution: Mark w_crow and w_botline invalid when changing the cursor line. (closes vim/vim#12465) https://github.com/vim/vim/commit/8509014adda188ee8bdf6a2e123fbf15a91b29d2 Co-authored-by: Bram Moolenaar --- src/nvim/ops.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index c39a3273da..2711c3d29c 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3484,6 +3484,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (lnum == curwin->w_cursor.lnum) { // make sure curwin->w_virtcol is updated changed_cline_bef_curs(); + invalidate_botline(); curwin->w_cursor.col += (colnr_T)(totlen - 1); } changed_bytes(lnum, col); -- cgit From 780ab11b90119fb9b91d3266d6eef459228edc9a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 6 Jun 2023 11:15:27 +0800 Subject: vim-patch:partial:8.2.4950: text properties position wrong after shifting text (#23930) Problem: Text properties position wrong after shifting text. Solution: Adjust the text properties when shifting a block of text. (closes vim/vim#10418) https://github.com/vim/vim/commit/4b93674159d60c985de906c30f45dbaf2b64056f Co-authored-by: LemonBoy --- src/nvim/ops.c | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 2711c3d29c..4a6ed8c521 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -340,7 +340,6 @@ static void shift_block(oparg_T *oap, int amount) const int ts_val = (int)curbuf->b_p_ts; struct block_def bd; int incr; - int i = 0, j = 0; const int old_p_ri = p_ri; p_ri = 0; // don't want revins in indent @@ -391,40 +390,36 @@ static void shift_block(oparg_T *oap, int amount) bd.start_vcol = cts.cts_vcol; clear_chartabsize_arg(&cts); + int tabs = 0, spaces = 0; // OK, now total=all the VWS reqd, and textstart points at the 1st // non-ws char in the block. if (!curbuf->b_p_et) { - tabstop_fromto(ws_vcol, ws_vcol + total, ts_val, curbuf->b_p_vts_array, &i, &j); + tabstop_fromto(ws_vcol, ws_vcol + total, + ts_val, curbuf->b_p_vts_array, &tabs, &spaces); } else { - j = total; + spaces = total; } // if we're splitting a TAB, allow for it - int col_pre = bd.pre_whitesp_c - (bd.startspaces != 0); + const int col_pre = bd.pre_whitesp_c - (bd.startspaces != 0); bd.textcol -= col_pre; - const int len = (int)strlen(bd.textstart) + 1; - int col = bd.textcol + i + j + len; - assert(col >= 0); - newp = xmalloc((size_t)col); - memset(newp, NUL, (size_t)col); + + const size_t new_line_len // the length of the line after the block shift + = (size_t)bd.textcol + (size_t)tabs + (size_t)spaces + strlen(bd.textstart); + newp = xmalloc(new_line_len + 1); memmove(newp, oldp, (size_t)bd.textcol); startcol = bd.textcol; oldlen = (int)(bd.textstart - old_textstart) + col_pre; - newlen = i + j; - memset(newp + bd.textcol, TAB, (size_t)i); - memset(newp + bd.textcol + i, ' ', (size_t)j); - // the end - memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); + newlen = tabs + spaces; + memset(newp + bd.textcol, TAB, (size_t)tabs); + memset(newp + bd.textcol + tabs, ' ', (size_t)spaces); + // Note that STRMOVE() copies the trailing NUL. + STRMOVE(newp + bd.textcol + tabs + spaces, bd.textstart); } else { // left - colnr_T destination_col; // column to which text in block will - // be shifted 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 = bd.textstart; // Firstly, let's find the first non-whitespace character that is @@ -460,7 +455,7 @@ static void shift_block(oparg_T *oap, int amount) ? block_space_width : total; // The column to which we will shift the text. - destination_col = non_white_col - shift_amount; + const colnr_T destination_col = non_white_col - shift_amount; // Now let's find out how much of the beginning of the line we can // reuse without modification. @@ -491,7 +486,8 @@ static void shift_block(oparg_T *oap, int amount) // part of the line that will be copied, it means we encountered a tab // character, which we will have to partly replace with spaces. assert(destination_col - verbatim_copy_width >= 0); - fill = (size_t)(destination_col - verbatim_copy_width); + const size_t fill // nr of spaces that replace a TAB + = (size_t)(destination_col - verbatim_copy_width); assert(verbatim_copy_end - oldp >= 0); const size_t verbatim_diff = (size_t)(verbatim_copy_end - oldp); @@ -499,14 +495,16 @@ 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; + const size_t new_line_len // the length of the line after the block shift + = verbatim_diff + fill + strlen(non_white); - newp = xmalloc(new_line_len); + newp = xmalloc(new_line_len + 1); startcol = (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); + // Note that STRMOVE() copies the trailing NUL. STRMOVE(newp + verbatim_diff + fill, non_white); } // replace the line -- cgit From fcf3519c65a2d6736de437f686e788684a6c8564 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 17 Apr 2023 22:18:58 +0200 Subject: refactor: remove long long is 32-bits even on 64-bit windows which makes the type suboptimal for a codebase meant to be cross-platform. --- src/nvim/ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 4a6ed8c521..0aefd28fec 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5763,7 +5763,7 @@ typedef struct { int rv_mode; ///< 'v', 'V', or Ctrl-V linenr_T rv_line_count; ///< number of lines colnr_T rv_vcol; ///< number of cols or end column - long rv_count; ///< count for Visual operator + int rv_count; ///< count for Visual operator int rv_arg; ///< extra argument } redo_VIsual_T; @@ -6157,7 +6157,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) switch (oap->op_type) { case OP_LSHIFT: case OP_RSHIFT: - op_shift(oap, true, oap->is_VIsual ? (int)cap->count1 : 1); + op_shift(oap, true, oap->is_VIsual ? cap->count1 : 1); auto_format(false, true); break; -- cgit From cefd774fac76b91f5368833555818c80c992c3b1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 24 Aug 2023 15:14:23 +0200 Subject: refactor(memline): distinguish mutating uses of ml_get_buf() ml_get_buf() takes a third parameters to indicate whether the caller wants to mutate the memline data in place. However the vast majority of the call sites is using this function just to specify a buffer but without any mutation. This makes it harder to grep for the places which actually perform mutation. Solution: Remove the bool param from ml_get_buf(). it now works like ml_get() except for a non-current buffer. Add a new ml_get_buf_mut() function for the mutating use-case, which can be grepped along with the other ml_replace() etc functions which can modify the memline. --- src/nvim/ops.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 0aefd28fec..0564e3dde2 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1373,7 +1373,7 @@ bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg) return false; } - *argp = ml_get_buf(curwin->w_buffer, curwin->w_cursor.lnum, false); + *argp = ml_get_buf(curwin->w_buffer, curwin->w_cursor.lnum); return true; case '_': // black hole: always empty @@ -1783,7 +1783,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)c; + *(ml_get_buf_mut(curbuf, lp.lnum) + lp.col) = (char)c; if (!curbuf_splice_pending) { extmark_splice_cols(curbuf, (int)lp.lnum - 1, lp.col, 1, 1, kExtmarkUndo); } @@ -6915,14 +6915,14 @@ bcount_t get_region_bytecount(buf_T *buf, linenr_T start_lnum, linenr_T end_lnum if (start_lnum == end_lnum) { return end_col - start_col; } - const char *first = ml_get_buf(buf, start_lnum, false); + const char *first = ml_get_buf(buf, start_lnum); 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)) + 1; } if (end_lnum > max_lnum) { return deleted_bytes; -- cgit From 008154954791001efcc46c28146e21403f3a698b Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 21 Aug 2023 14:52:17 +0200 Subject: refactor(change): do API changes to buffer without curbuf switch Most of the messy things when changing a non-current buffer is not about the buffer, it is about windows. In particular, it is about `curwin`. When editing a non-current buffer which is displayed in some other window in the current tabpage, one such window will be "borrowed" as the curwin. But this means if two or more non-current windows displayed the buffers, one of them will be treated differenty. this is not desirable. In particular, with nvim_buf_set_text, cursor _column_ position was only corrected for one single window. Two new tests are added: the test with just one non-current window passes, but the one with two didn't. Two corresponding such tests were also added for nvim_buf_set_lines. This already worked correctly on master, but make sure this is well-tested for future refactors. Also, nvim_create_buf no longer invokes autocmds just because you happened to use `scratch=true`. No option value was changed, therefore OptionSet must not be fired. --- src/nvim/ops.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 0564e3dde2..8270641256 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -281,7 +281,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount) } } - changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L, true); + changed_lines(curbuf, oap->start.lnum, 0, oap->end.lnum + 1, 0L, true); } /// Shift the current line one shiftwidth left (if left != 0) or right @@ -626,7 +626,7 @@ static void block_insert(oparg_T *oap, char *s, int b_insert, struct block_def * State = oldstate; - changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L, true); + changed_lines(curbuf, oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L, true); } /// Handle reindenting a block of lines. @@ -690,7 +690,7 @@ void op_reindent(oparg_T *oap, Indenter how) // 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, + changed_lines(curbuf, first_changed, 0, oap->is_VIsual ? start_lnum + (linenr_T)oap->line_count : last_changed + 1, 0L, true); } else if (oap->is_VIsual) { @@ -1593,7 +1593,7 @@ int op_delete(oparg_T *oap) } check_cursor_col(); - changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, + changed_lines(curbuf, curwin->w_cursor.lnum, curwin->w_cursor.col, oap->end.lnum + 1, 0L, true); oap->line_count = 0; // no lines deleted } else if (oap->motion_type == kMTLineWise) { @@ -1628,12 +1628,12 @@ int op_delete(oparg_T *oap) // leave cursor past last char in line if (oap->line_count > 1) { - u_clearline(); // "U" command not possible after "2cc" + u_clearline(curbuf); // "U" command not possible after "2cc" } } else { del_lines(oap->line_count, true); beginline(BL_WHITE | BL_FIX); - u_clearline(); // "U" command not possible after "dd" + u_clearline(curbuf); // "U" command not possible after "dd" } } else { if (virtual_op) { @@ -2030,7 +2030,7 @@ static int op_replace(oparg_T *oap, int c) curwin->w_cursor = oap->start; check_cursor(); - changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L, true); + changed_lines(curbuf, oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L, true); if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { // Set "'[" and "']" marks. @@ -2064,7 +2064,7 @@ void op_tilde(oparg_T *oap) did_change |= one_change; } if (did_change) { - changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L, true); + changed_lines(curbuf, oap->start.lnum, 0, oap->end.lnum + 1, 0L, true); } } else { // not block mode if (oap->motion_type == kMTLineWise) { @@ -2092,7 +2092,7 @@ void op_tilde(oparg_T *oap) } } if (did_change) { - changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, + changed_lines(curbuf, oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L, true); } } @@ -2531,7 +2531,7 @@ int op_change(oparg_T *oap) } } check_cursor(); - changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L, true); + changed_lines(curbuf, oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L, true); xfree(ins_text); } } @@ -3365,7 +3365,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) } } - changed_lines(lnum, 0, curbuf->b_op_start.lnum + (linenr_T)y_size + changed_lines(curbuf, lnum, 0, curbuf->b_op_start.lnum + (linenr_T)y_size - nr_lines, nr_lines, true); // Set '[ mark. @@ -3481,8 +3481,8 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // Place cursor on last putted char. if (lnum == curwin->w_cursor.lnum) { // make sure curwin->w_virtcol is updated - changed_cline_bef_curs(); - invalidate_botline(); + changed_cline_bef_curs(curwin); + invalidate_botline(curwin); curwin->w_cursor.col += (colnr_T)(totlen - 1); } changed_bytes(lnum, col); @@ -3620,10 +3620,10 @@ error: // note changed text for displaying and folding if (y_type == kMTCharWise) { - changed_lines(curwin->w_cursor.lnum, col, + changed_lines(curbuf, curwin->w_cursor.lnum, col, curwin->w_cursor.lnum + 1, nr_lines, true); } else { - changed_lines(curbuf->b_op_start.lnum, 0, + changed_lines(curbuf, curbuf->b_op_start.lnum, 0, curbuf->b_op_start.lnum, nr_lines, true); } @@ -4159,7 +4159,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions // Only report the change in the first line here, del_lines() will report // the deleted line. - changed_lines(curwin->w_cursor.lnum, currsize, + changed_lines(curbuf, curwin->w_cursor.lnum, currsize, curwin->w_cursor.lnum + 1, 0L, true); // Delete following lines. To do this we move the cursor there @@ -4379,7 +4379,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) change_cnt = do_addsub(oap->op_type, &pos, 0, amount); disable_fold_update--; if (change_cnt) { - changed_lines(pos.lnum, 0, pos.lnum + 1, 0L, true); + changed_lines(curbuf, pos.lnum, 0, pos.lnum + 1, 0L, true); } } else { int length; @@ -4437,7 +4437,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) disable_fold_update--; if (change_cnt) { - changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L, true); + changed_lines(curbuf, oap->start.lnum, 0, oap->end.lnum + 1, 0L, true); } if (!change_cnt && oap->is_VIsual) { -- cgit From 15298e79269e95899b9812c78af19f954b3bcba6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 3 Sep 2023 09:14:45 +0800 Subject: vim-patch:9.0.1847: [security] potential oob write in do_addsub() Problem: potential oob write in do_addsub() Solution: don't overflow buf2, check size in for loop() https://github.com/vim/vim/commit/889f6af37164775192e33b233a90e86fd3df0f57 Co-authored-by: Christian Brabandt --- 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 8270641256..96deae228f 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4770,7 +4770,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) } } - while (bits > 0) { + while (bits > 0 && i < NUMBUFLEN - 1) { buf2[i++] = ((n >> --bits) & 0x1) ? '1' : '0'; } -- cgit From f91cd31d7d9d70006e0000592637d5d997eab52c Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 21:46:39 +0200 Subject: refactor(messages): fold msg_outtrans_attr into msg_outtrans problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- 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 96deae228f..bab1696cfe 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3838,7 +3838,7 @@ void ex_display(exarg_T *eap) for (p = yb->y_array[j]; *p != NUL && (n -= ptr2cells(p)) >= 0; p++) { // -V1019 clen = utfc_ptr2len(p); - msg_outtrans_len(p, clen); + msg_outtrans_len(p, clen, 0); p += clen - 1; } } @@ -3913,10 +3913,10 @@ static void dis_msg(const char *p, bool skip_esc) && (n -= ptr2cells(p)) >= 0) { int l; if ((l = utfc_ptr2len(p)) > 1) { - msg_outtrans_len(p, l); + msg_outtrans_len(p, l, 0); p += l; } else { - msg_outtrans_len(p++, 1); + msg_outtrans_len(p++, 1, 0); } } os_breakcheck(); -- cgit From b85f1dafc7c0a19704135617454f1c66f41202c1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 22:21:17 +0200 Subject: refactor(messages): fold msg_attr into msg problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- src/nvim/ops.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index bab1696cfe..d328299232 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -938,7 +938,7 @@ int do_record(int c) if (p_ch == 0 || ui_has(kUIMessages)) { showmode(); } else { - msg(""); + msg("", 0); } if (p == NULL) { retval = FAIL; @@ -5333,7 +5333,7 @@ void cursor_pos_info(dict_T *dict) // Compute the length of the file in characters. if (curbuf->b_ml.ml_flags & ML_EMPTY) { if (dict == NULL) { - msg(_(no_lines_msg)); + msg(_(no_lines_msg), 0); return; } } else { @@ -5538,7 +5538,7 @@ void cursor_pos_info(dict_T *dict) msg_start(); msg_scroll = true; } - msg(IObuff); + msg(IObuff, 0); p_shm = p; } } @@ -6452,7 +6452,7 @@ static yankreg_T *adjust_clipboard_name(int *name, bool quiet, bool writing) clipboard_didwarn = true; // Do NOT error (emsg()) here--if it interrupts :redir we get into // a weird state, stuck in "redirect mode". - msg(MSG_NO_CLIP); + msg(MSG_NO_CLIP, 0); } // ... else, be silent (don't flood during :while, :redir, etc.). goto end; -- cgit From af7d317f3ff31d5ac5d8724b5057a422e1451b54 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 26 Sep 2023 22:36:08 +0200 Subject: refactor: remove long long is 32-bits even on 64-bit windows which makes the type suboptimal for a codebase meant to be cross-platform. --- 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 d328299232..9e85997ca0 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -3182,7 +3182,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) if (cur_ve_flags == VE_ALL && y_type == kMTCharWise) { if (gchar_cursor() == TAB) { int viscol = getviscol(); - long ts = curbuf->b_p_ts; + OptInt ts = curbuf->b_p_ts; // Don't need to insert spaces when "p" on the last position of a // tab or "P" on the first position. if (dir == FORWARD -- cgit From bc13bc154aa574e0bb58a50f2e0ca4570efa57c3 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 29 Sep 2023 16:10:54 +0200 Subject: refactor(message): smsg_attr -> smsg --- src/nvim/ops.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 9e85997ca0..d42ce03f9a 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -656,7 +656,7 @@ void op_reindent(oparg_T *oap, Indenter how) if (i > 1 && (i % 50 == 0 || i == oap->line_count - 1) && oap->line_count > p_report) { - smsg(_("%" PRId64 " lines to indent... "), (int64_t)i); + smsg(0, _("%" PRId64 " lines to indent... "), (int64_t)i); } // Be vi-compatible: For lisp indenting the first line is not @@ -699,9 +699,7 @@ void op_reindent(oparg_T *oap, Indenter how) if (oap->line_count > p_report) { i = oap->line_count - (i + 1); - smsg(NGETTEXT("%" PRId64 " line indented ", - "%" PRId64 " lines indented ", i), - (int64_t)i); + smsg(0, NGETTEXT("%" PRId64 " line indented ", "%" PRId64 " lines indented ", i), (int64_t)i); } if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { // set '[ and '] marks @@ -2109,8 +2107,7 @@ void op_tilde(oparg_T *oap) } if (oap->line_count > p_report) { - smsg(NGETTEXT("%" PRId64 " line changed", - "%" PRId64 " lines changed", oap->line_count), + smsg(0, NGETTEXT("%" PRId64 " line changed", "%" PRId64 " lines changed", oap->line_count), (int64_t)oap->line_count); } } @@ -2783,12 +2780,12 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) update_screen(); } if (yank_type == kMTBlockWise) { - smsg(NGETTEXT("block of %" PRId64 " line yanked%s", - "block of %" PRId64 " lines yanked%s", yanklines), + smsg(0, NGETTEXT("block of %" PRId64 " line yanked%s", + "block of %" PRId64 " lines yanked%s", yanklines), (int64_t)yanklines, namebuf); } else { - smsg(NGETTEXT("%" PRId64 " line yanked%s", - "%" PRId64 " lines yanked%s", yanklines), + smsg(0, NGETTEXT("%" PRId64 " line yanked%s", + "%" PRId64 " lines yanked%s", yanklines), (int64_t)yanklines, namebuf); } } @@ -4452,8 +4449,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) } if (change_cnt > p_report) { - smsg(NGETTEXT("%" PRId64 " lines changed", - "%" PRId64 " lines changed", change_cnt), + smsg(0, NGETTEXT("%" PRId64 " lines changed", "%" PRId64 " lines changed", change_cnt), (int64_t)change_cnt); } } -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/ops.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index d42ce03f9a..5d3e285e3b 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -49,6 +49,8 @@ #include "nvim/normal.h" #include "nvim/ops.h" #include "nvim/option.h" +#include "nvim/option_defs.h" +#include "nvim/option_vars.h" #include "nvim/os/input.h" #include "nvim/os/time.h" #include "nvim/plines.h" -- cgit From e72b546354cd90bf0cd8ee6dd045538d713009ad Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/ops.c | 57 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 5d3e285e3b..348a86a0f6 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -217,7 +217,7 @@ int get_extra_op_char(int optype) /// handle a shift operation void op_shift(oparg_T *oap, int curs_top, int amount) { - long i; + int i; int block_col = 0; if (u_save((linenr_T)(oap->start.lnum - 1), @@ -292,7 +292,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount) /// @param call_changed_bytes call changed_bytes() void shift_line(int left, int round, int amount, int call_changed_bytes) { - const int sw_val = (int)get_sw_value_indent(curbuf); + const int sw_val = get_sw_value_indent(curbuf); int count = get_indent(); // get current indent @@ -338,7 +338,7 @@ static void shift_block(oparg_T *oap, int amount) const int oldstate = State; char *newp; const int oldcol = curwin->w_cursor.col; - const int sw_val = (int)get_sw_value_indent(curbuf); + const int sw_val = get_sw_value_indent(curbuf); const int ts_val = (int)curbuf->b_p_ts; struct block_def bd; int incr; @@ -634,7 +634,7 @@ static void block_insert(oparg_T *oap, char *s, int b_insert, struct block_def * /// Handle reindenting a block of lines. void op_reindent(oparg_T *oap, Indenter how) { - long i = 0; + int i = 0; linenr_T first_changed = 0; linenr_T last_changed = 0; linenr_T start_lnum = curwin->w_cursor.lnum; @@ -647,8 +647,8 @@ void op_reindent(oparg_T *oap, Indenter how) // Save for undo. Do this once for all lines, much faster than doing this // for each line separately, especially when undoing. - if (u_savecommon(curbuf, start_lnum - 1, start_lnum + (linenr_T)oap->line_count, - start_lnum + (linenr_T)oap->line_count, false) == OK) { + if (u_savecommon(curbuf, start_lnum - 1, start_lnum + oap->line_count, + start_lnum + oap->line_count, false) == OK) { char *l; int amount; for (i = oap->line_count - 1; i >= 0 && !got_int; i--) { @@ -693,7 +693,7 @@ void op_reindent(oparg_T *oap, Indenter how) // there is no change still need to remove the Visual highlighting. if (last_changed != 0) { changed_lines(curbuf, first_changed, 0, - oap->is_VIsual ? start_lnum + (linenr_T)oap->line_count : + oap->is_VIsual ? start_lnum + oap->line_count : last_changed + 1, 0L, true); } else if (oap->is_VIsual) { redraw_curbuf_later(UPD_INVERTED); @@ -1717,8 +1717,8 @@ int op_delete(oparg_T *oap) pos_T curpos; // save deleted and changed lines for undo - if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), - (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) { + if (u_save(curwin->w_cursor.lnum - 1, + curwin->w_cursor.lnum + oap->line_count) == FAIL) { return FAIL; } @@ -2204,7 +2204,7 @@ bool swapchar(int op_type, pos_T *pos) /// Insert and append operators for Visual mode. void op_insert(oparg_T *oap, long count1) { - long pre_textlen = 0; + int pre_textlen = 0; char *firstline; colnr_T ind_pre_col = 0; int ind_pre_vcol = 0; @@ -2251,7 +2251,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 = (int)strlen(firstline); } if (oap->op_type == OP_APPEND) { @@ -2400,7 +2400,7 @@ void op_insert(oparg_T *oap, long count1) } else { firstline += add; } - long ins_len = (long)strlen(firstline) - pre_textlen - offset; + int ins_len = (int)strlen(firstline) - pre_textlen - offset; if (pre_textlen >= 0 && ins_len > 0) { char *ins_text = xstrnsave(firstline, (size_t)ins_len); // block handled here @@ -2421,8 +2421,8 @@ void op_insert(oparg_T *oap, long count1) int op_change(oparg_T *oap) { int retval; - long pre_textlen = 0; - long pre_indent = 0; + int pre_textlen = 0; + int pre_indent = 0; char *firstline; struct block_def bd; @@ -2456,8 +2456,8 @@ int op_change(oparg_T *oap) coladvance_force(getviscol()); } firstline = ml_get(oap->start.lnum); - pre_textlen = (long)strlen(firstline); - pre_indent = (long)getwhitecols(firstline); + pre_textlen = (int)strlen(firstline); + pre_indent = (int)getwhitecols(firstline); bd.textcol = curwin->w_cursor.col; } @@ -2478,25 +2478,25 @@ int op_change(oparg_T *oap) // 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) { - long ins_len; + int ins_len; // 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); if (bd.textcol > (colnr_T)pre_indent) { - long new_indent = (long)getwhitecols(firstline); + int new_indent = (int)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 = (int)strlen(firstline) - pre_textlen; if (ins_len > 0) { long offset; char *newp; char *oldp; // Subsequent calls to ml_get() flush the firstline data - take a // copy of the inserted text. - char *ins_text = xmalloc((size_t)(ins_len + 1)); + char *ins_text = xmalloc((size_t)ins_len + 1); xstrlcpy(ins_text, firstline + bd.textcol, (size_t)ins_len + 1); for (linenr_T linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; linenr++) { @@ -2526,7 +2526,7 @@ int op_change(oparg_T *oap) STRMOVE(newp + offset, oldp); ml_replace(linenr, newp, false); extmark_splice_cols(curbuf, (int)linenr - 1, bd.textcol, - 0, vpos.coladd + (int)ins_len, kExtmarkUndo); + 0, vpos.coladd + ins_len, kExtmarkUndo); } } check_cursor(); @@ -2903,7 +2903,7 @@ static void do_autocmd_textyankpost(oparg_T *oap, yankreg_T *reg) /// PUT_LINE force linewise put (":put") /// PUT_BLOCK_INNER in block mode, do not add trailing spaces /// @param dir BACKWARD for 'P', FORWARD for 'p' -void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) +void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) { char *ptr; char *newp; @@ -3320,7 +3320,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); + totlen = (size_t)count * (size_t)(yanklen + spaces) + (size_t)bd.startspaces + + (size_t)bd.endspaces; newp = xmalloc(totlen + oldlen + 1); // copy part up to cursor to new line @@ -3446,7 +3447,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags) // multiplication overflow emsg(_(e_resulting_text_too_long)); } else { - totlen = (size_t)(count * yanklen); + totlen = (size_t)count * (size_t)yanklen; do { oldp = ml_get(lnum); oldlen = strlen(oldp); @@ -4166,7 +4167,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions // 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); + del_lines((int)count - 1, false); curwin->w_cursor.lnum = t; curbuf_splice_pending--; curbuf->deleted_bytes2 = 0; @@ -5569,7 +5570,7 @@ static void op_colon(oparg_T *oap) if (oap->start.lnum == curwin->w_cursor.lnum) { stuffcharReadbuff('.'); } else { - stuffnumReadbuff((long)oap->start.lnum); + stuffnumReadbuff(oap->start.lnum); } // When using !! on a closed fold the range ".!" works best to operate @@ -5590,7 +5591,7 @@ static void op_colon(oparg_T *oap) stuffReadbuff(".+"); stuffnumReadbuff(oap->line_count - 1); } else { - stuffnumReadbuff((long)oap->end.lnum); + stuffnumReadbuff(oap->end.lnum); } } } @@ -5996,7 +5997,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) resel_VIsual_vcol = oap->end_vcol; } } - resel_VIsual_line_count = (linenr_T)oap->line_count; + resel_VIsual_line_count = oap->line_count; } // can't redo yank (unless 'y' is in 'cpoptions') and ":" -- cgit From 8e932480f61d6101bf8bea1abc07ed93826221fd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- 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 348a86a0f6..f4eaf3a320 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2202,7 +2202,7 @@ bool swapchar(int op_type, pos_T *pos) } /// Insert and append operators for Visual mode. -void op_insert(oparg_T *oap, long count1) +void op_insert(oparg_T *oap, int count1) { int pre_textlen = 0; char *firstline; @@ -2491,7 +2491,7 @@ int op_change(oparg_T *oap) ins_len = (int)strlen(firstline) - pre_textlen; if (ins_len > 0) { - long offset; + int offset; char *newp; char *oldp; // Subsequent calls to ml_get() flush the firstline data - take a @@ -2932,7 +2932,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) pos_T old_pos; char *insert_string = NULL; bool allocated = false; - long cnt; + int cnt; const pos_T orig_start = curbuf->b_op_start; const pos_T orig_end = curbuf->b_op_end; unsigned cur_ve_flags = get_ve_flags(); @@ -3334,7 +3334,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) ptr += bd.startspaces; // insert the new text - for (long j = 0; j < count; j++) { + for (int j = 0; j < count; j++) { memmove(ptr, y_array[i], (size_t)yanklen); ptr += yanklen; @@ -5339,7 +5339,7 @@ void cursor_pos_info(dict_T *dict) linenr_T lnum; int eol_size; varnumber_T last_check = 100000L; - long line_count_selected = 0; + int line_count_selected = 0; if (get_fileformat(curbuf) == EOL_DOS) { eol_size = 2; } else { @@ -5398,7 +5398,7 @@ void cursor_pos_info(dict_T *dict) if (l_VIsual_active && lnum >= min_pos.lnum && lnum <= max_pos.lnum) { char *s = NULL; - long len = 0L; + int len = 0L; switch (l_VIsual_mode) { case Ctrl_V: @@ -5406,7 +5406,7 @@ void cursor_pos_info(dict_T *dict) block_prep(&oparg, &bd, lnum, false); virtual_op = kNone; s = bd.textstart; - len = (long)bd.textlen; + len = bd.textlen; break; case 'V': s = ml_get(lnum); @@ -5429,7 +5429,7 @@ void cursor_pos_info(dict_T *dict) if (lnum == curbuf->b_ml.ml_line_count && !curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol) - && (long)strlen(s) < len) { + && (int)strlen(s) < len) { byte_count_cursor -= eol_size; } } -- cgit From 468a3a14072a638865681dad88d3c3b31cf11e23 Mon Sep 17 00:00:00 2001 From: James <89495599+IAKOBVS@users.noreply.github.com> Date: Tue, 10 Oct 2023 21:03:55 +0700 Subject: refactor: use xstpcpy() instead of strcat() (#25572) --- src/nvim/ops.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index f4eaf3a320..cb8d1dabc0 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -983,10 +983,12 @@ 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 *lp = xmalloc(strlen(*pp) + strlen(p) + 1); - STRCPY(lp, *pp); - // TODO(philix): use xstpcpy() in stuff_yank() - STRCAT(lp, p); + const size_t ppl = strlen(*pp); + const size_t pl = strlen(p); + char *lp = xmalloc(ppl + pl + 1); + memcpy(lp, *pp, ppl); + memcpy(lp + ppl, p, pl); + *(lp + ppl + pl) = NUL; xfree(p); xfree(*pp); *pp = lp; -- cgit From af010e23f38a23bb74ea5b61e1b1a05e76410b5f Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Fri, 13 Oct 2023 20:16:15 +0600 Subject: refactor(options): rename `empty_option` to `empty_string_option` --- src/nvim/ops.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index cb8d1dabc0..260019da33 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -5365,8 +5365,8 @@ void cursor_pos_info(dict_T *dict) char *const saved_w_sbr = curwin->w_p_sbr; // Make 'sbr' empty for a moment to get the correct size. - p_sbr = empty_option; - curwin->w_p_sbr = empty_option; + p_sbr = empty_string_option; + curwin->w_p_sbr = empty_string_option; oparg.is_VIsual = true; oparg.motion_type = kMTBlockWise; oparg.op_type = OP_NOP; -- cgit From ac353e87aecf02315d82a3ad22725d2bc8140f0c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 28 Oct 2023 10:42:18 +0800 Subject: vim-patch:9.0.2075: TextChangedI may not always trigger (#25808) Problem: TextChangedI may not always trigger Solution: trigger it in more cases: for insert/ append/change operations, and when opening a new line, fixes: vim/vim#13367 closes: vim/vim#13375 https://github.com/vim/vim/commit/4bca4897a12dfb91b3b27e3083fd5f370bd857d1 Co-authored-by: Christian Brabandt --- src/nvim/ops.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 260019da33..f325eceaaf 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -6226,6 +6226,9 @@ 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); + // trigger TextChangedI + curbuf->b_last_changedtick_i = buf_get_changedtick(curbuf); + if (op_change(oap)) { // will call edit() cap->retval |= CA_COMMAND_BUSY; } @@ -6324,6 +6327,9 @@ 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); + // trigger TextChangedI + curbuf->b_last_changedtick_i = buf_get_changedtick(curbuf); + op_insert(oap, cap->count1); // Reset linebreak, so that formatting works correctly. -- cgit From acc646ad8fc3ef11fcc63b69f3d8484e4a91accd Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 29 Sep 2023 14:58:48 +0200 Subject: refactor: the long goodbye long is 32 bits on windows, while it is 64 bits on other architectures. This makes the type suboptimal for a codebase meant to be cross-platform. Replace it with more appropriate integer types. --- src/nvim/ops.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index f325eceaaf..9dbeed8658 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -283,7 +283,7 @@ void op_shift(oparg_T *oap, int curs_top, int amount) } } - changed_lines(curbuf, oap->start.lnum, 0, oap->end.lnum + 1, 0L, true); + changed_lines(curbuf, oap->start.lnum, 0, oap->end.lnum + 1, 0, true); } /// Shift the current line one shiftwidth left (if left != 0) or right @@ -628,7 +628,7 @@ static void block_insert(oparg_T *oap, char *s, int b_insert, struct block_def * State = oldstate; - changed_lines(curbuf, oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L, true); + changed_lines(curbuf, oap->start.lnum + 1, 0, oap->end.lnum + 1, 0, true); } /// Handle reindenting a block of lines. @@ -694,7 +694,7 @@ void op_reindent(oparg_T *oap, Indenter how) if (last_changed != 0) { changed_lines(curbuf, first_changed, 0, oap->is_VIsual ? start_lnum + oap->line_count : - last_changed + 1, 0L, true); + last_changed + 1, 0, true); } else if (oap->is_VIsual) { redraw_curbuf_later(UPD_INVERTED); } @@ -720,7 +720,7 @@ int get_expr_register(void) { char *new_line; - new_line = getcmdline('=', 0L, 0, true); + new_line = getcmdline('=', 0, 0, true); if (new_line == NULL) { return NUL; } @@ -1262,7 +1262,7 @@ int insert_reg(int regname, bool literally_arg) char *arg; if (regname == '.') { // Insert last inserted text. - retval = stuff_inserted(NUL, 1L, true); + retval = stuff_inserted(NUL, 1, true); } else if (get_spec_reg(regname, &arg, &allocated, true)) { if (arg == NULL) { return FAIL; @@ -1280,7 +1280,7 @@ int insert_reg(int regname, bool literally_arg) if (regname == '-') { AppendCharToRedobuff(Ctrl_R); AppendCharToRedobuff(regname); - do_put(regname, NULL, BACKWARD, 1L, PUT_CURSEND); + do_put(regname, NULL, BACKWARD, 1, PUT_CURSEND); } else { stuffescaped(reg->y_array[i], literally); } @@ -1354,7 +1354,7 @@ bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg) return false; } *argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP | (regname == Ctrl_P ? FNAME_EXP : 0), - 1L, NULL); + 1, NULL); *allocated = true; return true; @@ -1596,7 +1596,7 @@ int op_delete(oparg_T *oap) check_cursor_col(); changed_lines(curbuf, curwin->w_cursor.lnum, curwin->w_cursor.col, - oap->end.lnum + 1, 0L, true); + oap->end.lnum + 1, 0, true); oap->line_count = 0; // no lines deleted } else if (oap->motion_type == kMTLineWise) { if (oap->op_type == OP_CHANGE) { @@ -1936,7 +1936,7 @@ static int op_replace(oparg_T *oap, int c) linenr_T baselnum = curwin->w_cursor.lnum; if (after_p != NULL) { ml_append(curwin->w_cursor.lnum++, after_p, (int)after_p_len, false); - appended_lines_mark(curwin->w_cursor.lnum, 1L); + appended_lines_mark(curwin->w_cursor.lnum, 1); oap->end.lnum++; xfree(after_p); } @@ -2032,7 +2032,7 @@ static int op_replace(oparg_T *oap, int c) curwin->w_cursor = oap->start; check_cursor(); - changed_lines(curbuf, oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L, true); + changed_lines(curbuf, oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0, true); if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { // Set "'[" and "']" marks. @@ -2066,7 +2066,7 @@ void op_tilde(oparg_T *oap) did_change |= one_change; } if (did_change) { - changed_lines(curbuf, oap->start.lnum, 0, oap->end.lnum + 1, 0L, true); + changed_lines(curbuf, oap->start.lnum, 0, oap->end.lnum + 1, 0, true); } } else { // not block mode if (oap->motion_type == kMTLineWise) { @@ -2095,7 +2095,7 @@ void op_tilde(oparg_T *oap) } if (did_change) { changed_lines(curbuf, oap->start.lnum, oap->start.col, oap->end.lnum + 1, - 0L, true); + 0, true); } } @@ -2532,7 +2532,7 @@ int op_change(oparg_T *oap) } } check_cursor(); - changed_lines(curbuf, oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L, true); + changed_lines(curbuf, oap->start.lnum + 1, 0, oap->end.lnum + 1, 0, true); xfree(ins_text); } } @@ -3618,7 +3618,7 @@ error: ExtmarkOp kind = (y_type == kMTLineWise && !(flags & PUT_LINE_SPLIT)) ? kExtmarkUndo : kExtmarkNOOP; mark_adjust(curbuf->b_op_start.lnum + (y_type == kMTCharWise), - (linenr_T)MAXLNUM, nr_lines, 0L, kind); + (linenr_T)MAXLNUM, nr_lines, 0, kind); // note changed text for displaying and folding if (y_type == kMTCharWise) { @@ -4162,7 +4162,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions // Only report the change in the first line here, del_lines() will report // the deleted line. changed_lines(curbuf, curwin->w_cursor.lnum, currsize, - curwin->w_cursor.lnum + 1, 0L, true); + curwin->w_cursor.lnum + 1, 0, true); // Delete following lines. To do this we move the cursor there // briefly, and then move it back. After del_lines() the cursor may @@ -4381,7 +4381,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) change_cnt = do_addsub(oap->op_type, &pos, 0, amount); disable_fold_update--; if (change_cnt) { - changed_lines(curbuf, pos.lnum, 0, pos.lnum + 1, 0L, true); + changed_lines(curbuf, pos.lnum, 0, pos.lnum + 1, 0, true); } } else { int length; @@ -4439,7 +4439,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) disable_fold_update--; if (change_cnt) { - changed_lines(curbuf, oap->start.lnum, 0, oap->end.lnum + 1, 0L, true); + changed_lines(curbuf, oap->start.lnum, 0, oap->end.lnum + 1, 0, true); } if (!change_cnt && oap->is_VIsual) { @@ -5026,7 +5026,7 @@ static void finish_write_reg(int name, yankreg_T *reg, yankreg_T *old_y_previous /// @see write_reg_contents_ex 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); + write_reg_contents_ex(name, str, len, must_append, kMTUnknown, 0); } void write_reg_contents_lst(int name, char **strings, bool must_append, MotionType yank_type, @@ -5340,7 +5340,7 @@ void cursor_pos_info(dict_T *dict) } else { linenr_T lnum; int eol_size; - varnumber_T last_check = 100000L; + varnumber_T last_check = 100000; int line_count_selected = 0; if (get_fileformat(curbuf) == EOL_DOS) { eol_size = 2; @@ -5393,14 +5393,14 @@ void cursor_pos_info(dict_T *dict) if (got_int) { return; } - last_check = byte_count + 100000L; + last_check = byte_count + 100000; } // Do extra processing for VIsual mode. if (l_VIsual_active && lnum >= min_pos.lnum && lnum <= max_pos.lnum) { char *s = NULL; - int len = 0L; + int len = 0; switch (l_VIsual_mode) { case Ctrl_V: @@ -6034,9 +6034,9 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) if (opchar == 'g' && extra_opchar == '@') { // also repeat the count for 'operatorfunc' - prep_redo_num2(oap->regname, 0L, NUL, 'v', cap->count0, opchar, extra_opchar, nchar); + prep_redo_num2(oap->regname, 0, NUL, 'v', cap->count0, opchar, extra_opchar, nchar); } else { - prep_redo(oap->regname, 0L, NUL, 'v', opchar, extra_opchar, nchar); + prep_redo(oap->regname, 0, NUL, 'v', opchar, extra_opchar, nchar); } } if (!redo_VIsual_busy) { -- cgit From cd63a9addd6e1114c3524fa041ece560550cfe7b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 10 Nov 2023 08:39:21 +0800 Subject: refactor: change some xstrndup() and xstrnsave() to xmemdupz() (#25959) When the given length is exactly the number of bytes to copy, xmemdupz() makes the intention clearer. --- 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 9dbeed8658..b56d5e11ea 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1366,7 +1366,7 @@ bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg) cnt = find_ident_under_cursor(argp, (regname == Ctrl_W ? (FIND_IDENT|FIND_STRING) : FIND_STRING)); - *argp = cnt ? xstrnsave(*argp, cnt) : NULL; + *argp = cnt ? xmemdupz(*argp, cnt) : NULL; *allocated = true; return true; @@ -2404,7 +2404,7 @@ void op_insert(oparg_T *oap, int count1) } int ins_len = (int)strlen(firstline) - pre_textlen - offset; if (pre_textlen >= 0 && ins_len > 0) { - char *ins_text = xstrnsave(firstline, (size_t)ins_len); + char *ins_text = xmemdupz(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); @@ -3118,7 +3118,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) if (dir == FORWARD && *p != NUL) { MB_PTR_ADV(p); } - ptr = xstrnsave(oldp, (size_t)(p - oldp)); + ptr = xmemdupz(oldp, (size_t)(p - oldp)); ml_replace(curwin->w_cursor.lnum, ptr, false); nr_lines++; dir = FORWARD; -- cgit From 8e58d37f2e15ac8540377148e55ed08a039aadb6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 11 Nov 2023 11:20:08 +0100 Subject: refactor: remove redundant casts --- src/nvim/ops.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index b56d5e11ea..8acbf10efd 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2471,7 +2471,7 @@ int op_change(oparg_T *oap) const bool save_finish_op = finish_op; finish_op = false; - retval = edit(NUL, false, (linenr_T)1); + retval = edit(NUL, false, 1); finish_op = save_finish_op; @@ -3110,7 +3110,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) MB_PTR_ADV(p); } ptr = xstrdup(p); - ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, false); + ml_append(curwin->w_cursor.lnum, ptr, 0, false); xfree(ptr); oldp = get_cursor_line_ptr(); @@ -3254,8 +3254,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) // add a new line if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { - if (ml_append(curbuf->b_ml.ml_line_count, "", - (colnr_T)1, false) == FAIL) { + if (ml_append(curbuf->b_ml.ml_line_count, "", 1, false) == FAIL) { break; } nr_lines++; @@ -3529,7 +3528,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) STRCPY(newp, y_array[y_size - 1]); STRCAT(newp, ptr); // insert second line - ml_append(lnum, newp, (colnr_T)0, false); + ml_append(lnum, newp, 0, false); new_lnum++; xfree(newp); @@ -3547,7 +3546,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) for (; i < y_size; i++) { if ((y_type != kMTCharWise || i < y_size - 1)) { - if (ml_append(lnum, y_array[i], (colnr_T)0, false) == FAIL) { + if (ml_append(lnum, y_array[i], 0, false) == FAIL) { goto error; } new_lnum++; @@ -4130,7 +4129,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions // what is added if it is inside these spaces. const int spaces_removed = (int)((curr - curr_start) - spaces[t]); linenr_T lnum = curwin->w_cursor.lnum + t; - colnr_T mincol = (colnr_T)0; + colnr_T mincol = 0; linenr_T lnum_amount = -t; colnr_T col_amount = (colnr_T)(cend - newp - spaces_removed); @@ -4703,7 +4702,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) if (do_unsigned && negative) { if (subtract) { // sticking at zero. - n = (uvarnumber_T)0; + n = 0; } else { // sticking at 2^64 - 1. n = (uvarnumber_T)(-1); -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/ops.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 8acbf10efd..bcaad27040 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1,6 +1,3 @@ -// 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 @@ -3837,7 +3834,7 @@ void ex_display(exarg_T *eap) n -= 2; } for (p = yb->y_array[j]; - *p != NUL && (n -= ptr2cells(p)) >= 0; p++) { // -V1019 + *p != NUL && (n -= ptr2cells(p)) >= 0; p++) { clen = utfc_ptr2len(p); msg_outtrans_len(p, clen, 0); p += clen - 1; @@ -6733,7 +6730,7 @@ static void set_clipboard(int name, yankreg_T *reg) list_T *args = tv_list_alloc(3); tv_list_append_list(args, lines); - tv_list_append_string(args, ®type, 1); // -V614 + tv_list_append_string(args, ®type, 1); tv_list_append_string(args, ((char[]) { (char)name }), 1); (void)eval_call_provider("clipboard", "set", args, true); -- cgit From e9bfbe99cd7154912ef00fb1144411ee5d173b28 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 13 Nov 2023 18:18:04 +0800 Subject: fix(textformat): remove unnecessary changed_bytes() (#26027) This was removed from Vim in patch 8.1.0681. --- src/nvim/ops.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index bcaad27040..db59c2c98e 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1569,7 +1569,7 @@ int op_delete(oparg_T *oap) curwin->w_cursor.coladd = 0; } - // n == number of chars deleted + // "n" == number of chars deleted // 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; @@ -4025,8 +4025,9 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions comments = xcalloc(count, sizeof(*comments)); } - // Don't move anything, just compute the final line length + // Don't move anything yet, just compute the final line length // and setup the array of space strings lengths + // This loops forward over joined lines. for (t = 0; t < (linenr_T)count; t++) { curr_start = ml_get(curwin->w_cursor.lnum + t); curr = curr_start; @@ -4107,6 +4108,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions *cend = 0; // Move affected lines to the new long one. + // This loops backwards over the joined lines, including the original line. // // 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 -- cgit From 28f4f3c48498086307ed825d1761edb5789ca0e8 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 15:54:54 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment - use bool to represent boolean values --- src/nvim/ops.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index db59c2c98e..9c2b4e7b74 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -2541,9 +2541,7 @@ int op_change(oparg_T *oap) #if defined(EXITFREE) void clear_registers(void) { - int i; - - for (i = 0; i < NUM_REGISTERS; i++) { + for (int i = 0; i < NUM_REGISTERS; i++) { free_register(&y_regs[i]); } } -- cgit From ac1113ded5f8f09dd99a9894d7a7e795626fb728 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 13 Nov 2023 23:40:37 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment --- src/nvim/ops.c | 225 ++++++++++++++++++++++----------------------------------- 1 file changed, 85 insertions(+), 140 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 9c2b4e7b74..34aa2c80db 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -527,11 +527,10 @@ static void block_insert(oparg_T *oap, char *s, int b_insert, struct block_def * colnr_T offset; // pointer along new line 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 - for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) { + for (linenr_T lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) { block_prep(oap, bdp, lnum, true); if (bdp->is_short && b_insert) { continue; // OP_INSERT, line ends before block start @@ -646,7 +645,6 @@ void op_reindent(oparg_T *oap, Indenter how) // for each line separately, especially when undoing. if (u_savecommon(curbuf, start_lnum - 1, start_lnum + oap->line_count, start_lnum + oap->line_count, false) == OK) { - char *l; int amount; for (i = oap->line_count - 1; i >= 0 && !got_int; i--) { // it's a slow thing to do, so give feedback so there's no worry @@ -662,7 +660,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 = skipwhite(get_cursor_line_ptr()); + char *l = skipwhite(get_cursor_line_ptr()); if (*l == NUL) { // empty or blank line amount = 0; } else { @@ -715,9 +713,7 @@ static char *expr_line = NULL; /// @return '=' when OK, NUL otherwise. int get_expr_register(void) { - char *new_line; - - new_line = getcmdline('=', 0, 0, true); + char *new_line = getcmdline('=', 0, 0, true); if (new_line == NULL) { return NUL; } @@ -742,8 +738,6 @@ void set_expr_line(char *new_line) /// @return a pointer to allocated memory, or NULL for failure. char *get_expr_line(void) { - char *expr_copy; - char *rv; static int nested = 0; if (expr_line == NULL) { @@ -752,7 +746,7 @@ char *get_expr_line(void) // Make a copy of the expression, because evaluating it may cause it to be // changed. - expr_copy = xstrdup(expr_line); + char *expr_copy = xstrdup(expr_line); // When we are invoked recursively limit the evaluation to 10 levels. // Then return the string as-is. @@ -761,7 +755,7 @@ char *get_expr_line(void) } nested++; - rv = eval_to_string(expr_copy, true); + char *rv = eval_to_string(expr_copy, true); nested--; xfree(expr_copy); return rv; @@ -888,7 +882,6 @@ bool yank_register_mline(int regname) int do_record(int c) { static int regname; - yankreg_T *old_y_previous; int retval; if (reg_recording == 0) { @@ -942,7 +935,7 @@ int do_record(int c) } else { // We don't want to change the default register here, so save and // restore the current register name. - old_y_previous = y_previous; + yankreg_T *old_y_previous = y_previous; retval = stuff_yank(regname, p); @@ -1023,13 +1016,11 @@ static char *execreg_line_continuation(char **lines, size_t *idx) garray_T ga; ga_init(&ga, (int)sizeof(char), 400); - 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 = skipwhite(lines[i]); + char *p = skipwhite(lines[i]); if (*p != '\\' && (p[0] != '"' || p[1] != '\\' || p[2] != ' ')) { break; } @@ -1039,7 +1030,7 @@ static char *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 = skipwhite(lines[j]); + char *p = skipwhite(lines[j]); if (*p == '\\') { // Adjust the growsize to the current length to // speed up concatenating many lines. @@ -1066,7 +1057,6 @@ static char *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 *p; int retval = OK; if (regname == '@') { // repeat previous one @@ -1095,12 +1085,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 = 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); + char *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) { @@ -1110,14 +1100,14 @@ int do_execreg(int regname, int colon, int addcr, int silent) } xfree(p); } else if (regname == '=') { - p = get_expr_line(); + char *p = get_expr_line(); if (p == NULL) { return FAIL; } retval = put_in_typebuf(p, true, colon, silent); xfree(p); } else if (regname == '.') { // use last inserted text - p = get_last_insert_save(); + char *p = get_last_insert_save(); if (p == NULL) { emsg(_(e_noinstext)); return FAIL; @@ -1147,7 +1137,7 @@ int do_execreg(int regname, int colon, int addcr, int silent) char *str = reg->y_array[i]; bool free_str = false; if (colon && i > 0) { - p = skipwhite(str); + char *p = skipwhite(str); if (*p == '\\' || (p[0] == '"' && p[1] == '\\' && p[2] == ' ')) { str = execreg_line_continuation(reg->y_array, &i); free_str = true; @@ -1302,8 +1292,6 @@ int insert_reg(int regname, bool literally_arg) /// @return true if "regname" is a special register, bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg) { - size_t cnt; - *argp = NULL; *allocated = false; switch (regname) { @@ -1360,9 +1348,9 @@ bool get_spec_reg(int regname, char **argp, bool *allocated, bool errmsg) if (!errmsg) { return false; } - cnt = find_ident_under_cursor(argp, (regname == Ctrl_W - ? (FIND_IDENT|FIND_STRING) - : FIND_STRING)); + size_t cnt = find_ident_under_cursor(argp, (regname == Ctrl_W + ? (FIND_IDENT|FIND_STRING) + : FIND_STRING)); *argp = cnt ? xmemdupz(*argp, cnt) : NULL; *allocated = true; return true; @@ -1439,10 +1427,7 @@ static void shift_delete_registers(bool y_append) /// @return FAIL if undo failed, OK otherwise. int op_delete(oparg_T *oap) { - int n; linenr_T lnum; - char *ptr; - char *newp, *oldp; struct block_def bd = { 0 }; linenr_T old_lcount = curbuf->b_ml.ml_line_count; @@ -1475,7 +1460,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; + char *ptr = ml_get(oap->end.lnum) + oap->end.col; if (*ptr != NUL) { ptr += oap->inclusive; } @@ -1572,9 +1557,9 @@ int op_delete(oparg_T *oap) // "n" == number of chars deleted // 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); - newp = xmalloc(strlen(oldp) - (size_t)n + 1); + int n = bd.textlen - bd.startspaces - bd.endspaces; + char *oldp = ml_get(lnum); + char *newp = xmalloc(strlen(oldp) - (size_t)n + 1); // copy up to deleted part memmove(newp, oldp, (size_t)bd.textcol); // insert spaces @@ -1685,7 +1670,7 @@ int op_delete(oparg_T *oap) display_dollar(oap->end.col - !oap->inclusive); } - n = oap->end.col - oap->start.col + 1 - !oap->inclusive; + int n = oap->end.col - oap->start.col + 1 - !oap->inclusive; if (virtual_op) { // fix up things for virtualedit-delete: @@ -1734,7 +1719,7 @@ int op_delete(oparg_T *oap) del_lines(oap->line_count - 2, false); // delete from start of line until op_end - n = (oap->end.col + 1 - !oap->inclusive); + int n = (oap->end.col + 1 - !oap->inclusive); curwin->w_cursor.col = 0; (void)del_bytes((colnr_T)n, !virtual_op, oap->op_type == OP_DELETE && !oap->is_VIsual); @@ -2043,7 +2028,6 @@ static int op_replace(oparg_T *oap, int c) /// Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?". void op_tilde(oparg_T *oap) { - pos_T pos; struct block_def bd; int did_change = false; @@ -2052,7 +2036,7 @@ void op_tilde(oparg_T *oap) return; } - pos = oap->start; + pos_T pos = oap->start; if (oap->motion_type == kMTBlockWise) { // Visual block mode for (; pos.lnum <= oap->end.lnum; pos.lnum++) { int one_change; @@ -2204,11 +2188,9 @@ bool swapchar(int op_type, pos_T *pos) void op_insert(oparg_T *oap, int count1) { int pre_textlen = 0; - char *firstline; colnr_T ind_pre_col = 0; int ind_pre_vcol = 0; struct block_def bd; - pos_T t1; // edit() changes this - record it for OP_APPEND bd.is_MAX = (curwin->w_curswant == MAXCOL); @@ -2245,7 +2227,7 @@ void op_insert(oparg_T *oap, int count1) // Get indent information ind_pre_col = (colnr_T)getwhitecols_curline(); ind_pre_vcol = get_indent(); - firstline = ml_get(oap->start.lnum) + bd.textcol; + char *firstline = ml_get(oap->start.lnum) + bd.textcol; if (oap->op_type == OP_APPEND) { firstline += bd.textlen; @@ -2285,7 +2267,7 @@ void op_insert(oparg_T *oap, int count1) } } - t1 = oap->start; + pos_T t1 = oap->start; const pos_T start_insert = curwin->w_cursor; (void)edit(NUL, false, (linenr_T)count1); @@ -2376,7 +2358,7 @@ void op_insert(oparg_T *oap, int count1) // Subsequent calls to ml_get() flush the firstline data - take a // copy of the required string. - firstline = ml_get(oap->start.lnum); + char *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 @@ -2419,7 +2401,6 @@ void op_insert(oparg_T *oap, int count1) /// @return true if edit() returns because of a CTRL-O command int op_change(oparg_T *oap) { - int retval; int pre_textlen = 0; int pre_indent = 0; char *firstline; @@ -2468,7 +2449,7 @@ int op_change(oparg_T *oap) const bool save_finish_op = finish_op; finish_op = false; - retval = edit(NUL, false, 1); + int retval = edit(NUL, false, 1); finish_op = save_finish_op; @@ -2597,13 +2578,9 @@ bool op_yank(oparg_T *oap, bool message) static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) { yankreg_T newreg; // new yank register when appending - char **new_ptr; - linenr_T lnum; // current line number MotionType yank_type = oap->motion_type; size_t yanklines = (size_t)oap->line_count; linenr_T yankendlnum = oap->end.lnum; - char *p; - char *pnew; struct block_def bd; yankreg_T *curr = reg; // copy of current register @@ -2635,7 +2612,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) reg->timestamp = os_time(); size_t y_idx = 0; // index in y_array[] - lnum = oap->start.lnum; + linenr_T lnum = oap->start.lnum; // current line number if (yank_type == kMTBlockWise) { // Visual block mode @@ -2661,7 +2638,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 = ml_get(lnum); + char *p = ml_get(lnum); bd.startspaces = 0; bd.endspaces = 0; @@ -2725,7 +2702,7 @@ static void op_yank_reg(oparg_T *oap, bool message, yankreg_T *reg, bool append) if (curr != reg) { // append the new block to the old block size_t j; - new_ptr = xmalloc(sizeof(char *) * (curr->y_size + reg->y_size)); + char **new_ptr = xmalloc(sizeof(char *) * (curr->y_size + reg->y_size)); for (j = 0; j < curr->y_size; j++) { new_ptr[j] = curr->y_array[j]; } @@ -2741,8 +2718,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); + char *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]); @@ -2902,34 +2879,23 @@ 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, int count, int flags) { - char *ptr; - char *newp; - char *oldp; - int yanklen; size_t totlen = 0; // init for gcc linenr_T lnum = 0; - colnr_T col = 0; - size_t i; // index in y_array[] MotionType y_type; size_t y_size; - size_t oldlen; int y_width = 0; colnr_T vcol = 0; - int delcount; int incr = 0; struct block_def bd; char **y_array = NULL; linenr_T nr_lines = 0; - pos_T new_cursor; int indent; int orig_indent = 0; // init for gcc int indent_diff = 0; // init for gcc bool first_indent = true; int lendiff = 0; - pos_T old_pos; char *insert_string = NULL; bool allocated = false; - int cnt; const pos_T orig_start = curbuf->b_op_start; const pos_T orig_end = curbuf->b_op_end; unsigned cur_ve_flags = get_ve_flags(); @@ -3046,7 +3012,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) // Loop twice: count the number of lines and save them. while (true) { y_size = 0; - ptr = insert_string; + char *ptr = insert_string; while (ptr != NULL) { if (y_array != NULL) { y_array[y_size] = ptr; @@ -3104,11 +3070,11 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) if (dir == FORWARD && *p != NUL) { MB_PTR_ADV(p); } - ptr = xstrdup(p); + char *ptr = xstrdup(p); ml_append(curwin->w_cursor.lnum, ptr, 0, false); xfree(ptr); - oldp = get_cursor_line_ptr(); + char *oldp = get_cursor_line_ptr(); p = oldp + curwin->w_cursor.col; if (dir == FORWARD && *p != NUL) { MB_PTR_ADV(p); @@ -3173,7 +3139,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) goto end; } - yanklen = (int)strlen(y_array[0]); + int yanklen = (int)strlen(y_array[0]); if (cur_ve_flags == VE_ALL && y_type == kMTCharWise) { if (gchar_cursor() == TAB) { @@ -3194,7 +3160,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) } lnum = curwin->w_cursor.lnum; - col = curwin->w_cursor.col; + colnr_T col = curwin->w_cursor.col; // Block mode if (y_type == kMTBlockWise) { @@ -3235,7 +3201,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) } curwin->w_cursor.coladd = 0; bd.textcol = 0; - for (i = 0; i < y_size; i++) { + for (size_t i = 0; i < y_size; i++) { int spaces = 0; char shortline; // can just be 0 or 1, needed for blockwise paste beyond the current @@ -3245,7 +3211,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) bd.startspaces = 0; bd.endspaces = 0; vcol = 0; - delcount = 0; + int delcount = 0; // add a new line if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { @@ -3256,8 +3222,8 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) lines_appended = 1; } // get the old line and advance to the position to insert at - oldp = get_cursor_line_ptr(); - oldlen = strlen(oldp); + char *oldp = get_cursor_line_ptr(); + size_t oldlen = strlen(oldp); chartabsize_T cts; init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, 0, oldp, oldp); @@ -3267,7 +3233,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) cts.cts_vcol += incr; } vcol = cts.cts_vcol; - ptr = cts.cts_ptr; + char *ptr = cts.cts_ptr; bd.textcol = (colnr_T)(ptr - oldp); clear_chartabsize_arg(&cts); @@ -3318,7 +3284,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) totlen = (size_t)count * (size_t)(yanklen + spaces) + (size_t)bd.startspaces + (size_t)bd.endspaces; - newp = xmalloc(totlen + oldlen + 1); + char *newp = xmalloc(totlen + oldlen + 1); // copy part up to cursor to new line ptr = newp; @@ -3409,7 +3375,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) // Line mode: BACKWARD is the same as FORWARD on the previous line lnum--; } - new_cursor = curwin->w_cursor; + pos_T new_cursor = curwin->w_cursor; // simple case: insert into one line at a time if (y_type == kMTCharWise && y_size == 1) { @@ -3445,8 +3411,8 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) } else { totlen = (size_t)count * (size_t)yanklen; do { - oldp = ml_get(lnum); - oldlen = strlen(oldp); + char *oldp = ml_get(lnum); + size_t oldlen = strlen(oldp); if (lnum > start_lnum) { pos_T pos = { .lnum = lnum, @@ -3461,10 +3427,10 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) lnum++; continue; } - newp = xmalloc(totlen + oldlen + 1); + char *newp = xmalloc(totlen + oldlen + 1); memmove(newp, oldp, (size_t)col); - ptr = newp + col; - for (i = 0; i < (size_t)count; i++) { + char *ptr = newp + col; + for (size_t i = 0; i < (size_t)count; i++) { memmove(ptr, y_array[0], (size_t)yanklen); ptr += yanklen; } @@ -3506,20 +3472,19 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) } } else { linenr_T new_lnum = new_cursor.lnum; - size_t len; // Insert at least one line. When y_type is kMTCharWise, break the first // line in two. - for (cnt = 1; cnt <= count; cnt++) { - i = 0; + for (int cnt = 1; cnt <= count; cnt++) { + size_t i = 0; if (y_type == kMTCharWise) { // Split the current line in two at the insert position. // 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; + char *ptr = ml_get(lnum) + col; totlen = strlen(y_array[y_size - 1]); - newp = xmalloc((size_t)(strlen(ptr) + totlen + 1)); + char *newp = xmalloc((size_t)(strlen(ptr) + totlen + 1)); STRCPY(newp, y_array[y_size - 1]); STRCAT(newp, ptr); // insert second line @@ -3527,7 +3492,7 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) new_lnum++; xfree(newp); - oldp = ml_get(lnum); + char *oldp = ml_get(lnum); newp = xmalloc((size_t)col + (size_t)yanklen + 1); // copy first part of line memmove(newp, oldp, (size_t)col); @@ -3549,9 +3514,9 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) lnum++; nr_lines++; if (flags & PUT_FIXINDENT) { - old_pos = curwin->w_cursor; + pos_T old_pos = curwin->w_cursor; curwin->w_cursor.lnum = lnum; - ptr = ml_get(lnum); + char *ptr = ml_get(lnum); if (cnt == count && i == y_size - 1) { lendiff = (int)strlen(ptr); } @@ -3626,7 +3591,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]); + size_t len = strlen(y_array[y_size - 1]); col = (colnr_T)len - lendiff; if (col > 1) { curbuf->b_op_end.col = col - 1; @@ -3766,7 +3731,6 @@ void ex_display(exarg_T *eap) char *p; yankreg_T *yb; char *arg = eap->arg; - int clen; int type; if (arg != NULL && *arg == NUL) { @@ -3833,7 +3797,7 @@ void ex_display(exarg_T *eap) } for (p = yb->y_array[j]; *p != NUL && (n -= ptr2cells(p)) >= 0; p++) { - clen = utfc_ptr2len(p); + int clen = utfc_ptr2len(p); msg_outtrans_len(p, clen, 0); p += clen - 1; } @@ -3932,7 +3896,6 @@ static void dis_msg(const char *p, bool skip_esc) 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(line, &comment_flags); *is_comment = false; @@ -3955,7 +3918,7 @@ char *skip_comment(char *line, bool process, bool include_space, bool *is_commen return line; } - lead_len = get_leader_len(line, &comment_flags, false, include_space); + int lead_len = get_leader_len(line, &comment_flags, false, include_space); if (lead_len == 0) { return line; @@ -3996,14 +3959,10 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions 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 int sumsize = 0; // size of the long new line - linenr_T t; - colnr_T col = 0; int ret = OK; int *comments = NULL; int remove_comments = (use_formatoptions == true) @@ -4018,7 +3977,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions // Allocate an array to store the number of spaces inserted before each // line. We will use it to pre-compute the length of the new line and the // proper placement of each original line in the new one. - spaces = xcalloc(count, 1); + char *spaces = xcalloc(count, 1); // number of spaces inserted before a line if (remove_comments) { comments = xcalloc(count, sizeof(*comments)); } @@ -4026,7 +3985,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions // Don't move anything yet, just compute the final line length // and setup the array of space strings lengths // This loops forward over joined lines. - for (t = 0; t < (linenr_T)count; t++) { + for (linenr_T t = 0; t < (linenr_T)count; t++) { curr_start = ml_get(curwin->w_cursor.lnum + t); curr = curr_start; if (t == 0 && setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) { @@ -4098,10 +4057,10 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions } // store the column position before last line - col = sumsize - currsize - spaces[count - 1]; + colnr_T col = sumsize - currsize - spaces[count - 1]; // allocate the space for the new line - newp = xmalloc((size_t)sumsize + 1); + char *newp = xmalloc((size_t)sumsize + 1); cend = newp + sumsize; *cend = 0; @@ -4114,7 +4073,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions curbuf_splice_pending++; - for (t = (linenr_T)count - 1;; t--) { + for (linenr_T t = (linenr_T)count - 1;; t--) { cend -= currsize; memmove(cend, curr, (size_t)currsize); if (spaces[t] > 0) { @@ -4163,7 +4122,7 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions // 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; + linenr_T t = curwin->w_cursor.lnum; curwin->w_cursor.lnum++; del_lines((int)count - 1, false); curwin->w_cursor.lnum = t; @@ -4227,11 +4186,6 @@ static void restore_lbr(bool lbr_saved) static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool is_del) { int incr = 0; - char *pend; - char *pstart; - char *line; - char *prev_pstart; - char *prev_pend; // Avoid a problem with unwanted linebreaks in block mode. const bool lbr_saved = reset_lbr(); @@ -4247,8 +4201,8 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool bdp->end_char_vcols = 0; bdp->start_char_vcols = 0; - line = ml_get(lnum); - prev_pstart = line; + char *line = ml_get(lnum); + char *prev_pstart = line; chartabsize_T cts; init_chartabsize_arg(&cts, curwin, lnum, bdp->start_vcol, line, line); @@ -4267,7 +4221,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool MB_PTR_ADV(cts.cts_ptr); } bdp->start_vcol = cts.cts_vcol; - pstart = cts.cts_ptr; + char *pstart = cts.cts_ptr; clear_chartabsize_arg(&cts); bdp->start_char_vcols = incr; @@ -4284,7 +4238,7 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool if (is_del && bdp->startspaces) { bdp->startspaces = bdp->start_char_vcols - bdp->startspaces; } - pend = pstart; + char *pend = pstart; bdp->end_vcol = bdp->start_vcol; if (bdp->end_vcol > oap->end_vcol) { // it's all in one character bdp->is_oneChar = true; @@ -4306,7 +4260,7 @@ 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); - prev_pend = pend; + char *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 = cts.cts_ptr; @@ -4358,7 +4312,6 @@ static void block_prep(oparg_T *oap, struct block_def *bdp, linenr_T lnum, bool /// @param[in] g_cmd Prefixed with `g`. void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) { - pos_T pos; struct block_def bd; ssize_t change_cnt = 0; linenr_T amount = Prenum1; @@ -4369,7 +4322,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) disable_fold_update++; if (!VIsual_active) { - pos = curwin->w_cursor; + pos_T pos = curwin->w_cursor; if (u_save_cursor() == FAIL) { disable_fold_update--; return; @@ -4389,7 +4342,7 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) return; } - pos = oap->start; + pos_T pos = oap->start; for (; pos.lnum <= oap->end.lnum; pos.lnum++) { if (oap->motion_type == kMTBlockWise) { // Visual block mode @@ -4466,17 +4419,11 @@ void op_addsub(oparg_T *oap, linenr_T Prenum1, bool g_cmd) /// @return true if some character was changed. int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) { - int col; char *buf1 = NULL; 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 *ptr; - int c; - int todel; - int firstdigit; bool negative = false; bool was_positive = true; bool visual = VIsual_active; @@ -4500,8 +4447,8 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) } curwin->w_cursor = *pos; - ptr = ml_get(pos->lnum); - col = pos->col; + char *ptr = ml_get(pos->lnum); + int col = pos->col; if (*ptr == NUL || col + !!save_coladd >= (int)strlen(ptr)) { goto theend; @@ -4594,7 +4541,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 = (uint8_t)ptr[col]; + int firstdigit = (uint8_t)ptr[col]; if (!ascii_isdigit(firstdigit) && !(do_alpha && ASCII_ISALPHA(firstdigit))) { beep_flush(); goto theend; @@ -4670,7 +4617,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) subtract ^= true; } - oldn = n; + uvarnumber_T oldn = n; if (!overflow) { // if number is too big don't add/subtract n = subtract ? n - (uvarnumber_T)Prenum1 @@ -4717,8 +4664,8 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) curwin->w_cursor.col = col; startpos = curwin->w_cursor; did_change = true; - todel = length; - c = gchar_cursor(); + int todel = length; + int c = gchar_cursor(); // Don't include the '-' in the length, only the length of the part // after it is kept the same. @@ -5311,7 +5258,6 @@ static varnumber_T line_count_info(char *line, varnumber_T *wc, varnumber_T *cc, /// @param dict when not NULL, store the info there instead of showing it. void cursor_pos_info(dict_T *dict) { - char *p; char buf1[50]; char buf2[40]; varnumber_T byte_count = 0; @@ -5334,7 +5280,6 @@ void cursor_pos_info(dict_T *dict) return; } } else { - linenr_T lnum; int eol_size; varnumber_T last_check = 100000; int line_count_selected = 0; @@ -5382,7 +5327,7 @@ void cursor_pos_info(dict_T *dict) line_count_selected = max_pos.lnum - min_pos.lnum + 1; } - for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; lnum++) { + for (linenr_T lnum = 1; lnum <= curbuf->b_ml.ml_line_count; lnum++) { // Check for a CTRL-C every 100000 characters. if (byte_count > last_check) { os_breakcheck(); @@ -5488,7 +5433,7 @@ void cursor_pos_info(dict_T *dict) (int64_t)byte_count_cursor, (int64_t)byte_count); } } else { - p = get_cursor_line_ptr(); + char *p = get_cursor_line_ptr(); validate_virtcol(); col_print(buf1, sizeof(buf1), (int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1); @@ -5529,7 +5474,7 @@ void cursor_pos_info(dict_T *dict) } if (dict == NULL) { // Don't shorten this message, the user asked for it. - p = p_shm; + char *p = p_shm; p_shm = ""; if (p_ch < 1) { msg_start(); -- cgit From a6e3d93421ba13c407a96fac9cc01fa41ec7ad98 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 16 Nov 2023 10:59:11 +0100 Subject: refactor: enable formatting for ternaries This requires removing the "Inner expression should be aligned" rule from clint as it prevents essentially any formatting regarding ternary operators. --- src/nvim/ops.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 34aa2c80db..c6f7c74d6b 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -451,8 +451,8 @@ static void shift_block(oparg_T *oap, int amount) const colnr_T block_space_width = non_white_col - oap->start_vcol; // We will shift by "total" or "block_space_width", whichever is less. const colnr_T shift_amount = block_space_width < total - ? block_space_width - : total; + ? block_space_width + : total; // The column to which we will shift the text. const colnr_T destination_col = non_white_col - shift_amount; @@ -688,8 +688,8 @@ void op_reindent(oparg_T *oap, Indenter how) // there is no change still need to remove the Visual highlighting. if (last_changed != 0) { changed_lines(curbuf, first_changed, 0, - oap->is_VIsual ? start_lnum + oap->line_count : - last_changed + 1, 0, true); + oap->is_VIsual ? start_lnum + oap->line_count + : last_changed + 1, 0, true); } else if (oap->is_VIsual) { redraw_curbuf_later(UPD_INVERTED); } @@ -2067,8 +2067,8 @@ void op_tilde(oparg_T *oap) } else { while (true) { did_change |= swapchars(oap->op_type, &pos, - pos.lnum == oap->end.lnum ? oap->end.col + 1 : - (int)strlen(ml_get_pos(&pos))); + pos.lnum == oap->end.lnum ? oap->end.col + 1 + : (int)strlen(ml_get_pos(&pos))); if (ltoreq(oap->end, pos) || inc(&pos) == -1) { break; } @@ -2913,8 +2913,9 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) bool non_linewise_vis = (VIsual_active && VIsual_mode != 'V'); // PUT_LINE has special handling below which means we use 'i' to start. - char command_start_char = non_linewise_vis ? 'c' : - (flags & PUT_LINE ? 'i' : (dir == FORWARD ? 'a' : 'i')); + char command_start_char = non_linewise_vis + ? 'c' + : (flags & PUT_LINE ? 'i' : (dir == FORWARD ? 'a' : 'i')); // To avoid 'autoindent' on linewise puts, create a new line with `:put _`. if (flags & PUT_LINE) { @@ -3125,8 +3126,8 @@ void do_put(int regname, yankreg_T *reg, int dir, int count, int flags) } // In an empty buffer the empty line is going to be replaced, include // it in the saved lines. - if ((buf_is_empty(curbuf) ? - u_save(0, 2) : u_save(lnum - 1, lnum)) == FAIL) { + if ((buf_is_empty(curbuf) + ? u_save(0, 2) : u_save(lnum - 1, lnum)) == FAIL) { goto end; } if (dir == FORWARD) { @@ -6201,8 +6202,8 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank) break; } op_reindent(oap, - *curbuf->b_p_inde != NUL ? get_expr_indent : - get_c_indent); + *curbuf->b_p_inde != NUL ? get_expr_indent + : get_c_indent); break; } -- cgit From 40139738eb479d0913ec6ce751ca5adfa50ad8c3 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 26 Nov 2023 21:36:02 +0100 Subject: build: enable IWYU on mac --- src/nvim/ops.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index c6f7c74d6b..1144829a17 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "nvim/api/private/defs.h" #include "nvim/ascii.h" -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- 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 1144829a17..e31f126834 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -57,7 +57,7 @@ #include "nvim/strings.h" #include "nvim/terminal.h" #include "nvim/textformat.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/vim.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/ops.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index e31f126834..e66f46945e 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -12,8 +12,8 @@ #include #include "nvim/api/private/defs.h" -#include "nvim/ascii.h" -#include "nvim/assert.h" +#include "nvim/ascii_defs.h" +#include "nvim/assert_defs.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" #include "nvim/change.h" @@ -36,7 +36,7 @@ #include "nvim/indent.h" #include "nvim/indent_c.h" #include "nvim/keycodes.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/mark.h" #include "nvim/mbyte.h" #include "nvim/memline.h" @@ -60,7 +60,7 @@ #include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/undo.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #include "nvim/window.h" static yankreg_T y_regs[NUM_REGISTERS] = { 0 }; -- cgit From a6cba103cebce535279db197f9efeb34e9d1171f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 20:32:40 +0800 Subject: refactor: move some constants out of vim_defs.h (#26298) --- src/nvim/ops.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index e66f46945e..3a4e87edf7 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -32,7 +32,7 @@ #include "nvim/getchar.h" #include "nvim/gettext.h" #include "nvim/globals.h" -#include "nvim/highlight_defs.h" +#include "nvim/highlight.h" #include "nvim/indent.h" #include "nvim/indent_c.h" #include "nvim/keycodes.h" @@ -103,9 +103,9 @@ static const char e_search_pattern_and_expression_register_may_not_contain_two_o #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 ops.h!!! +/// The third field indicates whether the operator always works on lines. static char opchars[][3] = { { NUL, NUL, 0 }, // OP_NOP { 'd', NUL, OPF_CHANGE }, // OP_DELETE -- cgit