From 5c4b503d3cb4a48d083bcf50d4932927e6eb749d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 5 Feb 2023 09:37:12 +0800 Subject: vim-patch:9.0.1279: display shows lines scrolled down erroneously (#22126) Problem: Display shows lines scrolled down erroneously. (Yishai Lerner) Solution: Do not change "wl_lnum" at index zero. (closes vim/vim#11938) https://github.com/vim/vim/commit/61fdbfa1e3c842252b701aec12f45839ca41ece5 Co-authored-by: Bram Moolenaar --- src/nvim/change.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 06696610b0..1bd7ea3a5a 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -296,7 +296,9 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T 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) { + // Do not change wl_lnum at index zero, it is used to + // compare with w_topline. Invalidate it instead. + if (wp->w_lines[i].wl_lnum < lnume || i == 0) { // line included in change wp->w_lines[i].wl_valid = false; } else if (xtra != 0) { -- cgit From 0a897f89c52b92cb518dae1c92de22ca1d170d2a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 4 Mar 2023 10:25:18 +0800 Subject: vim-patch:partial:9.0.0013: reproducing memory access errors can be difficult Problem: Reproducing memory access errors can be difficult. Solution: When testing, copy each line to allocated memory, so that valgrind can detect accessing memory before and/or after it. Fix uncovered problems. https://github.com/vim/vim/commit/fa4873ccfc10e0f278dc46f39d00136fab059b19 Since test_override() is N/A, enable ml_get_alloc_lines when ASAN is enabled instead, so it also applies to functional tests. Use xstrdup() to copy the line as ml_line_len looks hard to port. Squash the test changes from patch 9.0.0016. Co-authored-by: Bram Moolenaar --- src/nvim/change.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 1bd7ea3a5a..7c8f62015d 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1162,12 +1162,16 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) if (p[0] == '/' && p[-1] == '*') { // End of C comment, indent should line up // with the line containing the start of - // the comment + // the comment. curwin->w_cursor.col = (colnr_T)(p - ptr); if ((pos = findmatch(NULL, NUL)) != NULL) { curwin->w_cursor.lnum = pos->lnum; newindent = get_indent(); + break; } + // this may make "ptr" invalid, get it again + ptr = ml_get(curwin->w_cursor.lnum); + p = ptr + curwin->w_cursor.col; } } } -- 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/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 7c8f62015d..04eadfa269 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -42,7 +42,6 @@ #include "nvim/os/time.h" #include "nvim/plines.h" #include "nvim/pos.h" -#include "nvim/screen.h" #include "nvim/search.h" #include "nvim/state.h" #include "nvim/strings.h" -- cgit From eb3fcf652bbcab01cd6d55a0e2c120c09cbe69d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 17 Mar 2023 21:19:34 +0800 Subject: vim-patch:9.0.0194: cursor displayed in wrong position after removing text prop (#22706) Problem: Cursor displayed in wrong position after removing text prop. (Ben Jackson) Solution: Invalidate the cursor position. (closes vim/vim#10898) https://github.com/vim/vim/commit/326c5d36e7cb8526330565109c17b4a13ff790ae Co-authored-by: Bram Moolenaar --- src/nvim/change.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 04eadfa269..1500aded0c 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -446,6 +446,7 @@ void deleted_lines_mark(linenr_T lnum, long count) } /// Marks the area to be redrawn after a change. +/// Consider also calling changed_line_display_buf(). /// /// @param buf the buffer where lines were changed /// @param lnum first line with change -- cgit From 7190dba017e3aac0409c73ff1c954d18858cb3c9 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Thu, 6 Apr 2023 22:39:50 +0200 Subject: refactor: remove use of reserved c++ keywords libnvim couldn't be easily used in C++ due to the use of reserved keywords. Additionally, add explicit casts to *alloc function calls used in inline functions, as C++ doesn't allow implicit casts from void pointers. --- 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 1500aded0c..34121473ca 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -399,13 +399,13 @@ void changed_bytes(linenr_T lnum, colnr_T col) /// insert/delete bytes at column /// /// Like changed_bytes() but also adjust extmark for "new" bytes. -void inserted_bytes(linenr_T lnum, colnr_T col, int old, int new) +void inserted_bytes(linenr_T lnum, colnr_T start_col, int old_col, int new_col) { if (curbuf_splice_pending == 0) { - extmark_splice_cols(curbuf, (int)lnum - 1, col, old, new, kExtmarkUndo); + extmark_splice_cols(curbuf, (int)lnum - 1, start_col, old_col, new_col, kExtmarkUndo); } - changed_bytes(lnum, col); + changed_bytes(lnum, start_col); } /// Appended "count" lines below line "lnum" in the current buffer. -- cgit From 04933b1ea968f958d2541dd65fd33ebb503caac3 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:08:16 +0200 Subject: refactor: remove redundant casts --- src/nvim/change.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 34121473ca..493207d9d5 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1311,7 +1311,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, (char *)lead_middle, COM_MAX_LEN, ","); + (void)copy_option_part(&p, lead_middle, COM_MAX_LEN, ","); require_blank = false; } @@ -1322,7 +1322,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } p++; } - (void)copy_option_part(&p, (char *)lead_middle, COM_MAX_LEN, ","); + (void)copy_option_part(&p, lead_middle, COM_MAX_LEN, ","); while (*p && p[-1] != ':') { // find end of end flags // Check whether we allow automatic ending of comments @@ -1331,7 +1331,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } p++; } - size_t n = copy_option_part(&p, (char *)lead_end, COM_MAX_LEN, ","); + size_t n = copy_option_part(&p, lead_end, COM_MAX_LEN, ","); if (end_comment_pending == -1) { // we can set it now end_comment_pending = (unsigned char)lead_end[n - 1]; @@ -1352,7 +1352,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // Doing "o" on a start of comment inserts the middle leader. if (lead_len > 0) { if (current_flag == COM_START) { - lead_repl = (char *)lead_middle; + lead_repl = lead_middle; lead_repl_len = (int)strlen(lead_middle); } -- 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/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 493207d9d5..6fd32d9113 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -711,8 +711,7 @@ void ins_char_bytes(char *buf, size_t charlen) // Copy bytes after the changed character(s). char *p = newp + col; if (linelen > col + oldlen) { - memmove(p + newlen, oldp + col + oldlen, - (size_t)(linelen - col - oldlen)); + memmove(p + newlen, oldp + col + oldlen, linelen - col - oldlen); } // Insert or overwrite the new character. -- 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/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 6fd32d9113..1d6869990e 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -950,7 +950,7 @@ int copy_indent(int size, char *src) // Add tabs required for indent. if (!curbuf->b_p_et) { - for (;;) { + while (true) { tab_pad = tabstop_padding(ind_col, curbuf->b_p_ts, curbuf->b_p_vts_array); -- cgit From 6f41eaa2b5abd5c252428ba278a9fcc356e48c1d Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 11 May 2023 20:37:49 +0200 Subject: vim-patch:9.0.1543: display errors when making topline shorter Problem: Display errors when making topline shorter and 'smoothscroll' is set. Solution: Reset w_skipcol when the topline becomes shorter than its current value. (Luuk van Baal, closes vim/vim#12367) https://github.com/vim/vim/commit/5d01f86d99bc3a3fd92d4f4e9338a9e78e9ebe16 --- src/nvim/change.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 1d6869990e..a9e7126afc 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -247,11 +247,24 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T wp->w_redr_type = UPD_VALID; } + linenr_T last = lnume + xtra - 1; // last line after the change + + // Reset "w_skipcol" if the topline length has become smaller to + // such a degree that nothing will be visible anymore, accounting + // for 'smoothscroll' <<< or 'listchars' "precedes" marker. + if (wp->w_skipcol > 0 + && (last < wp->w_topline + || (wp->w_topline >= lnum + && wp->w_topline < lnume + && win_linetabsize(wp, wp->w_topline, ml_get(wp->w_topline), (colnr_T)MAXCOL) + <= (unsigned)wp->w_skipcol + (wp->w_p_list && wp->w_p_lcs_chars.prec ? 1 : 3)))) { + wp->w_skipcol = 0; + } + // Check if a change in the buffer has invalidated the cached // 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". - 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 -- cgit From edfa8d6f2f2bc87f3d98b26ef3f8afbfdc8c5bde Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Sun, 14 May 2023 00:03:03 +0200 Subject: vim-patch:9.0.1551: position of marker for 'smoothscroll' not computed correctly (#23617) Problem: Position of marker for 'smoothscroll' not computed correctly. Solution: Take 'list' and other options into account. (Luuk van Baal, closes vim/vim#12393) https://github.com/vim/vim/commit/24b62ec8258cc7c9ca2c09f645f7f6b02584c892 --- 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 a9e7126afc..f4969d0ca9 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -257,7 +257,8 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T || (wp->w_topline >= lnum && wp->w_topline < lnume && win_linetabsize(wp, wp->w_topline, ml_get(wp->w_topline), (colnr_T)MAXCOL) - <= (unsigned)wp->w_skipcol + (wp->w_p_list && wp->w_p_lcs_chars.prec ? 1 : 3)))) { + <= (unsigned)(wp->w_skipcol + sms_marker_overlap(wp, win_col_off(wp) + - win_col_off2(wp)))))) { wp->w_skipcol = 0; } -- cgit From d2dc7cfa5b930a1ff68426f3d47809508ac7d392 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Wed, 24 May 2023 20:26:03 +0200 Subject: vim-patch:9.0.0608: with spelling, deleting a full stop does not update next line Problem: With spell checking, deleting a full stop at the end of a line does not update SpellCap at the start of the next line. Solution: Update the next line when characters have been deleted. Also when using undo. https://github.com/vim/vim/commit/26f09ea54b2c60abf21df42c60bdfc60eca17b0d Co-authored-by: Bram Moolenaar --- src/nvim/change.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index f4969d0ca9..ebbb0d4db6 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -43,6 +43,7 @@ #include "nvim/plines.h" #include "nvim/pos.h" #include "nvim/search.h" +#include "nvim/spell.h" #include "nvim/state.h" #include "nvim/strings.h" #include "nvim/textformat.h" @@ -393,6 +394,12 @@ void changed_bytes(linenr_T lnum, colnr_T col) { changedOneline(curbuf, lnum); changed_common(lnum, col, lnum + 1, 0); + // When text has been changed at the end of the line, possibly the start of + // the next line may have SpellCap that should be removed or it needs to be + // displayed. Schedule the next line for redrawing just in case. + if (spell_check_window(curwin) && lnum < curbuf->b_ml.ml_line_count) { + redrawWinline(curwin, lnum + 1); + } // notify any channels that are watching buf_updates_send_changes(curbuf, lnum, 1, 1); -- cgit From 50efdd6ccf1891392c048b92da5e5d123a30ff26 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Wed, 24 May 2023 20:41:58 +0200 Subject: vim-patch:9.0.0664: bad redrawing with spell checking, using "C" and "$" in 'cpo' Problem: Bad redrawing with spell checking, using "C" and "$" in 'cpo'. Solution: Do not redraw the next line when "$" is in 'cpo'. (closes vim/vim#11285) https://github.com/vim/vim/commit/f3ef026c9897f1d2e3fba47166a4771d507dae91 Co-authored-by: Bram Moolenaar --- src/nvim/change.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index ebbb0d4db6..9e1767c2f3 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -397,7 +397,10 @@ void changed_bytes(linenr_T lnum, colnr_T col) // When text has been changed at the end of the line, possibly the start of // the next line may have SpellCap that should be removed or it needs to be // displayed. Schedule the next line for redrawing just in case. - if (spell_check_window(curwin) && lnum < curbuf->b_ml.ml_line_count) { + // Don't do this when displaying '$' at the end of changed text. + if (spell_check_window(curwin) + && lnum < curbuf->b_ml.ml_line_count + && vim_strchr(p_cpo, CPO_DOLLAR) == NULL) { redrawWinline(curwin, lnum + 1); } // notify any channels that are watching -- 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/change.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 9e1767c2f3..932de727b5 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -441,7 +441,7 @@ void appended_lines(linenr_T lnum, linenr_T count) } /// Like appended_lines(), but adjust marks first. -void appended_lines_mark(linenr_T lnum, long count) +void appended_lines_mark(linenr_T lnum, int count) { mark_adjust(lnum + 1, (linenr_T)MAXLNUM, (linenr_T)count, 0L, kExtmarkUndo); changed_lines(lnum + 1, 0, lnum + 1, (linenr_T)count, true); @@ -458,7 +458,7 @@ void deleted_lines(linenr_T lnum, linenr_T count) /// Like deleted_lines(), but adjust marks first. /// Make sure the cursor is on a valid line before calling, a GUI callback may /// be triggered to display the cursor. -void deleted_lines_mark(linenr_T lnum, long count) +void deleted_lines_mark(linenr_T lnum, int count) { bool made_empty = (count > 0) && curbuf->b_ml.ml_flags & ML_EMPTY; @@ -812,7 +812,7 @@ int del_char(bool fixpos) } /// Like del_bytes(), but delete characters instead of bytes. -int del_chars(long count, int fixpos) +int del_chars(int count, int fixpos) { int bytes = 0; char *p = get_cursor_pos_ptr(); @@ -1928,7 +1928,7 @@ void truncate_line(int fixpos) /// Saves the lines for undo first if "undo" is true. void del_lines(long nlines, bool undo) { - long n; + int n; linenr_T first = curwin->w_cursor.lnum; if (nlines <= 0) { -- cgit From 58a1ef8e6a93c615379f6fbe7234697bcdc42b3e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 12 Aug 2023 09:50:17 +0800 Subject: fix(events): avoid unnecessary CursorMoved (#24675) Problem: Temporarily changing current window in a script causes CursorMoved to be triggerd. Solution: Don't trigger CursorMoved if neither curwin nor cursor changed between two checks. --- 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 932de727b5..599e319dde 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -361,9 +361,10 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T } // when the cursor line is changed always trigger CursorMoved - if (lnum <= curwin->w_cursor.lnum + if (last_cursormoved_win == curwin + && lnum <= curwin->w_cursor.lnum && lnume + (xtra < 0 ? -xtra : xtra) > curwin->w_cursor.lnum) { - curwin->w_last_cursormoved.lnum = 0; + last_cursormoved.lnum = 0; } } -- 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/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 599e319dde..36f0fc70a1 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -609,7 +609,7 @@ bool file_ff_differs(buf_T *buf, bool ignore_empty) if (ignore_empty && (buf->b_flags & BF_NEW) && buf->b_ml.ml_line_count == 1 - && *ml_get_buf(buf, (linenr_T)1, false) == NUL) { + && *ml_get_buf(buf, (linenr_T)1) == NUL) { return false; } if (buf->b_start_ffc != *buf->b_p_ff) { -- 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/change.c | 122 +++++++++++++++++++++++++++++------------------------- 1 file changed, 65 insertions(+), 57 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 36f0fc70a1..067b48faee 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -101,28 +101,28 @@ void change_warning(buf_T *buf, int col) } } -/// Call this function when something in the current buffer is changed. +/// Call this function when something in a buffer is changed. /// /// Most often called through changed_bytes() and changed_lines(), which also /// mark the area of the display to be redrawn. /// /// Careful: may trigger autocommands that reload the buffer. -void changed(void) +void changed(buf_T *buf) { - if (!curbuf->b_changed) { + if (!buf->b_changed) { int save_msg_scroll = msg_scroll; // Give a warning about changing a read-only file. This may also // check-out the file, thus change "curbuf"! - change_warning(curbuf, 0); + change_warning(buf, 0); // Create a swap file if that is wanted. // Don't do this for "nofile" and "nowrite" buffer types. - if (curbuf->b_may_swap && !bt_dontwrite(curbuf)) { + if (buf->b_may_swap && !bt_dontwrite(buf)) { bool save_need_wait_return = need_wait_return; need_wait_return = false; - ml_open_file(curbuf); + ml_open_file(buf); // The ml_open_file() can cause an ATTENTION message. // Wait two seconds, to make sure the user reads this unexpected @@ -137,9 +137,9 @@ void changed(void) need_wait_return = save_need_wait_return; } } - changed_internal(); + changed_internal(buf); } - buf_inc_changedtick(curbuf); + buf_inc_changedtick(buf); // If a pattern is highlighted, the position may now be invalid. highlight_match = false; @@ -147,12 +147,12 @@ void changed(void) /// Internal part of changed(), no user interaction. /// Also used for recovery. -void changed_internal(void) +void changed_internal(buf_T *buf) { - curbuf->b_changed = true; - curbuf->b_changed_invalid = true; - ml_setflags(curbuf); - redraw_buf_status_later(curbuf); + buf->b_changed = true; + buf->b_changed_invalid = true; + ml_setflags(buf); + redraw_buf_status_later(buf); redraw_tabline = true; need_maketitle = true; // set window title later } @@ -160,13 +160,15 @@ 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, linenr_T xtra) +static void changed_common(buf_T *buf, linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T xtra) { // mark the buffer as modified - changed(); + changed(buf); - if (curwin->w_p_diff && diff_internal()) { - curtab->tp_diff_update = true; + FOR_ALL_WINDOWS_IN_TAB(win, curtab) { + if (win->w_buffer == buf && win->w_p_diff && diff_internal()) { + curtab->tp_diff_update = true; + } } // set the '. mark @@ -174,22 +176,25 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T 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); + + if (curwin->w_buffer == buf) { + 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); + RESET_FMARK(&buf->b_last_change, ((pos_T) { lnum, col, 0 }), buf->handle, view); // 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) { + if (buf->b_new_change || buf->b_changelistlen == 0) { int add; - if (curbuf->b_changelistlen == 0) { + if (buf->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". - pos_T *p = &curbuf->b_changelist[curbuf->b_changelistlen - 1].mark; + pos_T *p = &buf->b_changelist[buf->b_changelistlen - 1].mark; if (p->lnum != lnum) { add = true; } else { @@ -204,17 +209,17 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T // This is the first of a new sequence of undo-able changes // and it's at some distance of the last change. Use a new // position in the changelist. - curbuf->b_new_change = false; + buf->b_new_change = false; - if (curbuf->b_changelistlen == JUMPLISTSIZE) { + if (buf->b_changelistlen == JUMPLISTSIZE) { // changelist is full: remove oldest entry - curbuf->b_changelistlen = JUMPLISTSIZE - 1; - memmove(curbuf->b_changelist, curbuf->b_changelist + 1, - sizeof(curbuf->b_changelist[0]) * (JUMPLISTSIZE - 1)); + buf->b_changelistlen = JUMPLISTSIZE - 1; + memmove(buf->b_changelist, buf->b_changelist + 1, + sizeof(buf->b_changelist[0]) * (JUMPLISTSIZE - 1)); FOR_ALL_TAB_WINDOWS(tp, wp) { // Correct position in changelist for other windows on // this buffer. - if (wp->w_buffer == curbuf && wp->w_changelistidx > 0) { + if (wp->w_buffer == buf && wp->w_changelistidx > 0) { wp->w_changelistidx--; } } @@ -222,27 +227,29 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T FOR_ALL_TAB_WINDOWS(tp, wp) { // For other windows, if the position in the changelist is // at the end it stays at the end. - if (wp->w_buffer == curbuf - && wp->w_changelistidx == curbuf->b_changelistlen) { + if (wp->w_buffer == buf + && wp->w_changelistidx == buf->b_changelistlen) { wp->w_changelistidx++; } } - curbuf->b_changelistlen++; + buf->b_changelistlen++; } } - curbuf->b_changelist[curbuf->b_changelistlen - 1] = - curbuf->b_last_change; + buf->b_changelist[buf->b_changelistlen - 1] = + buf->b_last_change; // The current window is always after the last change, so that "g," // takes you back to it. - curwin->w_changelistidx = curbuf->b_changelistlen; + if (curwin->w_buffer == buf) { + curwin->w_changelistidx = buf->b_changelistlen; + } } - if (VIsual_active) { + if (curwin->w_buffer == buf && VIsual_active) { check_visual_pos(); } FOR_ALL_TAB_WINDOWS(tp, wp) { - if (wp->w_buffer == curbuf) { + if (wp->w_buffer == buf) { // Mark this window to be redrawn later. if (wp->w_redr_type < UPD_VALID) { wp->w_redr_type = UPD_VALID; @@ -295,7 +302,7 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T if (wp->w_cursor.lnum > lnum) { changed_line_abv_curs_win(wp); } else if (wp->w_cursor.lnum == lnum && wp->w_cursor.col >= col) { - changed_cline_bef_curs_win(wp); + changed_cline_bef_curs(wp); } if (wp->w_botline >= lnum) { // Assume that botline doesn't change (inserted lines make @@ -361,7 +368,7 @@ static void changed_common(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T } // when the cursor line is changed always trigger CursorMoved - if (last_cursormoved_win == curwin + if (last_cursormoved_win == curwin && curwin->w_buffer == buf && lnum <= curwin->w_cursor.lnum && lnume + (xtra < 0 ? -xtra : xtra) > curwin->w_cursor.lnum) { last_cursormoved.lnum = 0; @@ -394,7 +401,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, 0); + changed_common(curbuf, lnum, col, lnum + 1, 0); // When text has been changed at the end of the line, possibly the start of // the next line may have SpellCap that should be removed or it needs to be // displayed. Schedule the next line for redrawing just in case. @@ -438,14 +445,14 @@ void inserted_bytes(linenr_T lnum, colnr_T start_col, int old_col, int new_col) /// Takes care of marking the buffer to be redrawn and sets the changed flag. void appended_lines(linenr_T lnum, linenr_T count) { - changed_lines(lnum + 1, 0, lnum + 1, count, true); + changed_lines(curbuf, lnum + 1, 0, lnum + 1, count, true); } /// Like appended_lines(), but adjust marks first. void appended_lines_mark(linenr_T lnum, int count) { mark_adjust(lnum + 1, (linenr_T)MAXLNUM, (linenr_T)count, 0L, kExtmarkUndo); - changed_lines(lnum + 1, 0, lnum + 1, (linenr_T)count, true); + changed_lines(curbuf, lnum + 1, 0, lnum + 1, (linenr_T)count, true); } /// Deleted "count" lines at line "lnum" in the current buffer. @@ -453,7 +460,7 @@ void appended_lines_mark(linenr_T lnum, int count) /// Takes care of marking the buffer to be redrawn and sets the changed flag. void deleted_lines(linenr_T lnum, linenr_T count) { - changed_lines(lnum, 0, lnum + count, -count, true); + changed_lines(curbuf, lnum, 0, lnum + count, -count, true); } /// Like deleted_lines(), but adjust marks first. @@ -467,7 +474,7 @@ void deleted_lines_mark(linenr_T lnum, int count) // if we deleted the entire buffer, we need to implicitly add a new empty line extmark_adjust(curbuf, lnum, (linenr_T)(lnum + count - 1), MAXLNUM, -(linenr_T)count + (made_empty ? 1 : 0), kExtmarkUndo); - changed_lines(lnum, 0, lnum + (linenr_T)count, (linenr_T)(-count), true); + changed_lines(curbuf, lnum, 0, lnum + (linenr_T)count, (linenr_T)(-count), true); } /// Marks the area to be redrawn after a change. @@ -477,7 +484,7 @@ void deleted_lines_mark(linenr_T lnum, int 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, linenr_T xtra) +void buf_redraw_changed_lines_later(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 @@ -504,7 +511,7 @@ void changed_lines_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, linenr_T xtra) } } -/// Changed lines for the current buffer. +/// Changed lines for a buffer. /// Must be called AFTER the change and after mark_adjust(). /// - mark the buffer changed by calling changed() /// - mark the windows on this buffer to be redisplayed @@ -522,11 +529,12 @@ void changed_lines_buf(buf_T *buf, linenr_T lnum, linenr_T lnume, linenr_T 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, linenr_T xtra, bool do_buf_event) +void changed_lines(buf_T *buf, linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T xtra, + bool do_buf_event) { - changed_lines_buf(curbuf, lnum, lnume, xtra); + buf_redraw_changed_lines_later(buf, lnum, lnume, xtra); - if (xtra == 0 && curwin->w_p_diff && !diff_internal()) { + if (xtra == 0 && curwin->w_p_diff && curwin->w_buffer == buf && !diff_internal()) { // When the number of lines doesn't change then mark_adjust() isn't // called and other diff buffers still need to be marked for // displaying. @@ -537,19 +545,19 @@ void changed_lines(linenr_T lnum, colnr_T col, linenr_T lnume, linenr_T xtra, bo redraw_later(wp, UPD_VALID); wlnum = diff_lnum_win(lnum, wp); if (wlnum > 0) { - changed_lines_buf(wp->w_buffer, wlnum, - lnume - lnum + wlnum, 0L); + buf_redraw_changed_lines_later(wp->w_buffer, wlnum, + lnume - lnum + wlnum, 0L); } } } } - changed_common(lnum, col, lnume, xtra); + changed_common(buf, lnum, col, lnume, xtra); 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); + buf_updates_send_changes(buf, lnum, num_added, num_removed); } } @@ -1119,7 +1127,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) *p_extra = NUL; } - u_clearline(); // cannot do "U" command when adding lines + u_clearline(curbuf); // cannot do "U" command when adding lines did_si = false; ai_col = 0; @@ -1807,7 +1815,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) saved_line = NULL; if (did_append) { - changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, + changed_lines(curbuf, curwin->w_cursor.lnum, curwin->w_cursor.col, curwin->w_cursor.lnum + 1, 1L, true); did_append = false; @@ -1833,7 +1841,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) curwin->w_cursor.lnum = old_cursor.lnum + 1; } if (did_append) { - changed_lines(curwin->w_cursor.lnum, 0, curwin->w_cursor.lnum, 1L, true); + changed_lines(curbuf, 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, @@ -1958,7 +1966,7 @@ void del_lines(long nlines, bool undo) // Correct the cursor position before calling deleted_lines_mark(), it may // trigger a callback to display the cursor. curwin->w_cursor.col = 0; - check_cursor_lnum(); + check_cursor_lnum(curwin); // adjust marks, mark the buffer as changed and prepare for displaying deleted_lines_mark(first, n); -- cgit From 362df0f7938a0e6147ecf886655a0689430d426d Mon Sep 17 00:00:00 2001 From: Ibby <33922797+SleepySwords@users.noreply.github.com> Date: Sat, 26 Aug 2023 21:39:05 +1000 Subject: fix(extmarks): wrong display when changing text with virt_lines (#24879) --- src/nvim/change.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 067b48faee..084a8a1897 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -319,7 +319,12 @@ static void changed_common(buf_T *buf, linenr_T lnum, colnr_T col, linenr_T lnum if (wp->w_lines[i].wl_lnum >= lnum) { // Do not change wl_lnum at index zero, it is used to // compare with w_topline. Invalidate it instead. - if (wp->w_lines[i].wl_lnum < lnume || i == 0) { + // If the buffer has virt_lines, invalidate the line + // after the changed lines as the virt_lines for a + // changed line may become invalid. + if (i == 0 || wp->w_lines[i].wl_lnum < lnume + || (wp->w_lines[i].wl_lnum == lnume + && wp->w_buffer->b_virt_line_blocks > 0)) { // line included in change wp->w_lines[i].wl_valid = false; } else if (xtra != 0) { -- 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/change.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 084a8a1897..48dc02b65b 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -39,6 +39,7 @@ #include "nvim/message.h" #include "nvim/move.h" #include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/os/time.h" #include "nvim/plines.h" #include "nvim/pos.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/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 48dc02b65b..abbfe2505e 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1941,7 +1941,7 @@ void truncate_line(int fixpos) /// Delete "nlines" lines at the cursor. /// Saves the lines for undo first if "undo" is true. -void del_lines(long nlines, bool undo) +void del_lines(linenr_T nlines, bool undo) { int n; linenr_T first = curwin->w_cursor.lnum; -- 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/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 abbfe2505e..acc657a1c2 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -831,7 +831,7 @@ int del_chars(int count, int fixpos) { int bytes = 0; char *p = get_cursor_pos_ptr(); - for (long i = 0; i < count && *p != NUL; i++) { + for (int i = 0; i < count && *p != NUL; i++) { int l = utfc_ptr2len(p); bytes += l; p += l; @@ -1829,7 +1829,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) if (flags & OPENLINE_MARKFIX) { mark_col_adjust(curwin->w_cursor.lnum, curwin->w_cursor.col + less_cols_off, - 1L, (long)-less_cols, 0); + 1L, -less_cols, 0); } // Always move extmarks - Here we move only the line where the // cursor is, the previous mark_adjust takes care of the lines after -- 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/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 acc657a1c2..a2657b86aa 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -92,7 +92,7 @@ void change_warning(buf_T *buf, int col) (void)msg_end(); if (msg_silent == 0 && !silent_mode && ui_active()) { ui_flush(); - os_delay(1002L, true); // give the user time to think about it + os_delay(1002, true); // give the user time to think about it } buf->b_did_warn = true; redraw_cmdline = false; // don't redraw and erase the message @@ -131,7 +131,7 @@ void changed(buf_T *buf) // and don't let the emsg() set msg_scroll. if (need_wait_return && emsg_silent == 0 && !in_assert_fails) { ui_flush(); - os_delay(2002L, true); + os_delay(2002, true); wait_return(true); msg_scroll = save_msg_scroll; } else { @@ -457,7 +457,7 @@ void appended_lines(linenr_T lnum, linenr_T count) /// Like appended_lines(), but adjust marks first. void appended_lines_mark(linenr_T lnum, int count) { - mark_adjust(lnum + 1, (linenr_T)MAXLNUM, (linenr_T)count, 0L, kExtmarkUndo); + mark_adjust(lnum + 1, (linenr_T)MAXLNUM, (linenr_T)count, 0, kExtmarkUndo); changed_lines(curbuf, lnum + 1, 0, lnum + 1, (linenr_T)count, true); } @@ -552,7 +552,7 @@ void changed_lines(buf_T *buf, linenr_T lnum, colnr_T col, linenr_T lnume, linen wlnum = diff_lnum_win(lnum, wp); if (wlnum > 0) { buf_redraw_changed_lines_later(wp->w_buffer, wlnum, - lnume - lnum + wlnum, 0L); + lnume - lnum + wlnum, 0); } } } @@ -823,7 +823,7 @@ int del_char(bool fixpos) if (*get_cursor_pos_ptr() == NUL) { return FAIL; } - return del_chars(1L, fixpos); + return del_chars(1, fixpos); } /// Like del_bytes(), but delete characters instead of bytes. @@ -1731,7 +1731,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) } // Postpone calling changed_lines(), because it would mess up folding // with markers. - mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L, kExtmarkNOOP); + mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1, 0, kExtmarkNOOP); did_append = true; } else { // In MODE_VREPLACE state we are starting to replace the next line. @@ -1822,14 +1822,14 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) saved_line = NULL; if (did_append) { changed_lines(curbuf, curwin->w_cursor.lnum, curwin->w_cursor.col, - curwin->w_cursor.lnum + 1, 1L, true); + curwin->w_cursor.lnum + 1, 1, true); did_append = false; // Move marks after the line break to the new line. if (flags & OPENLINE_MARKFIX) { mark_col_adjust(curwin->w_cursor.lnum, curwin->w_cursor.col + less_cols_off, - 1L, -less_cols, 0); + 1, -less_cols, 0); } // Always move extmarks - Here we move only the line where the // cursor is, the previous mark_adjust takes care of the lines after @@ -1847,7 +1847,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) curwin->w_cursor.lnum = old_cursor.lnum + 1; } if (did_append) { - changed_lines(curbuf, curwin->w_cursor.lnum, 0, curwin->w_cursor.lnum, 1L, true); + changed_lines(curbuf, curwin->w_cursor.lnum, 0, curwin->w_cursor.lnum, 1, 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, -- 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/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 a2657b86aa..39229e1cf0 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -623,7 +623,7 @@ bool file_ff_differs(buf_T *buf, bool ignore_empty) if (ignore_empty && (buf->b_flags & BF_NEW) && buf->b_ml.ml_line_count == 1 - && *ml_get_buf(buf, (linenr_T)1) == NUL) { + && *ml_get_buf(buf, 1) == NUL) { return false; } if (buf->b_start_ffc != *buf->b_p_ff) { @@ -1726,7 +1726,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) curwin->w_cursor.lnum--; } if ((State & VREPLACE_FLAG) == 0 || 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, p_extra, 0, false) == FAIL) { goto theend; } // Postpone calling changed_lines(), because it would mess up folding -- 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/change.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 39229e1cf0..bee074385e 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.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 - /// change.c: functions related to changing text #include -- 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/change.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index bee074385e..46c21da384 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1696,14 +1696,13 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) // concatenate leader and p_extra, if there is a leader if (lead_len > 0) { if (flags & OPENLINE_COM_LIST && second_line_indent > 0) { - int i; int padding = second_line_indent - (newindent + (int)strlen(leader)); // Here whitespace is inserted after the comment char. // Below, set_indent(newindent, SIN_INSERT) will insert the // whitespace needed before the comment char. - for (i = 0; i < padding; i++) { + for (int i = 0; i < padding; i++) { STRCAT(leader, " "); less_cols--; newcol++; @@ -1987,9 +1986,7 @@ int get_leader_len(char *line, char **flags, bool backward, bool include_space) int got_com = false; char part_buf[COM_MAX_LEN]; // buffer for one option part char *string; // pointer to comment string - char *list; int middle_match_len = 0; - char *prev_list; char *saved_flags = NULL; int result = 0; @@ -2002,13 +1999,13 @@ int get_leader_len(char *line, char **flags, bool backward, bool include_space) while (line[i] != NUL) { // scan through the 'comments' option for a match int found_one = false; - for (list = curbuf->b_p_com; *list;) { + for (char *list = 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; + char *prev_list = list; (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ","); string = vim_strchr(part_buf, ':'); if (string == NULL) { // missing ':', ignore this part @@ -2204,7 +2201,6 @@ int get_last_leader_offset(char *line, char **flags) if (found_one) { char part_buf2[COM_MAX_LEN]; // buffer for one option part - int len1, len2, off; result = i; // If this comment nests, continue searching. @@ -2222,7 +2218,7 @@ int get_last_leader_offset(char *line, char **flags) while (ascii_iswhite(*com_leader)) { com_leader++; } - len1 = (int)strlen(com_leader); + int len1 = (int)strlen(com_leader); for (list = curbuf->b_p_com; *list;) { char *flags_save = list; @@ -2236,14 +2232,14 @@ int get_last_leader_offset(char *line, char **flags) while (ascii_iswhite(*string)) { string++; } - len2 = (int)strlen(string); + int len2 = (int)strlen(string); if (len2 == 0) { continue; } // Now we have to verify whether string ends with a substring // beginning the com_leader. - for (off = (len2 > i ? i : len2); off > 0 && off + len1 > len2;) { + for (int off = (len2 > i ? i : len2); off > 0 && off + len1 > len2;) { off--; if (!strncmp(string + off, com_leader, (size_t)(len2 - off))) { if (i - off < lower_check_bound) { -- cgit From 6952b1951b6a60df8d477279f4451094fb51c413 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 17 Nov 2023 08:40:02 +0800 Subject: vim-patch:9.0.2107: [security]: FPE in adjust_plines_for_skipcol (#26082) Problem: [security]: FPE in adjust_plines_for_skipcol Solution: don't divide by zero, return zero Prevent a floating point exception when calculating w_skipcol (which can happen with a small window when the number option is set and cpo+=n). Add a test to verify https://github.com/vim/vim/commit/cb0b99f0672d8446585d26e998343dceca17d1ce Co-authored-by: Christian Brabandt --- 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 46c21da384..58718811bc 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -262,9 +262,9 @@ static void changed_common(buf_T *buf, linenr_T lnum, colnr_T col, linenr_T lnum && (last < wp->w_topline || (wp->w_topline >= lnum && wp->w_topline < lnume - && win_linetabsize(wp, wp->w_topline, ml_get(wp->w_topline), (colnr_T)MAXCOL) - <= (unsigned)(wp->w_skipcol + sms_marker_overlap(wp, win_col_off(wp) - - win_col_off2(wp)))))) { + && win_linetabsize(wp, wp->w_topline, ml_get(wp->w_topline), MAXCOL) + <= (wp->w_skipcol + + sms_marker_overlap(wp, win_col_off(wp) - win_col_off2(wp)))))) { wp->w_skipcol = 0; } -- cgit From b522cb1ac3fbdf6e68eed5d0b6e1cbeaf3ac2254 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 6 Nov 2023 14:52:27 +0100 Subject: refactor(grid): make screen rendering more multibyte than ever before Problem: buffer text with composing chars are converted from UTF-8 to an array of up to seven UTF-32 values and then converted back to UTF-8 strings. Solution: Convert buffer text directly to UTF-8 based schar_T values. The limit of the text size is now in schar_T bytes, which is currently 31+1 but easily could be raised as it no longer multiplies the size of the entire screen grid when not used, the full size is only required for temporary scratch buffers. Also does some general cleanup to win_line text handling, which was unnecessarily complicated due to multibyte rendering being an "opt-in" feature long ago. Nowadays, a char is just a char, regardless if it consists of one ASCII byte or multiple bytes. --- src/nvim/change.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 58718811bc..aa58779f5b 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -665,7 +665,7 @@ void ins_bytes_len(char *p, size_t len) /// convert bytes to a character. void ins_char(int c) { - char buf[MB_MAXBYTES + 1]; + char buf[MB_MAXCHAR + 1]; size_t n = (size_t)utf_char2bytes(c, buf); // When "c" is 0x100, 0x200, etc. we don't want to insert a NUL byte. @@ -869,12 +869,9 @@ 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) { - int cc[MAX_MCO]; - - (void)utfc_ptr2char(oldp + col, cc); - if (cc[0] != NUL) { + if (p_deco && use_delcombine && utfc_ptr2len(oldp + col) >= count) { + char *p0 = oldp + col; + if (utf_composinglike(p0, p0 + utf_ptr2len(p0))) { // Find the last composing char, there can be several. int n = col; do { -- cgit From a827003e3052c6d9ee7bdb71518182e9bd76317d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 25 Nov 2023 11:32:32 +0100 Subject: build: rework IWYU mapping files Create mapping to most of the C spec and some POSIX specific functions. This is more robust than relying files shipped with IWYU. --- 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 aa58779f5b..f9eeab38c8 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -23,7 +23,6 @@ #include "nvim/fold.h" #include "nvim/gettext.h" #include "nvim/globals.h" -#include "nvim/grid_defs.h" #include "nvim/highlight_defs.h" #include "nvim/indent.h" #include "nvim/indent_c.h" -- cgit From 8b428ca8b79ebb7b36c3e403ff3bcb6924a635a6 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 16:00:21 +0100 Subject: build(IWYU): fix includes for func_attr.h --- src/nvim/change.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index f9eeab38c8..c0380b57df 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -21,6 +21,7 @@ #include "nvim/ex_cmds_defs.h" #include "nvim/extmark.h" #include "nvim/fold.h" +#include "nvim/func_attr.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/highlight_defs.h" -- cgit From f4aedbae4cb1f206f5b7c6142697b71dd473059b Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 18:39:38 +0100 Subject: build(IWYU): fix includes for undo_defs.h --- 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 c0380b57df..2949ebaf62 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -39,7 +39,7 @@ #include "nvim/option_vars.h" #include "nvim/os/time.h" #include "nvim/plines.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/search.h" #include "nvim/spell.h" #include "nvim/state.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/change.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/change.c') diff --git a/src/nvim/change.c b/src/nvim/change.c index 2949ebaf62..20cc034638 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -5,8 +5,8 @@ #include #include -#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/buffer_defs.h" @@ -28,7 +28,7 @@ #include "nvim/indent.h" #include "nvim/indent_c.h" #include "nvim/insexpand.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/mark.h" #include "nvim/mbyte.h" #include "nvim/memline.h" @@ -47,7 +47,7 @@ #include "nvim/textformat.h" #include "nvim/ui.h" #include "nvim/undo.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "change.c.generated.h" -- 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/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 20cc034638..81a55b92ee 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -24,7 +24,7 @@ #include "nvim/func_attr.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/insexpand.h" -- cgit