From d391940b9a074bca7ee82460ccaaabf46b5f2ba9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 15 Jan 2022 19:21:17 +0800 Subject: vim-patch:8.2.3227: 'virtualedit' can only be set globally Problem: 'virtualedit' can only be set globally. Solution: Make 'virtualedit' global-local. (Gary Johnson, closes vim/vim#8638) https://github.com/vim/vim/commit/53ba05b09075f14227f9be831a22ed16f7cc26b2 I changed some macros to unsigned integer literals to avoid compiler warnings. --- src/nvim/change.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 1dbbfff024..0c16b204e3 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -789,7 +789,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) // fixpos is true, we don't want to end up positioned at the NUL, // unless "restart_edit" is set or 'virtualedit' contains "onemore". if (col > 0 && fixpos && restart_edit == 0 - && (ve_flags & VE_ONEMORE) == 0) { + && (get_ve_flags() & VE_ONEMORE) == 0) { curwin->w_cursor.col--; curwin->w_cursor.coladd = 0; curwin->w_cursor.col -= utf_head_off(oldp, oldp + curwin->w_cursor.col); -- cgit From eda957db10e97b28a2734e0391d986676927d963 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 31 Jan 2022 15:44:54 +0800 Subject: vim-patch:8.2.3787: no proper formatting of a C line comment after a statement Problem: No proper formatting of a C line comment after a statement. Solution: Find the start of the line comment, insert the comment leader and indent the comment properly. https://github.com/vim/vim/commit/6e371ecb27227ff8fedd8561d0f3880a17576848 --- src/nvim/change.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 0c16b204e3..02893e53b0 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -952,11 +952,13 @@ int copy_indent(int size, char_u *src) /// /// "second_line_indent": indent for after ^^D in Insert mode or if flag /// OPENLINE_COM_LIST +/// "did_do_comment" is set to true when intentionally putting the comment +/// leader in fromt of the new line. /// /// @param dir FORWARD or BACKWARD /// /// @return true on success, false on failure -int open_line(int dir, int flags, int second_line_indent) +int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) { char_u *next_line = NULL; // copy of the next line char_u *p_extra = NULL; // what goes to next line @@ -969,6 +971,7 @@ int open_line(int dir, int flags, int second_line_indent) bool retval = false; // return value int extra_len = 0; // length of p_extra string int lead_len; // length of comment leader + int comment_start = 0; // start index of the comment leader char_u *lead_flags; // position in 'comments' for comment leader char_u *leader = NULL; // copy of comment leader char_u *allocated = NULL; // allocated memory @@ -977,6 +980,7 @@ int open_line(int dir, int flags, int second_line_indent) pos_T *pos; bool do_si = (!p_paste && curbuf->b_p_si && !curbuf->b_p_cin && *curbuf->b_p_inde == NUL); + bool do_cindent; bool no_si = false; // reset did_si afterwards int first_char = NUL; // init for GCC int vreplace_mode; @@ -1189,11 +1193,29 @@ int open_line(int dir, int flags, int second_line_indent) did_ai = true; } + // May do indenting after opening a new line. + do_cindent = !p_paste && (curbuf->b_p_cin || *curbuf->b_p_inde != NUL) + && in_cinkeys(dir == FORWARD ? KEY_OPEN_FORW : KEY_OPEN_BACK, + ' ', linewhite(curwin->w_cursor.lnum)); + // Find out if the current line starts with a comment leader. // This may then be inserted in front of the new line. end_comment_pending = NUL; if (flags & OPENLINE_DO_COM) { lead_len = get_leader_len(saved_line, &lead_flags, dir == BACKWARD, true); + if (lead_len == 0 && do_cindent) { + comment_start = check_linecomment(saved_line); + if (comment_start != MAXCOL) { + lead_len = get_leader_len(saved_line + comment_start, + &lead_flags, dir == BACKWARD, true); + if (lead_len != 0) { + lead_len += comment_start; + if (did_do_comment != NULL) { + *did_do_comment = true; + } + } + } + } } else { lead_len = 0; } @@ -1349,6 +1371,13 @@ int open_line(int dir, int flags, int second_line_indent) STRLCPY(leader, saved_line, lead_len + 1); + // TODO(vim): handle multi-byte and double width chars + for (int li = 0; li < comment_start; li++) { + if (!ascii_iswhite(leader[li])) { + leader[li] = ' '; + } + } + // Replace leader with lead_repl, right or left adjusted if (lead_repl != NULL) { int c = 0; @@ -1758,13 +1787,7 @@ int open_line(int dir, int flags, int second_line_indent) ai_col = (colnr_T)getwhitecols_curline(); } // May do indenting after opening a new line. - if (!p_paste - && (curbuf->b_p_cin - || *curbuf->b_p_inde != NUL - ) - && in_cinkeys(dir == FORWARD - ? KEY_OPEN_FORW - : KEY_OPEN_BACK, ' ', linewhite(curwin->w_cursor.lnum))) { + if (do_cindent) { do_c_expr_indent(); ai_col = (colnr_T)getwhitecols_curline(); } -- cgit From da3b04a9e07635bab9b0d67e9b16c62c1e59e004 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 31 Jan 2022 15:44:54 +0800 Subject: vim-patch:8.2.3934: repeating line comment is undesired for "O" command Problem: Repeating line comment is undesired for "O" command. Solution: Do not copy line comment leader for "O". (closes vim/vim#9426) https://github.com/vim/vim/commit/5ea5f373729589acb38ce3f3ca338e8a6d398bdc --- src/nvim/change.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 02893e53b0..54c4ba5319 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1201,13 +1201,14 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // Find out if the current line starts with a comment leader. // This may then be inserted in front of the new line. end_comment_pending = NUL; - if (flags & OPENLINE_DO_COM) { + if (flags & OPENLINE_DO_COM && dir == FORWARD) { + // Check for a line comment after code. lead_len = get_leader_len(saved_line, &lead_flags, dir == BACKWARD, true); if (lead_len == 0 && do_cindent) { comment_start = check_linecomment(saved_line); if (comment_start != MAXCOL) { lead_len = get_leader_len(saved_line + comment_start, - &lead_flags, dir == BACKWARD, true); + &lead_flags, false, true); if (lead_len != 0) { lead_len += comment_start; if (did_do_comment != NULL) { -- cgit From 3c75e63bf68f6ee88d1eda31caf042ed132badd9 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 8 Feb 2022 21:10:32 +0800 Subject: vim-patch:8.2.4326: "o" and "O" copying comment not sufficiently tested Problem: "o" and "O" copying comment not sufficiently tested. Solution: Add a test case. (closes vim/vim#9718) https://github.com/vim/vim/commit/51ab7c7d0da08aac796acff22a6c075dac579e76 Fix a mistake when porting Vim patch 8.2.3934 --- src/nvim/change.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 54c4ba5319..6ac759d5e0 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1201,10 +1201,10 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // Find out if the current line starts with a comment leader. // This may then be inserted in front of the new line. end_comment_pending = NUL; - if (flags & OPENLINE_DO_COM && dir == FORWARD) { - // Check for a line comment after code. + if (flags & OPENLINE_DO_COM) { lead_len = get_leader_len(saved_line, &lead_flags, dir == BACKWARD, true); - if (lead_len == 0 && do_cindent) { + if (lead_len == 0 && do_cindent && dir == FORWARD) { + // Check for a line comment after code. comment_start = check_linecomment(saved_line); if (comment_start != MAXCOL) { lead_len = get_leader_len(saved_line + comment_start, -- cgit From 30bf40ec4b44172d2720a6f2365cf6acb5ad8863 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 19 Feb 2022 15:13:37 +0000 Subject: vim-patch:8.2.4403: ml_get error with nested folds and deleting lines Problem: ml_get error with nested folds and deleting lines. Solution: Correct the last line number before calling hasFoldingWin(). https://github.com/vim/vim/commit/943773783384a5ff63f57769d37ddabf8156fe1e --- src/nvim/change.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 6ac759d5e0..736867b6d3 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -223,19 +223,20 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra // values for the cursor. // Update the folds for this window. Can't postpone this, because // a following operator might work on the whole fold: ">>dd". - foldUpdate(wp, lnum, lnume + xtra - 1); + linenr_T last = lnume + xtra - 1; // last line after the change + foldUpdate(wp, lnum, last); // The change may cause lines above or below the change to become // included in a fold. Set lnum/lnume to the first/last line that // might be displayed differently. // Set w_cline_folded here as an efficient way to update it when - // inserting lines just above a closed fold. */ + // inserting lines just above a closed fold. bool folded = hasFoldingWin(wp, lnum, &lnum, NULL, false, NULL); if (wp->w_cursor.lnum == lnum) { wp->w_cline_folded = folded; } - folded = hasFoldingWin(wp, lnume, NULL, &lnume, false, NULL); - if (wp->w_cursor.lnum == lnume) { + folded = hasFoldingWin(wp, last, NULL, &last, false, NULL); + if (wp->w_cursor.lnum == last) { wp->w_cline_folded = folded; } -- cgit From 198bf3a8f2897d679a297fd04e3183dbac8bd61e Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Sat, 12 Mar 2022 17:54:31 +0100 Subject: refactor: minimize variable scope and eliminate empty declarations --- src/nvim/change.c | 78 ++++++++++++++++++++----------------------------------- 1 file changed, 28 insertions(+), 50 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 736867b6d3..607414ac3c 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -42,7 +42,7 @@ /// Careful: may trigger autocommands that reload the buffer. void change_warning(buf_T *buf, int col) { - static char *w_readonly = N_("W10: Warning: Changing a readonly file"); + static const char *w_readonly = N_("W10: Warning: Changing a readonly file"); if (buf->b_did_warn == false && curbufIsChanged() == 0 @@ -140,10 +140,6 @@ void changed_internal(void) /// Careful: may trigger autocommands that reload the buffer. static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra) { - int i; - pos_T *p; - int add; - // mark the buffer as modified changed(); @@ -158,13 +154,14 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra // Create a new entry if a new undo-able change was started or we // don't have an entry yet. if (curbuf->b_new_change || curbuf->b_changelistlen == 0) { + int add; if (curbuf->b_changelistlen == 0) { add = true; } else { // Don't create a new entry when the line number is the same // as the last one and the column is not too far away. Avoids // creating many entries for typing "xxxxx". - p = &curbuf->b_changelist[curbuf->b_changelistlen - 1].mark; + pos_T *p = &curbuf->b_changelist[curbuf->b_changelistlen - 1].mark; if (p->lnum != lnum) { add = true; } else { @@ -243,7 +240,7 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra // If the changed line is in a range of previously folded lines, // compare with the first line in that range. if (wp->w_cursor.lnum <= lnum) { - i = find_wl_entry(wp, lnum); + int i = find_wl_entry(wp, lnum); if (i >= 0 && wp->w_cursor.lnum > wp->w_lines[i].wl_lnum) { changed_line_abv_curs_win(wp); } @@ -264,7 +261,7 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra // For entries below the change: Correct the lnums for // inserted/deleted lines. Makes it possible to stop displaying // after the change. - for (i = 0; i < wp->w_lines_valid; i++) { + for (int i = 0; i < wp->w_lines_valid; i++) { if (wp->w_lines[i].wl_valid) { if (wp->w_lines[i].wl_lnum >= lnum) { if (wp->w_lines[i].wl_lnum < lnume) { @@ -352,12 +349,10 @@ void changed_bytes(linenr_T lnum, colnr_T col) // Diff highlighting in other diff windows may need to be updated too. if (curwin->w_p_diff) { - linenr_T wlnum; - FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { if (wp->w_p_diff && wp != curwin) { redraw_later(wp, VALID); - wlnum = diff_lnum_win(lnum, wp); + linenr_T wlnum = diff_lnum_win(lnum, wp); if (wlnum > 0) { changedOneline(wp->w_buffer, wlnum); } @@ -673,21 +668,18 @@ void ins_char_bytes(char_u *buf, size_t charlen) /// Caller must have prepared for undo. void ins_str(char_u *s) { - char_u *oldp, *newp; int newlen = (int)STRLEN(s); - int oldlen; - colnr_T col; linenr_T lnum = curwin->w_cursor.lnum; if (virtual_active() && curwin->w_cursor.coladd > 0) { coladvance_force(getviscol()); } - col = curwin->w_cursor.col; - oldp = ml_get(lnum); - oldlen = (int)STRLEN(oldp); + colnr_T col = curwin->w_cursor.col; + char_u *oldp = ml_get(lnum); + int oldlen = (int)STRLEN(oldp); - newp = (char_u *)xmalloc((size_t)oldlen + (size_t)newlen + 1); + char_u *newp = (char_u *)xmalloc((size_t)oldlen + (size_t)newlen + 1); if (col > 0) { memmove(newp, oldp, (size_t)col); } @@ -719,13 +711,9 @@ int del_char(bool fixpos) int del_chars(long count, int fixpos) { int bytes = 0; - long i; - char_u *p; - int l; - - p = get_cursor_pos_ptr(); - for (i = 0; i < count && *p != NUL; i++) { - l = utfc_ptr2len(p); + char_u *p = get_cursor_pos_ptr(); + for (long i = 0; i < count && *p != NUL; i++) { + int l = utfc_ptr2len(p); bytes += l; p += l; } @@ -768,12 +756,11 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) if (p_deco && use_delcombine && utfc_ptr2len(oldp + col) >= count) { int cc[MAX_MCO]; - int n; (void)utfc_ptr2char(oldp + col, cc); if (cc[0] != NUL) { // Find the last composing char, there can be several. - n = col; + int n = col; do { col = n; count = utf_ptr2len(oldp + n); @@ -828,23 +815,18 @@ int copy_indent(int size, char_u *src) { char_u *p = NULL; char_u *line = NULL; - char_u *s; - int todo; int ind_len; int line_len = 0; int tab_pad; - int ind_done; - int round; - int ind_col; // Round 1: compute the number of characters needed for the indent // Round 2: copy the characters. - for (round = 1; round <= 2; round++) { - todo = size; + for (int round = 1; round <= 2; round++) { + int todo = size; ind_len = 0; - ind_done = 0; - ind_col = 0; - s = src; + int ind_done = 0; + int ind_col = 0; + char_u *s = src; // Count/copy the usable portion of the source line. while (todo > 0 && ascii_iswhite(*s)) { @@ -1065,7 +1047,6 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) if (!trunc_line && do_si && *saved_line != NUL && (p_extra == NULL || first_char != '{')) { char_u *ptr; - char_u last_char; old_cursor = curwin->w_cursor; ptr = saved_line; @@ -1075,8 +1056,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) lead_len = 0; } if (dir == FORWARD) { - // Skip preprocessor directives, unless they are - // recognised as comments. + // Skip preprocessor directives, unless they are recognised as comments. if (lead_len == 0 && ptr[0] == '#') { while (ptr[0] == '#' && curwin->w_cursor.lnum > 1) { ptr = ml_get(--curwin->w_cursor.lnum); @@ -1119,7 +1099,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) while (p > ptr && ascii_iswhite(*p)) { p--; } - last_char = *p; + char_u last_char = *p; // find the character just before the '{' or ';' if (last_char == '{' || last_char == ';') { @@ -1896,10 +1876,8 @@ void del_lines(long nlines, bool undo) /// If "include_space" is set, include trailing whitespace while calculating the length. int get_leader_len(char_u *line, char_u **flags, bool backward, bool include_space) { - int i, j; - int result; + int j; int got_com = false; - int found_one; char_u part_buf[COM_MAX_LEN]; // buffer for one option part char_u *string; // pointer to comment string char_u *list; @@ -1907,7 +1885,8 @@ int get_leader_len(char_u *line, char_u **flags, bool backward, bool include_spa char_u *prev_list; char_u *saved_flags = NULL; - result = i = 0; + int result = 0; + int i = 0; while (ascii_iswhite(line[i])) { // leading white space is ignored i++; } @@ -1915,7 +1894,7 @@ int get_leader_len(char_u *line, char_u **flags, bool backward, bool include_spa // Repeat to match several nested comment strings. while (line[i] != NUL) { // scan through the 'comments' option for a match - found_one = false; + int found_one = false; for (list = curbuf->b_p_com; *list;) { // Get one option part into part_buf[]. Advance "list" to next // one. Put "string" at start of string. @@ -2041,20 +2020,19 @@ int get_leader_len(char_u *line, char_u **flags, bool backward, bool include_spa int get_last_leader_offset(char_u *line, char_u **flags) { int result = -1; - int i, j; + int j; int lower_check_bound = 0; char_u *string; char_u *com_leader; char_u *com_flags; char_u *list; - int found_one; char_u part_buf[COM_MAX_LEN]; // buffer for one option part // Repeat to match several nested comment strings. - i = (int)STRLEN(line); + int i = (int)STRLEN(line); while (--i >= lower_check_bound) { // scan through the 'comments' option for a match - found_one = false; + int found_one = false; for (list = curbuf->b_p_com; *list;) { char_u *flags_save = list; -- cgit From d238b8f6003d34cae7f65ff7585b48a2cd9449fb Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Thu, 17 Mar 2022 06:21:24 +0100 Subject: chore: fix typos (#17670) Co-authored-by: zeertzjq --- src/nvim/change.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 607414ac3c..6c3dbf72e4 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -408,7 +408,7 @@ void deleted_lines(linenr_T lnum, long count) /// be triggered to display the cursor. void deleted_lines_mark(linenr_T lnum, long count) { - // if we deleted the entire buffer, we need to implicity add a new empty line + // if we deleted the entire buffer, we need to implicitly add a new empty line bool made_empty = (count > 0) && curbuf->b_ml.ml_flags & ML_EMPTY; mark_adjust(lnum, (linenr_T)(lnum + count - 1), (long)MAXLNUM, -- cgit From 81d7628c3fadaa72b879b5e934d30c609d7c89f8 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Tue, 29 Mar 2022 12:37:42 +0100 Subject: vim-patch:8.2.4644: redrawing too often when 'relativenumber' is set (#17756) Problem: Redrawing too often when 'relativenumber' is set. Solution: Only redraw when the cursor line changed. (Lewis Russell, closes vim/vim#10040) https://github.com/vim/vim/commit/1624639ec8a6c3c99e417a2990f2f02f0d0b6e10 --- src/nvim/change.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 6c3dbf72e4..0644b1d601 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -287,7 +287,7 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra } // Relative numbering may require updating more. - if (wp->w_p_rnu) { + if (wp->w_p_rnu && xtra != 0) { redraw_later(wp, SOME_VALID); } -- cgit From 1edca3872e7c80a5396b84ffddb879cc18633d56 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 7 Apr 2022 23:26:03 +0800 Subject: vim-patch:8.2.4707: redrawing could be a bit more efficient (#18022) Problem: Redrawing could be a bit more efficient. Solution: Optimize redrawing. (closes vim/vim#10105) https://github.com/vim/vim/commit/8c9796085071950f9a03ca0fe116608e4f86aac2 --- src/nvim/change.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 0644b1d601..44abd69733 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -286,9 +286,11 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra set_topline(wp, wp->w_topline); } - // Relative numbering may require updating more. + // If lines have been added or removed, relative numbering always + // requires a redraw. if (wp->w_p_rnu && xtra != 0) { - redraw_later(wp, SOME_VALID); + wp->w_last_cursor_lnum_rnu = 0; + redraw_later(wp, VALID); } // Cursor line highlighting probably need to be updated with -- cgit From 85b33fc0426049b5cf3e65bb76aa600272785109 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Mon, 11 Apr 2022 22:50:17 +0200 Subject: vim-patch:8.2.4737: // in JavaScript string recognized as comment (#18083) Problem: // in JavaScript string recognized as comment. Solution: Only check for linecomment if 'cindent' is set. (closes vim/vim#10151) https://github.com/vim/vim/commit/1655619717ff109ea8bf1002883636d5af345e48 --- src/nvim/change.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 44abd69733..024969415d 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1186,7 +1186,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) end_comment_pending = NUL; if (flags & OPENLINE_DO_COM) { lead_len = get_leader_len(saved_line, &lead_flags, dir == BACKWARD, true); - if (lead_len == 0 && do_cindent && dir == FORWARD) { + if (lead_len == 0 && curbuf->b_p_cin && do_cindent && dir == FORWARD) { // Check for a line comment after code. comment_start = check_linecomment(saved_line); if (comment_start != MAXCOL) { -- cgit From eef8de4df0247157e57f306062b1b86e01a41454 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Fri, 29 Apr 2022 13:53:42 +0200 Subject: refactor(uncrustify): change rules to better align with the style guide Add space around arithmetic operators '+' and '-'. Remove space between back-to-back parentheses, i.e. ')(' vs. ') ('. Remove space between '((' or '))' of control statements. Add space between ')' and '{' of control statements. Remove space between function name and '(' on function declaration. Collapse empty blocks between '{' and '}'. Remove newline at the end of the file. Remove newline between 'enum' and '{'. Remove newline between '}' and ')' in a function invocation. Remove newline between '}' and 'while' of 'do' statement. --- src/nvim/change.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 024969415d..c751507955 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -369,7 +369,7 @@ void changed_bytes(linenr_T lnum, colnr_T col) void inserted_bytes(linenr_T lnum, colnr_T col, int old, int new) { if (curbuf_splice_pending == 0) { - extmark_splice_cols(curbuf, (int)lnum-1, col, old, new, kExtmarkUndo); + extmark_splice_cols(curbuf, (int)lnum - 1, col, old, new, kExtmarkUndo); } changed_bytes(lnum, col); @@ -1306,8 +1306,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) p--; } for (lead_repl = p; lead_repl > curbuf->b_p_com - && lead_repl[-1] != ':'; lead_repl--) { - } + && lead_repl[-1] != ':'; lead_repl--) {} lead_repl_len = (int)(p - lead_repl); // We can probably always add an extra space when doing "O" on @@ -1379,8 +1378,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) if (c == COM_RIGHT) { // right adjusted leader // find last non-white in the leader to line up with for (p = leader + lead_len - 1; p > leader - && ascii_iswhite(*p); p--) { - } + && ascii_iswhite(*p); p--) {} p++; // Compute the length of the replaced characters in @@ -1728,8 +1726,8 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } // Always move extmarks - Here we move only the line where the // cursor is, the previous mark_adjust takes care of the lines after - int cols_added = mincol-1+less_cols_off-less_cols; - extmark_splice(curbuf, (int)lnum-1, mincol-1 - cols_spliced, + int cols_added = mincol - 1 + less_cols_off - less_cols; + extmark_splice(curbuf, (int)lnum - 1, mincol - 1 - cols_spliced, 0, less_cols_off, less_cols_off, 1, cols_added, 1 + cols_added, kExtmarkUndo); } else { @@ -1745,8 +1743,8 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) changed_lines(curwin->w_cursor.lnum, 0, curwin->w_cursor.lnum, 1L, true); // bail out and just get the final length of the line we just manipulated bcount_t extra = (bcount_t)STRLEN(ml_get(curwin->w_cursor.lnum)); - extmark_splice(curbuf, (int)curwin->w_cursor.lnum-1, 0, - 0, 0, 0, 1, 0, 1+extra, kExtmarkUndo); + extmark_splice(curbuf, (int)curwin->w_cursor.lnum - 1, 0, + 0, 0, 0, 1, 0, 1 + extra, kExtmarkUndo); } curbuf_splice_pending--; @@ -1942,8 +1940,7 @@ int get_leader_len(char_u *line, char_u **flags, bool backward, bool include_spa string++; } } - for (j = 0; string[j] != NUL && string[j] == line[i + j]; j++) { - } + for (j = 0; string[j] != NUL && string[j] == line[i + j]; j++) {} if (string[j] != NUL) { continue; // string doesn't match } @@ -2081,8 +2078,7 @@ int get_last_leader_offset(char_u *line, char_u **flags) // whitespace. Otherwise we would think we are inside a // comment if the middle part appears somewhere in the middle // of the line. E.g. for C the "*" appears often. - for (j = 0; j <= i && ascii_iswhite(line[j]); j++) { - } + for (j = 0; j <= i && ascii_iswhite(line[j]); j++) {} if (j < i) { continue; } -- cgit From 9a671e6a24243a5ff2879599d91ab5aec8b4e77d Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Wed, 4 May 2022 18:27:22 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/change.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index c751507955..2d5ece8880 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -645,7 +645,7 @@ void ins_char_bytes(char_u *buf, size_t charlen) } // Replace the line in the buffer. - ml_replace(lnum, newp, false); + ml_replace(lnum, (char *)newp, false); // mark the buffer as changed and prepare for displaying inserted_bytes(lnum, (colnr_T)col, (int)oldlen, (int)newlen); @@ -689,7 +689,7 @@ void ins_str(char_u *s) int bytes = oldlen - col + 1; assert(bytes >= 0); memmove(newp + col + newlen, oldp + col, (size_t)bytes); - ml_replace(lnum, newp, false); + ml_replace(lnum, (char *)newp, false); inserted_bytes(lnum, col, 0, newlen); curwin->w_cursor.col += newlen; } @@ -801,7 +801,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) } memmove(newp + col, oldp + col + count, (size_t)movelen); if (!was_alloced) { - ml_replace(lnum, newp, false); + ml_replace(lnum, (char *)newp, false); } // mark the buffer as changed and prepare for displaying @@ -914,7 +914,7 @@ int copy_indent(int size, char_u *src) memmove(p, get_cursor_line_ptr(), (size_t)line_len); // Replace the line - ml_replace(curwin->w_cursor.lnum, line, false); + ml_replace(curwin->w_cursor.lnum, (char *)line, false); // Put the cursor after the indent. curwin->w_cursor.col = ind_len; @@ -1612,7 +1612,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) curwin->w_cursor.lnum--; } if (!(State & VREPLACE_FLAG) || old_cursor.lnum >= orig_line_count) { - if (ml_append(curwin->w_cursor.lnum, p_extra, (colnr_T)0, false) == FAIL) { + if (ml_append(curwin->w_cursor.lnum, (char *)p_extra, (colnr_T)0, false) == FAIL) { goto theend; } // Postpone calling changed_lines(), because it would mess up folding @@ -1634,7 +1634,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) (void)u_save_cursor(); // errors are ignored! vr_lines_changed++; } - ml_replace(curwin->w_cursor.lnum, p_extra, true); + ml_replace(curwin->w_cursor.lnum, (char *)p_extra, true); changed_bytes(curwin->w_cursor.lnum, 0); // TODO(vigoux): extmark_splice_cols here?? curwin->w_cursor.lnum--; @@ -1700,7 +1700,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) if (trunc_line && !(flags & OPENLINE_KEEPTRAIL)) { truncate_spaces(saved_line); } - ml_replace(curwin->w_cursor.lnum, saved_line, false); + ml_replace(curwin->w_cursor.lnum, (char *)saved_line, false); int new_len = (int)STRLEN(saved_line); @@ -1785,7 +1785,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) p_extra = vim_strsave(get_cursor_line_ptr()); // Put back original line - ml_replace(curwin->w_cursor.lnum, next_line, false); + ml_replace(curwin->w_cursor.lnum, (char *)next_line, false); // Insert new stuff into line again curwin->w_cursor.col = 0; @@ -1818,7 +1818,7 @@ void truncate_line(int fixpos) } else { newp = vim_strnsave(ml_get(lnum), (size_t)col); } - ml_replace(lnum, newp, false); + ml_replace(lnum, (char *)newp, false); // mark the buffer as changed and prepare for displaying changed_bytes(lnum, curwin->w_cursor.col); -- cgit From d0897243f6a6bb802fc9622486afd69eb65fa6d5 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Fri, 6 May 2022 17:40:52 +0200 Subject: build(clint): remove "function size is too large" warning This warning is essentially only triggered for ported vim functions. It's unlikely that we'll refactor vim functions solely based on their size since it'd mean we'd greatly deviate from vim, which is a high cost when it comes to importing the vim patches. Thus, this warning only serves as an annoyance and should be removed. --- src/nvim/change.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 2d5ece8880..df7a7a00a9 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1802,7 +1802,7 @@ theend: xfree(next_line); xfree(allocated); return retval; -} // NOLINT(readability/fn_size) +} /// Delete from cursor to end of line. /// Caller must have prepared for undo. -- cgit From 2a378e6e82cececb12339f2df51ffe107039d867 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Wed, 4 May 2022 22:35:50 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/change.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 2d5ece8880..1ddb83db0b 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -599,7 +599,7 @@ void ins_char_bytes(char_u *buf, size_t charlen) if (vcol > new_vcol && oldp[col + oldlen] == TAB) { break; } - oldlen += (size_t)utfc_ptr2len(oldp + col + oldlen); + oldlen += (size_t)utfc_ptr2len((char *)oldp + col + oldlen); // Deleted a bit too much, insert spaces. if (vcol > new_vcol) { newlen += (size_t)(vcol - new_vcol); @@ -608,7 +608,7 @@ void ins_char_bytes(char_u *buf, size_t charlen) curwin->w_p_list = old_list; } else if (oldp[col] != NUL) { // normal replace - oldlen = (size_t)utfc_ptr2len(oldp + col); + oldlen = (size_t)utfc_ptr2len((char *)oldp + col); } @@ -655,7 +655,7 @@ void ins_char_bytes(char_u *buf, size_t charlen) if (p_sm && (State & INSERT) && msg_silent == 0 && !ins_compl_active()) { - showmatch(utf_ptr2char(buf)); + showmatch(utf_ptr2char((char *)buf)); } if (!p_ri || (State & REPLACE_FLAG)) { @@ -715,7 +715,7 @@ int del_chars(long count, int fixpos) int bytes = 0; char_u *p = get_cursor_pos_ptr(); for (long i = 0; i < count && *p != NUL; i++) { - int l = utfc_ptr2len(p); + int l = utfc_ptr2len((char *)p); bytes += l; p += l; } @@ -756,7 +756,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) // If 'delcombine' is set and deleting (less than) one character, only // delete the last combining character. if (p_deco && use_delcombine - && utfc_ptr2len(oldp + col) >= count) { + && utfc_ptr2len((char *)oldp + col) >= count) { int cc[MAX_MCO]; (void)utfc_ptr2char(oldp + col, cc); @@ -765,7 +765,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine) int n = col; do { col = n; - count = utf_ptr2len(oldp + n); + count = utf_ptr2len((char *)oldp + n); n += count; } while (utf_composinglike(oldp + col, oldp + n)); fixpos = false; @@ -1436,7 +1436,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) int l; for (i = 0; i < lead_len && p[i] != NUL; i += l) { - l = utfc_ptr2len(p + i); + l = utfc_ptr2len((char *)p + i); if (vim_strnsize(p, i + l) > repl_size) { break; } @@ -1459,7 +1459,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) lead_len--; memmove(p, p + 1, (size_t)(leader + lead_len - p)); } else { - int l = utfc_ptr2len(p); + int l = utfc_ptr2len((char *)p); if (l > 1) { if (ptr2cells(p) > 1) { @@ -1565,7 +1565,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } if (curbuf->b_p_ai || (flags & OPENLINE_DELSPACES)) { while ((*p_extra == ' ' || *p_extra == '\t') - && !utf_iscomposing(utf_ptr2char(p_extra + 1))) { + && !utf_iscomposing(utf_ptr2char((char *)p_extra + 1))) { if (REPLACE_NORMAL(State)) { replace_push(*p_extra); } -- cgit From 0a00792332add35c23b7cf96618ea317e7383a11 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Sat, 7 May 2022 16:49:36 +0200 Subject: vim-patch:8.2.4907: some users do not want a line comment always inserted (#18463) Problem: Some users do not want a line comment always inserted. Solution: Add the '/' flag to 'formatoptions' to not repeat the comment leader after a statement when using "o". https://github.com/vim/vim/commit/2bf875f881f7c6f6900bc0eb2a93a552db894109 --- src/nvim/change.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index bbb10d3a52..426310488a 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1186,7 +1186,8 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) end_comment_pending = NUL; if (flags & OPENLINE_DO_COM) { lead_len = get_leader_len(saved_line, &lead_flags, dir == BACKWARD, true); - if (lead_len == 0 && curbuf->b_p_cin && do_cindent && dir == FORWARD) { + if (lead_len == 0 && curbuf->b_p_cin && do_cindent && dir == FORWARD + && !has_format_option(FO_NO_OPEN_COMS)) { // Check for a line comment after code. comment_start = check_linecomment(saved_line); if (comment_start != MAXCOL) { -- cgit From e31b32a293f6ba8708499a176234f8be1df6a145 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Thu, 5 May 2022 13:36:14 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/change.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 426310488a..abc000d236 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -550,7 +550,7 @@ void ins_bytes_len(char_u *p, size_t len) void ins_char(int c) { char_u buf[MB_MAXBYTES + 1]; - size_t n = (size_t)utf_char2bytes(c, buf); + size_t n = (size_t)utf_char2bytes(c, (char *)buf); // When "c" is 0x100, 0x200, etc. we don't want to insert a NUL byte. // Happens for CTRL-Vu9900. @@ -1010,7 +1010,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) && !(State & VREPLACE_FLAG)) { p_extra = saved_line + curwin->w_cursor.col; if (do_si) { // need first char after new line break - p = skipwhite(p_extra); + p = (char_u *)skipwhite((char *)p_extra); first_char = *p; } extra_len = (int)STRLEN(p_extra); @@ -1077,7 +1077,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // */ // #define IN_THE_WAY // This should line up here; - p = skipwhite(ptr); + p = (char_u *)skipwhite((char *)ptr); if (p[0] == '/' && p[1] == '*') { p++; } @@ -1160,7 +1160,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) newindent = get_indent(); } } - p = skipwhite(ptr); + p = (char_u *)skipwhite((char *)ptr); if (*p == '}') { // if line starts with '}': do indent did_si = true; } else { // can delete indent when '{' typed @@ -1296,7 +1296,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // Remember where the end is, might want to use it to find the // start (for C-comments). if (dir == FORWARD) { - comment_end = skipwhite(saved_line); + comment_end = (char_u *)skipwhite((char *)saved_line); lead_len = 0; break; } @@ -1426,7 +1426,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } } } else { // left adjusted leader - p = skipwhite(leader); + p = (char_u *)skipwhite((char *)leader); // Compute the length of the replaced characters in // screen characters, not bytes. Move the part that is // not to be overwritten. @@ -1500,7 +1500,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) while (off > 0 && lead_len > 0 && leader[lead_len - 1] == ' ') { // Don't do it when there is a tab before the space - if (vim_strchr(skipwhite(leader), '\t') != NULL) { + if (vim_strchr((char_u *)skipwhite((char *)leader), '\t') != NULL) { break; } lead_len--; -- cgit From 9aa5647e686e5420e5b9b51828ec7d55631f98ed Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 10 May 2022 07:58:58 +0800 Subject: vim-patch:8.2.4911: the mode #defines are not clearly named (#18499) Problem: The mode #defines are not clearly named. Solution: Prepend MODE_. Renumber them to put the mapped modes first. https://github.com/vim/vim/commit/249591057b4840785c50e41dd850efb8a8faf435 A hunk from the patch depends on patch 8.2.4861, which hasn't been ported yet, but that should be easy to notice. --- src/nvim/change.c | 60 +++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index abc000d236..767e6d3837 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -543,7 +543,7 @@ void ins_bytes_len(char_u *p, size_t len) } /// Insert or replace a single character at the cursor position. -/// When in REPLACE or VREPLACE mode, replace any existing character. +/// When in MODE_REPLACE or MODE_VREPLACE state, replace any existing character. /// Caller must have prepared for undo. /// For multi-byte characters we get the whole character, the caller must /// convert bytes to a character. @@ -652,7 +652,7 @@ void ins_char_bytes(char_u *buf, size_t charlen) // If we're in Insert or Replace mode and 'showmatch' is set, then briefly // show the match for right parens and braces. - if (p_sm && (State & INSERT) + if (p_sm && (State & MODE_INSERT) && msg_silent == 0 && !ins_compl_active()) { showmatch(utf_ptr2char((char *)buf)); @@ -923,10 +923,10 @@ int copy_indent(int size, char_u *src) /// open_line: Add a new line below or above the current line. /// -/// For VREPLACE mode, we only add a new line when we get to the end of the -/// file, otherwise we just start replacing the next line. +/// For MODE_VREPLACE state, we only add a new line when we get to the end of +/// the file, otherwise we just start replacing the next line. /// -/// Caller must take care of undo. Since VREPLACE may affect any number of +/// Caller must take care of undo. Since MODE_VREPLACE may affect any number of /// lines however, it may call u_save_cursor() again when starting to change a /// new line. /// "flags": OPENLINE_DELSPACES delete spaces after cursor @@ -979,7 +979,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) char_u *saved_line = vim_strsave(get_cursor_line_ptr()); if (State & VREPLACE_FLAG) { - // With VREPLACE we make a copy of the next line, which we will be + // With MODE_VREPLACE we make a copy of the next line, which we will be // starting to replace. First make the new line empty and let vim play // with the indenting and comment leader to its heart's content. Then // we grab what it ended up putting on the new line, put back the @@ -992,11 +992,11 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) next_line = vim_strsave((char_u *)""); } - // In VREPLACE mode, a NL replaces the rest of the line, and starts - // replacing the next line, so push all of the characters left on the - // line onto the replace stack. We'll push any other characters that - // might be replaced at the start of the next line (due to autoindent - // etc) a bit later. + // In MODE_VREPLACE state, a NL replaces the rest of the line, and + // starts replacing the next line, so push all of the characters left + // on the line onto the replace stack. We'll push any other characters + // that might be replaced at the start of the next line (due to + // autoindent etc) a bit later. replace_push(NUL); // Call twice because BS over NL expects it replace_push(NUL); p = saved_line + curwin->w_cursor.col; @@ -1006,8 +1006,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) saved_line[curwin->w_cursor.col] = NUL; } - if ((State & INSERT) - && !(State & VREPLACE_FLAG)) { + if ((State & MODE_INSERT) && (State & VREPLACE_FLAG) == 0) { p_extra = saved_line + curwin->w_cursor.col; if (do_si) { // need first char after new line break p = (char_u *)skipwhite((char *)p_extra); @@ -1552,15 +1551,16 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } } - // (State == INSERT || State == REPLACE), only when dir == FORWARD + // (State == MODE_INSERT || State == MODE_REPLACE), only when dir == FORWARD if (p_extra != NULL) { *p_extra = saved_char; // restore char that NUL replaced // When 'ai' set or "flags" has OPENLINE_DELSPACES, skip to the first // non-blank. // - // When in REPLACE mode, put the deleted blanks on the replace stack, - // preceded by a NUL, so they can be put back when a BS is entered. + // When in MODE_REPLACE state, put the deleted blanks on the replace + // stack, preceded by a NUL, so they can be put back when a BS is + // entered. if (REPLACE_NORMAL(State)) { replace_push(NUL); // end of extra blanks } @@ -1612,7 +1612,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) if (dir == BACKWARD) { curwin->w_cursor.lnum--; } - if (!(State & VREPLACE_FLAG) || old_cursor.lnum >= orig_line_count) { + if ((State & VREPLACE_FLAG) == 0 || old_cursor.lnum >= orig_line_count) { if (ml_append(curwin->w_cursor.lnum, (char *)p_extra, (colnr_T)0, false) == FAIL) { goto theend; } @@ -1627,7 +1627,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } did_append = true; } else { - // In VREPLACE mode we are starting to replace the next line. + // In MODE_VREPLACE state we are starting to replace the next line. curwin->w_cursor.lnum++; if (curwin->w_cursor.lnum >= Insstart.lnum + vr_lines_changed) { // In case we NL to a new line, BS to the previous one, and NL @@ -1669,8 +1669,8 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) ai_col = curwin->w_cursor.col; - // In REPLACE mode, for each character in the new indent, there must - // be a NUL on the replace stack, for when it is deleted with BS + // In MODE_REPLACE state, for each character in the new indent, there + // must be a NUL on the replace stack, for when it is deleted with BS if (REPLACE_NORMAL(State)) { for (colnr_T n = 0; n < curwin->w_cursor.col; n++) { replace_push(NUL); @@ -1683,8 +1683,8 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } inhibit_delete_count--; - // In REPLACE mode, for each character in the extra leader, there must be - // a NUL on the replace stack, for when it is deleted with BS. + // In MODE_REPLACE state, for each character in the extra leader, there + // must be a NUL on the replace stack, for when it is deleted with BS. if (REPLACE_NORMAL(State)) { while (lead_len-- > 0) { replace_push(NUL); @@ -1694,7 +1694,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) curwin->w_cursor = old_cursor; if (dir == FORWARD) { - if (trunc_line || (State & INSERT)) { + if (trunc_line || (State & MODE_INSERT)) { // truncate current line at cursor saved_line[curwin->w_cursor.col] = NUL; // Remove trailing white space, unless OPENLINE_KEEPTRAIL used. @@ -1752,12 +1752,12 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) curwin->w_cursor.col = newcol; curwin->w_cursor.coladd = 0; - // In VREPLACE mode, we are handling the replace stack ourselves, so stop - // fixthisline() from doing it (via change_indent()) by telling it we're in - // normal INSERT mode. + // In MODE_VREPLACE state, we are handling the replace stack ourselves, so + // stop fixthisline() from doing it (via change_indent()) by telling it + // we're in normal MODE_INSERT state. if (State & VREPLACE_FLAG) { vreplace_mode = State; // So we know to put things right later - State = INSERT; + State = MODE_INSERT; } else { vreplace_mode = 0; } @@ -1778,9 +1778,9 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) State = vreplace_mode; } - // Finally, VREPLACE gets the stuff on the new line, then puts back the - // original line, and inserts the new stuff char by char, pushing old stuff - // onto the replace stack (via ins_char()). + // Finally, MODE_VREPLACE gets the stuff on the new line, then puts back + // the original line, and inserts the new stuff char by char, pushing old + // stuff onto the replace stack (via ins_char()). if (State & VREPLACE_FLAG) { // Put new line in p_extra p_extra = vim_strsave(get_cursor_line_ptr()); -- cgit From 85aae12a6dea48621ea2d24a946b3e7b86f9014d Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Sun, 8 May 2022 14:43:16 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/change.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 767e6d3837..b15e90e0bc 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -557,7 +557,7 @@ void ins_char(int c) if (buf[0] == 0) { buf[0] = '\n'; } - ins_char_bytes(buf, n); + ins_char_bytes((char_u *)buf, n); } void ins_char_bytes(char_u *buf, size_t charlen) -- cgit From 24eb1af4754b3061d0968112342ca5389b68d4f6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 14 May 2022 18:55:50 +0800 Subject: vim-patch:8.2.4951: smart indenting done when not enabled Problem: Smart indenting done when not enabled. Solution: Check option values before setting can_si. (closes vim/vim#10420) https://github.com/vim/vim/commit/de5cf287812510d2c8ffe66b99cf33c4e1a6e6f1 --- src/nvim/change.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index b15e90e0bc..091e9b2830 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -963,8 +963,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) char_u *p; char_u saved_char = NUL; // init for GCC pos_T *pos; - bool do_si = (!p_paste && curbuf->b_p_si && !curbuf->b_p_cin - && *curbuf->b_p_inde == NUL); + bool do_si = may_do_si(); bool do_cindent; bool no_si = false; // reset did_si afterwards int first_char = NUL; // init for GCC -- cgit From f0148de7907ec297647816d51c79745be729439e Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Mon, 9 May 2022 11:49:32 +0200 Subject: refactor: replace char_u variables and functions with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/change.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 091e9b2830..a21665dc23 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1498,7 +1498,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) while (off > 0 && lead_len > 0 && leader[lead_len - 1] == ' ') { // Don't do it when there is a tab before the space - if (vim_strchr((char_u *)skipwhite((char *)leader), '\t') != NULL) { + if (vim_strchr(skipwhite((char *)leader), '\t') != NULL) { break; } lead_len--; @@ -1878,7 +1878,7 @@ int get_leader_len(char_u *line, char_u **flags, bool backward, bool include_spa { int j; int got_com = false; - char_u part_buf[COM_MAX_LEN]; // buffer for one option part + char part_buf[COM_MAX_LEN]; // buffer for one option part char_u *string; // pointer to comment string char_u *list; int middle_match_len = 0; @@ -1902,8 +1902,8 @@ int get_leader_len(char_u *line, char_u **flags, bool backward, bool include_spa *flags = list; // remember where flags started } prev_list = list; - (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ","); - string = vim_strchr(part_buf, ':'); + (void)copy_option_part(&list, (char_u *)part_buf, COM_MAX_LEN, ","); + string = (char_u *)vim_strchr(part_buf, ':'); if (string == NULL) { // missing ':', ignore this part continue; } @@ -2025,7 +2025,7 @@ int get_last_leader_offset(char_u *line, char_u **flags) char_u *com_leader; char_u *com_flags; char_u *list; - char_u part_buf[COM_MAX_LEN]; // buffer for one option part + char part_buf[COM_MAX_LEN]; // buffer for one option part // Repeat to match several nested comment strings. int i = (int)STRLEN(line); @@ -2037,8 +2037,8 @@ int get_last_leader_offset(char_u *line, char_u **flags) // Get one option part into part_buf[]. Advance list to next one. // put string at start of string. - (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ","); - string = vim_strchr(part_buf, ':'); + (void)copy_option_part(&list, (char_u *)part_buf, COM_MAX_LEN, ","); + string = (char_u *)vim_strchr(part_buf, ':'); if (string == NULL) { // If everything is fine, this cannot actually // happen. continue; @@ -2096,7 +2096,7 @@ int get_last_leader_offset(char_u *line, char_u **flags) } if (found_one) { - char_u part_buf2[COM_MAX_LEN]; // buffer for one option part + char part_buf2[COM_MAX_LEN]; // buffer for one option part int len1, len2, off; result = i; @@ -2120,11 +2120,11 @@ int get_last_leader_offset(char_u *line, char_u **flags) for (list = curbuf->b_p_com; *list;) { char_u *flags_save = list; - (void)copy_option_part(&list, part_buf2, COM_MAX_LEN, ","); + (void)copy_option_part(&list, (char_u *)part_buf2, COM_MAX_LEN, ","); if (flags_save == com_flags) { continue; } - string = vim_strchr(part_buf2, ':'); + string = (char_u *)vim_strchr(part_buf2, ':'); string++; while (ascii_iswhite(*string)) { string++; -- cgit From 527e861cbb9c47411c4ba86dbdb9fc79bde47452 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 17 May 2022 08:10:34 +0800 Subject: vim-patch:8.2.4969: changing text in Visual mode may cause invalid memory access Problem: Changing text in Visual mode may cause invalid memory access. Solution: Check the Visual position after making a change. https://github.com/vim/vim/commit/7ce5b2b590256ce53d6af28c1d203fb3bc1d2d97 --- src/nvim/change.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index a21665dc23..94e5a19edc 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -209,6 +209,10 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra curwin->w_changelistidx = curbuf->b_changelistlen; } + if (VIsual_active) { + check_visual_pos(); + } + FOR_ALL_TAB_WINDOWS(tp, wp) { if (wp->w_buffer == curbuf) { // Mark this window to be redrawn later. -- cgit From 5193b17839c6524bb72ca35cbfc477c4ddd8ef13 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 22 May 2022 07:52:11 +0800 Subject: vim-patch:8.2.4993: smart/C/lisp indenting is optional (#18684) Problem: smart/C/lisp indenting is optional, which makes the code more complex, while it only reduces the executable size a bit. Solution: Graduate FEAT_CINDENT, FEAT_SMARTINDENT and FEAT_LISP. https://github.com/vim/vim/commit/8e145b82464a21ee4fdf7948f04e2a1d505f8bfa --- src/nvim/change.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 94e5a19edc..349f74e280 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1033,8 +1033,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // If 'autoindent' and/or 'smartindent' is set, try to figure out what // indent to use for the new line. - if (curbuf->b_p_ai - || do_si) { + if (curbuf->b_p_ai || do_si) { // count white space on current line newindent = get_indent_str_vtab(saved_line, curbuf->b_p_ts, @@ -1482,8 +1481,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } // Recompute the indent, it may have changed. - if (curbuf->b_p_ai - || do_si) { + if (curbuf->b_p_ai || do_si) { newindent = get_indent_str_vtab(leader, curbuf->b_p_ts, curbuf->b_p_vts_array, false); @@ -1526,15 +1524,13 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // if a new indent will be set below, remove the indent that // is in the comment leader - if (newindent - || did_si) { + if (newindent || did_si) { while (lead_len && ascii_iswhite(*leader)) { lead_len--; newcol--; leader++; } } - did_si = can_si = false; } else if (comment_end != NULL) { // We have finished a comment, so we don't use the leader. @@ -1646,8 +1642,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } inhibit_delete_count++; - if (newindent - || did_si) { + if (newindent || did_si) { curwin->w_cursor.lnum++; if (did_si) { int sw = get_sw_value(curbuf); @@ -1764,6 +1759,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } else { vreplace_mode = 0; } + // May do lisp indenting. if (!p_paste && leader == NULL @@ -1772,11 +1768,13 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) fixthisline(get_lisp_indent); ai_col = (colnr_T)getwhitecols_curline(); } + // May do indenting after opening a new line. if (do_cindent) { do_c_expr_indent(); ai_col = (colnr_T)getwhitecols_curline(); } + if (vreplace_mode != 0) { State = vreplace_mode; } -- cgit From 4b4643be07e4e9259b3cb05e511e5047778733c1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 23 May 2022 21:27:57 +0800 Subject: vim-patch:8.2.5008: when 'formatoptions' contains "/" wrongly wrapping comment (#18717) Problem: When 'formatoptions' contains "/" wrongly wrapping a long trailing comment. Solution: Pass the OPENLINE_FORMAT flag. https://github.com/vim/vim/commit/7e667788150be617aeac42b0d668618ac33ab9da --- src/nvim/change.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 349f74e280..c1fe5bc405 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1188,7 +1188,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) if (flags & OPENLINE_DO_COM) { lead_len = get_leader_len(saved_line, &lead_flags, dir == BACKWARD, true); if (lead_len == 0 && curbuf->b_p_cin && do_cindent && dir == FORWARD - && !has_format_option(FO_NO_OPEN_COMS)) { + && (!has_format_option(FO_NO_OPEN_COMS) || (flags & OPENLINE_FORMAT))) { // Check for a line comment after code. comment_start = check_linecomment(saved_line); if (comment_start != MAXCOL) { -- cgit From 9fec6dc9a25b5cf9c9a444ac2bd0728e8af3229e Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 25 May 2022 20:31:14 +0200 Subject: refactor(uncrustify): set maximum number of consecutive newlines to 2 (#18695) --- src/nvim/change.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index c1fe5bc405..9fd5083fd3 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -615,7 +615,6 @@ void ins_char_bytes(char_u *buf, size_t charlen) oldlen = (size_t)utfc_ptr2len((char *)oldp + col); } - // Push the replaced bytes onto the replace stack, so that they can be // put back when BS is used. The bytes of a multi-byte character are // done the other way around, so that the first byte is popped off -- cgit From 46536f53e82967dcac8d030ee3394cdb156f9603 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Wed, 20 Apr 2022 17:02:18 +0600 Subject: feat: add preview functionality to user commands Adds a Lua-only `preview` flag to user commands which allows the command to be incrementally previewed like `:substitute` when 'inccommand' is set. --- src/nvim/change.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 9fd5083fd3..fa1de69e2c 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -351,7 +351,7 @@ void changed_bytes(linenr_T lnum, colnr_T col) changedOneline(curbuf, lnum); changed_common(lnum, col, lnum + 1, 0L); // notify any channels that are watching - buf_updates_send_changes(curbuf, lnum, 1, 1, true); + buf_updates_send_changes(curbuf, lnum, 1, 1); // Diff highlighting in other diff windows may need to be updated too. if (curwin->w_p_diff) { @@ -501,7 +501,7 @@ void changed_lines(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra, bool d if (do_buf_event) { int64_t num_added = (int64_t)(lnume + xtra - lnum); int64_t num_removed = lnume - lnum; - buf_updates_send_changes(curbuf, lnum, num_added, num_removed, true); + buf_updates_send_changes(curbuf, lnum, num_added, num_removed); } } -- cgit From a732c253b71f89702285d5ec6fd7803045f6add9 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Sat, 7 May 2022 12:53:37 +0200 Subject: refactor: change type of linenr_T from long to int32_t The size of long varies depending on architecture, in contrast to the MAXLNUM constant which sets the maximum allowable number of lines to 2^32-1. This discrepancy may lead to hard to detect bugs, for example https://github.com/neovim/neovim/issues/18454. Setting linenr_T to a fix maximum size of 2^32-1 will prevent this type of errors in the future. Also change the variables `amount` and `amount_after` to be linenr_T since they're referring to "the line number difference" between two texts. --- src/nvim/change.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index fa1de69e2c..21afbf66de 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -138,7 +138,7 @@ void changed_internal(void) /// Common code for when a change was made. /// See changed_lines() for the arguments. /// Careful: may trigger autocommands that reload the buffer. -static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra) +static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T xtra) { // mark the buffer as modified changed(); @@ -349,7 +349,7 @@ static void changedOneline(buf_T *buf, linenr_T lnum) void changed_bytes(linenr_T lnum, colnr_T col) { changedOneline(curbuf, lnum); - changed_common(lnum, col, lnum + 1, 0L); + changed_common(lnum, col, lnum + 1, 0); // notify any channels that are watching buf_updates_send_changes(curbuf, lnum, 1, 1); @@ -382,7 +382,7 @@ void inserted_bytes(linenr_T lnum, colnr_T col, int old, int new) /// Appended "count" lines below line "lnum" in the current buffer. /// Must be called AFTER the change and after mark_adjust(). /// Takes care of marking the buffer to be redrawn and sets the changed flag. -void appended_lines(linenr_T lnum, long count) +void appended_lines(linenr_T lnum, linenr_T count) { changed_lines(lnum + 1, 0, lnum + 1, count, true); } @@ -393,18 +393,18 @@ void appended_lines_mark(linenr_T lnum, long count) // Skip mark_adjust when adding a line after the last one, there can't // be marks there. But it's still needed in diff mode. if (lnum + count < curbuf->b_ml.ml_line_count || curwin->w_p_diff) { - mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L, kExtmarkUndo); + mark_adjust(lnum + 1, (linenr_T)MAXLNUM, (linenr_T)count, 0L, kExtmarkUndo); } else { - extmark_adjust(curbuf, lnum + 1, (linenr_T)MAXLNUM, count, 0L, + extmark_adjust(curbuf, lnum + 1, (linenr_T)MAXLNUM, (linenr_T)count, 0L, kExtmarkUndo); } - changed_lines(lnum + 1, 0, lnum + 1, count, true); + changed_lines(lnum + 1, 0, lnum + 1, (linenr_T)count, true); } /// Deleted "count" lines at line "lnum" in the current buffer. /// Must be called AFTER the change and after mark_adjust(). /// Takes care of marking the buffer to be redrawn and sets the changed flag. -void deleted_lines(linenr_T lnum, long count) +void deleted_lines(linenr_T lnum, linenr_T count) { changed_lines(lnum, 0, lnum + count, -count, true); } @@ -418,9 +418,9 @@ void deleted_lines_mark(linenr_T lnum, long count) bool made_empty = (count > 0) && curbuf->b_ml.ml_flags & ML_EMPTY; mark_adjust(lnum, (linenr_T)(lnum + count - 1), (long)MAXLNUM, - -count + (made_empty?1:0), + -(linenr_T)count + (made_empty?1:0), kExtmarkUndo); - changed_lines(lnum, 0, lnum + count, -count, true); + changed_lines(lnum, 0, lnum + (linenr_T)count, (linenr_T)(-count), true); } /// Marks the area to be redrawn after a change. @@ -429,7 +429,7 @@ void deleted_lines_mark(linenr_T lnum, long count) /// @param lnum first line with change /// @param lnume line below last changed line /// @param xtra number of extra lines (negative when deleting) -void changed_lines_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, long xtra) +void changed_lines_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, linenr_T xtra) { if (buf->b_mod_set) { // find the maximum area that must be redisplayed @@ -474,7 +474,7 @@ void changed_lines_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, long xtra) /// @param do_buf_event some callers like undo/redo call changed_lines() and /// then increment changedtick *again*. This flag allows these callers to send /// the nvim_buf_lines_event events after they're done modifying changedtick. -void changed_lines(linenr_T lnum, colnr_T col, linenr_T lnume, long xtra, bool do_buf_event) +void changed_lines(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T xtra, bool do_buf_event) { changed_lines_buf(curbuf, lnum, lnume, xtra); -- cgit From 6130b4a84b41b71f4c0c58093a29585c6c67ff16 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 13 Jun 2022 20:20:34 +0800 Subject: vim-patch:8.2.1898: command modifier parsing always uses global cmdmod Problem: Command modifier parsing always uses global cmdmod. Solution: Pass in cmdmod_T to use. Rename struct fields consistently. https://github.com/vim/vim/commit/e10044015841711b989f9a898d427bcc1fdb4c32 --- src/nvim/change.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 21afbf66de..c0796386f1 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -148,7 +148,7 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T } // set the '. mark - if (!cmdmod.keepjumps) { + if ((cmdmod.cmod_flags & CMOD_KEEPJUMPS) == 0) { RESET_FMARK(&curbuf->b_last_change, ((pos_T) { lnum, col, 0 }), 0); // Create a new entry if a new undo-able change was started or we -- cgit From 014a88799a1d175ad121c520c9cc5bd0bb2d8813 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 28 Jun 2022 11:31:54 +0200 Subject: refactor: replace char_u #18429 Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/change.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index c0796386f1..a383fe6bb3 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1393,7 +1393,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) while (old_size < repl_size && p > leader) { MB_PTR_BACK(leader, p); - old_size += ptr2cells(p); + old_size += ptr2cells((char *)p); } l = lead_repl_len - (int)(endp - p); if (l != 0) { @@ -1413,7 +1413,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) if (l > 1) { p -= l; - if (ptr2cells(p) > 1) { + if (ptr2cells((char *)p) > 1) { p[1] = ' '; l--; } @@ -1463,7 +1463,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) int l = utfc_ptr2len((char *)p); if (l > 1) { - if (ptr2cells(p) > 1) { + if (ptr2cells((char *)p) > 1) { // Replace a double-wide char with // two spaces l--; -- cgit From 565f72b9689e0c440ff72c712a090224aaf7631b Mon Sep 17 00:00:00 2001 From: Javier Lopez Date: Thu, 30 Jun 2022 07:59:52 -0500 Subject: feat(marks): restore viewport on jump #15831 ** Refactor Previously most functions used to "get" a mark returned a position, changed the line number and sometimes changed even the current buffer. Now functions return a {x}fmark_T making calling context aware whether the mark is in another buffer without arcane casting. A new function is provided for switching to the mark buffer and returning a flag style Enum to convey what happen in the movement. If the cursor changed, line, columns, if it changed buffer, etc. The function to get named mark was split into multiple functions. - mark_get() -> fmark_T - mark_get_global() -> xfmark_T - mark_get_local() -> fmark_T - mark_get_motion() -> fmark_T - mark_get_visual() -> fmark_T Functions that manage the changelist and jumplist were also modified to return mark types. - get_jumplist -> fmark_T - get_changelist -> fmark_T The refactor is also seen mainly on normal.c, where all the mark movement has been siphoned through one function nv_gomark, while the other functions handle getting the mark and setting their movement flags. To handle whether context marks should be left, etc. ** Mark View While doing the refactor the concept of a mark view was also implemented: The view of a mark currently implemented as the number of lines between the mark position on creation and the window topline. This allows for moving not only back to the position of a mark but having the window look similar to when the mark was defined. This is done by carrying and extra element in the fmark_T struct, which can be extended later to also restore horizontal shift. *** User space features 1. There's a new option, jumpoptions+=view enables the mark view restoring automatically when using the jumplist, changelist, alternate-file and mark motions. g; g, '[mark] `[mark] ** Limitations - The view information is not saved in shada. - Calls to get_mark should copy the value in the pointer since we are using pos_to_mark() to wrap and provide a homogeneous interfaces. This was also a limitation in the previous state of things. --- src/nvim/change.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index a383fe6bb3..f1273c802e 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -149,7 +149,13 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T // set the '. mark if ((cmdmod.cmod_flags & CMOD_KEEPJUMPS) == 0) { - RESET_FMARK(&curbuf->b_last_change, ((pos_T) { lnum, col, 0 }), 0); + fmarkv_T view = INIT_FMARKV; + // Set the markview only if lnum is visible, as changes might be done + // outside of the current window view. + if (lnum >= curwin->w_topline && lnum <= curwin->w_botline) { + view = mark_view_make(curwin->w_topline, curwin->w_cursor); + } + RESET_FMARK(&curbuf->b_last_change, ((pos_T) { lnum, col, 0 }), curbuf->handle, view); // Create a new entry if a new undo-able change was started or we // don't have an entry yet. -- cgit From 3b8804571c565a91c9ce729bb487c7ba21b659e0 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Tue, 28 Jun 2022 13:03:09 +0200 Subject: refactor: replace char_u Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/change.c | 60 +++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index f1273c802e..4568b71fd9 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1059,7 +1059,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) old_cursor = curwin->w_cursor; ptr = saved_line; if (flags & OPENLINE_DO_COM) { - lead_len = get_leader_len(ptr, NULL, false, true); + lead_len = get_leader_len((char *)ptr, NULL, false, true); } else { lead_len = 0; } @@ -1072,7 +1072,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) newindent = get_indent(); } if (flags & OPENLINE_DO_COM) { - lead_len = get_leader_len(ptr, NULL, false, true); + lead_len = get_leader_len((char *)ptr, NULL, false, true); } else { lead_len = 0; } @@ -1191,14 +1191,14 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // This may then be inserted in front of the new line. end_comment_pending = NUL; if (flags & OPENLINE_DO_COM) { - lead_len = get_leader_len(saved_line, &lead_flags, dir == BACKWARD, true); + lead_len = get_leader_len((char *)saved_line, (char **)&lead_flags, dir == BACKWARD, true); if (lead_len == 0 && curbuf->b_p_cin && do_cindent && dir == FORWARD && (!has_format_option(FO_NO_OPEN_COMS) || (flags & OPENLINE_FORMAT))) { // Check for a line comment after code. comment_start = check_linecomment(saved_line); if (comment_start != MAXCOL) { - lead_len = get_leader_len(saved_line + comment_start, - &lead_flags, false, true); + lead_len = get_leader_len((char *)saved_line + comment_start, + (char **)&lead_flags, false, true); if (lead_len != 0) { lead_len += comment_start; if (did_do_comment != NULL) { @@ -1238,7 +1238,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } // find start of middle part - (void)copy_option_part(&p, lead_middle, COM_MAX_LEN, ","); + (void)copy_option_part((char **)&p, (char *)lead_middle, COM_MAX_LEN, ","); require_blank = false; } @@ -1249,7 +1249,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } p++; } - (void)copy_option_part(&p, lead_middle, COM_MAX_LEN, ","); + (void)copy_option_part((char **)&p, (char *)lead_middle, COM_MAX_LEN, ","); while (*p && p[-1] != ':') { // find end of end flags // Check whether we allow automatic ending of comments @@ -1258,7 +1258,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } p++; } - size_t n = copy_option_part(&p, lead_end, COM_MAX_LEN, ","); + size_t n = copy_option_part((char **)&p, (char *)lead_end, COM_MAX_LEN, ","); if (end_comment_pending == -1) { // we can set it now end_comment_pending = lead_end[n - 1]; @@ -1377,7 +1377,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) if (*p == COM_RIGHT || *p == COM_LEFT) { c = *p++; } else if (ascii_isdigit(*p) || *p == '-') { - off = getdigits_int(&p, true, 0); + off = getdigits_int((char **)&p, true, 0); } else { p++; } @@ -1881,16 +1881,16 @@ void del_lines(long nlines, bool undo) /// When "flags" is not NULL, it is set to point to the flags of the recognized comment leader. /// "backward" must be true for the "O" command. /// If "include_space" is set, include trailing whitespace while calculating the length. -int get_leader_len(char_u *line, char_u **flags, bool backward, bool include_space) +int get_leader_len(char *line, char **flags, bool backward, bool include_space) { int j; int got_com = false; char part_buf[COM_MAX_LEN]; // buffer for one option part - char_u *string; // pointer to comment string - char_u *list; + char *string; // pointer to comment string + char *list; int middle_match_len = 0; - char_u *prev_list; - char_u *saved_flags = NULL; + char *prev_list; + char *saved_flags = NULL; int result = 0; int i = 0; @@ -1902,15 +1902,15 @@ int get_leader_len(char_u *line, char_u **flags, bool backward, bool include_spa while (line[i] != NUL) { // scan through the 'comments' option for a match int found_one = false; - for (list = curbuf->b_p_com; *list;) { + for (list = (char *)curbuf->b_p_com; *list;) { // Get one option part into part_buf[]. Advance "list" to next // one. Put "string" at start of string. if (!got_com && flags != NULL) { *flags = list; // remember where flags started } prev_list = list; - (void)copy_option_part(&list, (char_u *)part_buf, COM_MAX_LEN, ","); - string = (char_u *)vim_strchr(part_buf, ':'); + (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ","); + string = vim_strchr(part_buf, ':'); if (string == NULL) { // missing ':', ignore this part continue; } @@ -2023,15 +2023,15 @@ int get_leader_len(char_u *line, char_u **flags, bool backward, bool include_spa /// /// When "flags" is not null, it is set to point to the flags describing the /// recognized comment leader. -int get_last_leader_offset(char_u *line, char_u **flags) +int get_last_leader_offset(char *line, char **flags) { int result = -1; int j; int lower_check_bound = 0; - char_u *string; - char_u *com_leader; - char_u *com_flags; - char_u *list; + char *string; + char *com_leader; + char *com_flags; + char *list; char part_buf[COM_MAX_LEN]; // buffer for one option part // Repeat to match several nested comment strings. @@ -2039,13 +2039,13 @@ int get_last_leader_offset(char_u *line, char_u **flags) while (--i >= lower_check_bound) { // scan through the 'comments' option for a match int found_one = false; - for (list = curbuf->b_p_com; *list;) { - char_u *flags_save = list; + for (list = (char *)curbuf->b_p_com; *list;) { + char *flags_save = list; // Get one option part into part_buf[]. Advance list to next one. // put string at start of string. - (void)copy_option_part(&list, (char_u *)part_buf, COM_MAX_LEN, ","); - string = (char_u *)vim_strchr(part_buf, ':'); + (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ","); + string = vim_strchr(part_buf, ':'); if (string == NULL) { // If everything is fine, this cannot actually // happen. continue; @@ -2124,14 +2124,14 @@ int get_last_leader_offset(char_u *line, char_u **flags) } len1 = (int)STRLEN(com_leader); - for (list = curbuf->b_p_com; *list;) { - char_u *flags_save = list; + for (list = (char *)curbuf->b_p_com; *list;) { + char *flags_save = list; - (void)copy_option_part(&list, (char_u *)part_buf2, COM_MAX_LEN, ","); + (void)copy_option_part(&list, part_buf2, COM_MAX_LEN, ","); if (flags_save == com_flags) { continue; } - string = (char_u *)vim_strchr(part_buf2, ':'); + string = vim_strchr(part_buf2, ':'); string++; while (ascii_iswhite(*string)) { string++; -- cgit