From 4be6c6cf0ddf5e31d4103cb5df06651ba6f4897b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 11:05:57 +0100 Subject: refactor: replace char_u with char (#21901) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/cursor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/cursor.c') diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index b1dbc68ea3..ceeaa65206 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -494,10 +494,10 @@ int gchar_cursor(void) /// Write a character at the current cursor position. /// It is directly written into the block. -void pchar_cursor(char_u c) +void pchar_cursor(char c) { *(ml_get_buf(curbuf, curwin->w_cursor.lnum, true) - + curwin->w_cursor.col) = (char)c; + + curwin->w_cursor.col) = c; } /// @return pointer to cursor line. -- 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/cursor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/cursor.c') diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index ceeaa65206..6d90b32545 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -351,7 +351,7 @@ void check_cursor_col_win(win_T *win) { colnr_T oldcol = win->w_cursor.col; colnr_T oldcoladd = win->w_cursor.col + win->w_cursor.coladd; - unsigned int cur_ve_flags = get_ve_flags(); + unsigned cur_ve_flags = get_ve_flags(); colnr_T len = (colnr_T)strlen(ml_get_buf(win->w_buffer, win->w_cursor.lnum, false)); if (len == 0) { -- cgit From c426f7a6228cb82af0f75ac4f2421543408ff091 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 27 Apr 2023 00:03:46 +0200 Subject: vim-patch:9.0.0751: 'scrolloff' does not work well with 'smoothscroll' Problem: 'scrolloff' does not work well with 'smoothscroll'. Solution: Make positioning the cursor a bit better. Rename functions. https://github.com/vim/vim/commit/c9121f798f49fa71e814912cb186d89c164090c3 Co-authored-by: Bram Moolenaar --- src/nvim/cursor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/cursor.c') diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 6d90b32545..cdadc89e31 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -115,7 +115,7 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a col = wcol; if ((addspaces || finetune) && !VIsual_active) { - curwin->w_curswant = linetabsize(line) + one_more; + curwin->w_curswant = linetabsize_str(line) + one_more; if (curwin->w_curswant > 0) { curwin->w_curswant--; } @@ -129,7 +129,7 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a && curwin->w_width_inner != 0 && wcol >= (colnr_T)width && width > 0) { - csize = linetabsize(line); + csize = linetabsize_str(line); if (csize > 0) { csize--; } -- cgit From 26a9f0e94eb62047f0c2bb99401a8ac09840d0dd Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 27 Apr 2023 19:08:20 +0200 Subject: vim-patch:9.0.0901: setting w_leftcol and handling side effects is confusing Problem: Setting w_leftcol and handling side effects is confusing. Solution: Use a function to set w_leftcol() and handle side effects. https://github.com/vim/vim/commit/0c34d562647f029faca40f7733ccfb7b5377672b Co-authored-by: Bram Moolenaar --- src/nvim/cursor.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/nvim/cursor.c') diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index cdadc89e31..8ba0b2ffb3 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -439,23 +439,27 @@ void adjust_cursor_col(void) } } -/// When curwin->w_leftcol has changed, adjust the cursor position. +/// Set "curwin->w_leftcol" to "leftcol". +/// Adjust the cursor position if needed. /// /// @return true if the cursor was moved. -bool leftcol_changed(void) +bool set_leftcol(colnr_T leftcol) { - // TODO(hinidu): I think it should be colnr_T or int, but p_siso is long. - // Perhaps we can change p_siso to int. - int64_t lastcol; - colnr_T s, e; - bool retval = false; + // Return quickly when there is no change. + if (curwin->w_leftcol == leftcol) { + return false; + } + curwin->w_leftcol = leftcol; changed_cline_bef_curs(); - lastcol = curwin->w_leftcol + curwin->w_width_inner - curwin_col_off() - 1; + // TODO(hinidu): I think it should be colnr_T or int, but p_siso is long. + // Perhaps we can change p_siso to int. + int64_t lastcol = curwin->w_leftcol + curwin->w_width_inner - curwin_col_off() - 1; validate_virtcol(); + bool retval = false; // If the cursor is right or left of the screen, move it to last or first - // character. + // visible character. long siso = get_sidescrolloff_value(curwin); if (curwin->w_virtcol > (colnr_T)(lastcol - siso)) { retval = true; @@ -468,6 +472,7 @@ bool leftcol_changed(void) // If the start of the character under the cursor is not on the screen, // advance the cursor one more char. If this fails (last char of the // line) adjust the scrolling. + colnr_T s, e; getvvcol(curwin, &curwin->w_cursor, &s, NULL, &e); if (e > (colnr_T)lastcol) { retval = true; -- cgit From 5a564bf242828a04c8fe12c7e83154cb09acf4aa Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Aug 2023 20:35:51 +0800 Subject: refactor: cast to int earlier when using 'so' and 'siso' (#24756) --- src/nvim/cursor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/cursor.c') diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 8ba0b2ffb3..a837618f5b 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -460,7 +460,7 @@ bool set_leftcol(colnr_T leftcol) bool retval = false; // If the cursor is right or left of the screen, move it to last or first // visible character. - long siso = get_sidescrolloff_value(curwin); + int siso = get_sidescrolloff_value(curwin); if (curwin->w_virtcol > (colnr_T)(lastcol - siso)) { retval = true; coladvance((colnr_T)(lastcol - siso)); -- 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/cursor.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/nvim/cursor.c') diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index a837618f5b..f7a456f4c7 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -108,7 +108,7 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a || (VIsual_active && *p_sel != 'o') || ((get_ve_flags() & VE_ONEMORE) && wcol < MAXCOL); - char *line = ml_get_buf(curbuf, pos->lnum, false); + char *line = ml_get_buf(curbuf, pos->lnum); if (wcol >= MAXCOL) { idx = (int)strlen(line) - 1 + one_more; @@ -315,7 +315,7 @@ void check_pos(buf_T *buf, pos_T *pos) } if (pos->col > 0) { - char *line = ml_get_buf(buf, pos->lnum, false); + char *line = ml_get_buf(buf, pos->lnum); colnr_T len = (colnr_T)strlen(line); if (pos->col > len) { pos->col = len; @@ -353,7 +353,7 @@ void check_cursor_col_win(win_T *win) colnr_T oldcoladd = win->w_cursor.col + win->w_cursor.coladd; unsigned cur_ve_flags = get_ve_flags(); - colnr_T len = (colnr_T)strlen(ml_get_buf(win->w_buffer, win->w_cursor.lnum, false)); + colnr_T len = (colnr_T)strlen(ml_get_buf(win->w_buffer, win->w_cursor.lnum)); if (len == 0) { win->w_cursor.col = 0; } else if (win->w_cursor.col >= len) { @@ -501,18 +501,17 @@ int gchar_cursor(void) /// It is directly written into the block. void pchar_cursor(char c) { - *(ml_get_buf(curbuf, curwin->w_cursor.lnum, true) - + curwin->w_cursor.col) = c; + *(ml_get_buf_mut(curbuf, curwin->w_cursor.lnum) + curwin->w_cursor.col) = c; } /// @return pointer to cursor line. char *get_cursor_line_ptr(void) { - return ml_get_buf(curbuf, curwin->w_cursor.lnum, false); + return ml_get_buf(curbuf, curwin->w_cursor.lnum); } /// @return pointer to cursor position. char *get_cursor_pos_ptr(void) { - return ml_get_buf(curbuf, curwin->w_cursor.lnum, false) + curwin->w_cursor.col; + return ml_get_buf(curbuf, curwin->w_cursor.lnum) + curwin->w_cursor.col; } -- 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/cursor.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/nvim/cursor.c') diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index f7a456f4c7..2dc903309e 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -324,18 +324,18 @@ void check_pos(buf_T *buf, pos_T *pos) } /// Make sure curwin->w_cursor.lnum is valid. -void check_cursor_lnum(void) +void check_cursor_lnum(win_T *win) { - if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) { + buf_T *buf = win->w_buffer; + if (win->w_cursor.lnum > buf->b_ml.ml_line_count) { // If there is a closed fold at the end of the file, put the cursor in // its first line. Otherwise in the last line. - if (!hasFolding(curbuf->b_ml.ml_line_count, - &curwin->w_cursor.lnum, NULL)) { - curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; + if (!hasFolding(buf->b_ml.ml_line_count, &win->w_cursor.lnum, NULL)) { + win->w_cursor.lnum = buf->b_ml.ml_line_count; } } - if (curwin->w_cursor.lnum <= 0) { - curwin->w_cursor.lnum = 1; + if (win->w_cursor.lnum <= 0) { + win->w_cursor.lnum = 1; } } @@ -406,7 +406,7 @@ void check_cursor_col_win(win_T *win) /// Make sure curwin->w_cursor in on a valid character void check_cursor(void) { - check_cursor_lnum(); + check_cursor_lnum(curwin); check_cursor_col(); } @@ -451,7 +451,7 @@ bool set_leftcol(colnr_T leftcol) } curwin->w_leftcol = leftcol; - changed_cline_bef_curs(); + changed_cline_bef_curs(curwin); // TODO(hinidu): I think it should be colnr_T or int, but p_siso is long. // Perhaps we can change p_siso to int. int64_t lastcol = curwin->w_leftcol + curwin->w_width_inner - curwin_col_off() - 1; @@ -481,7 +481,7 @@ bool set_leftcol(colnr_T leftcol) retval = true; if (coladvance(e + 1) == FAIL) { // there isn't another character curwin->w_leftcol = s; // adjust w_leftcol instead - changed_cline_bef_curs(); + changed_cline_bef_curs(curwin); } } -- cgit From 1f49c980368616345d8d0e121fed66a2013f9e96 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 27 Aug 2023 20:04:44 +0800 Subject: vim-patch:9.0.1792: problem with gj/gk/gM and virtual text (#24898) Problem: Normal mode "gM", "gj", "gk" commands behave incorrectly with virtual text. Solution: Use linetabsize() instead of linetabsize_str(). closes: vim/vim#12909 https://github.com/vim/vim/commit/d809c0a90387a23aed21ba37d0b65332fb5dafe7 --- src/nvim/cursor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/cursor.c') diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 2dc903309e..418d49dfeb 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -115,7 +115,7 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a col = wcol; if ((addspaces || finetune) && !VIsual_active) { - curwin->w_curswant = linetabsize_str(line) + one_more; + curwin->w_curswant = (int)linetabsize(curwin, pos->lnum) + one_more; if (curwin->w_curswant > 0) { curwin->w_curswant--; } @@ -129,7 +129,7 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a && curwin->w_width_inner != 0 && wcol >= (colnr_T)width && width > 0) { - csize = linetabsize_str(line); + csize = (int)linetabsize(curwin, pos->lnum); if (csize > 0) { csize--; } -- cgit From cf8b2c0e74fd5e723b0c15c2ce84e6900fd322d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 12:05:28 +0800 Subject: build(iwyu): add a few more _defs.h mappings (#25435) --- src/nvim/cursor.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/nvim/cursor.c') diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 418d49dfeb..be8fd03d57 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -10,7 +10,6 @@ #include "nvim/assert.h" #include "nvim/buffer_defs.h" #include "nvim/change.h" -#include "nvim/charset.h" #include "nvim/cursor.h" #include "nvim/drawscreen.h" #include "nvim/fold.h" @@ -25,7 +24,6 @@ #include "nvim/plines.h" #include "nvim/pos.h" #include "nvim/state.h" -#include "nvim/types.h" #include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS -- 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/cursor.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/cursor.c') diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index be8fd03d57..ca309757f9 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -21,6 +21,7 @@ #include "nvim/memory.h" #include "nvim/move.h" #include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/plines.h" #include "nvim/pos.h" #include "nvim/state.h" -- 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/cursor.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/cursor.c') diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index ca309757f9..4e8457eb2d 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.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 - #include #include #include -- 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/cursor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/cursor.c') diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 4e8457eb2d..32ee1d6c08 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -111,7 +111,7 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a col = wcol; if ((addspaces || finetune) && !VIsual_active) { - curwin->w_curswant = (int)linetabsize(curwin, pos->lnum) + one_more; + curwin->w_curswant = linetabsize(curwin, pos->lnum) + one_more; if (curwin->w_curswant > 0) { curwin->w_curswant--; } @@ -125,7 +125,7 @@ static int coladvance2(pos_T *pos, bool addspaces, bool finetune, colnr_T wcol_a && curwin->w_width_inner != 0 && wcol >= (colnr_T)width && width > 0) { - csize = (int)linetabsize(curwin, pos->lnum); + csize = linetabsize(curwin, pos->lnum); if (csize > 0) { csize--; } -- 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/cursor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/cursor.c') diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 32ee1d6c08..9434f33ae5 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -20,7 +20,7 @@ #include "nvim/option.h" #include "nvim/option_vars.h" #include "nvim/plines.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/state.h" #include "nvim/vim.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/cursor.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/cursor.c') diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 9434f33ae5..1110fe1e64 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -3,15 +3,15 @@ #include #include -#include "nvim/ascii.h" -#include "nvim/assert.h" +#include "nvim/ascii_defs.h" +#include "nvim/assert_defs.h" #include "nvim/buffer_defs.h" #include "nvim/change.h" #include "nvim/cursor.h" #include "nvim/drawscreen.h" #include "nvim/fold.h" #include "nvim/globals.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/mark.h" #include "nvim/mbyte.h" #include "nvim/memline.h" @@ -22,7 +22,7 @@ #include "nvim/plines.h" #include "nvim/pos_defs.h" #include "nvim/state.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "cursor.c.generated.h" -- cgit