From 27177e581902967dcf4f2f426464da1b636ca420 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 11 Feb 2023 14:14:24 +0100 Subject: refactor: reduce scope of locals as per the style guide (#22211) --- src/nvim/textobject.c | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) (limited to 'src/nvim/textobject.c') diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index 8e786c271c..37f893ecec 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -176,7 +176,6 @@ found: bool findpar(bool *pincl, int dir, long count, int what, bool both) { linenr_T curr; - bool did_skip; // true after separating lines have been skipped bool first; // true on first line linenr_T fold_first; // first line of a closed fold linenr_T fold_last; // last line of a closed fold @@ -186,7 +185,7 @@ bool findpar(bool *pincl, int dir, long count, int what, bool both) curr = curwin->w_cursor.lnum; while (count--) { - did_skip = false; + bool did_skip = false; // true after separating lines have been skipped for (first = true;; first = false) { if (*ml_get(curr) != NUL) { did_skip = true; @@ -324,10 +323,6 @@ static int cls(void) /// @param bigword "W", "E" or "B" int fwd_word(long count, bool bigword, bool eol) { - int sclass; // starting class - int i; - int last_line; - curwin->w_cursor.coladd = 0; cls_bigword = bigword; while (--count >= 0) { @@ -336,12 +331,12 @@ int fwd_word(long count, bool bigword, bool eol) if (hasFolding(curwin->w_cursor.lnum, NULL, &curwin->w_cursor.lnum)) { coladvance(MAXCOL); } - sclass = cls(); + int sclass = cls(); // starting class // We always move at least one character, unless on the last // character in the buffer. - last_line = (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count); - i = inc_cursor(); + int last_line = (curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count); + int i = inc_cursor(); if (i == -1 || (i >= 1 && last_line)) { // started at last char in file return FAIL; } @@ -493,13 +488,11 @@ finished: /// @return FAIL if start of the file was reached. int bckend_word(long count, bool bigword, bool eol) { - int sclass; // starting class - int i; - curwin->w_cursor.coladd = 0; cls_bigword = bigword; while (--count >= 0) { - sclass = cls(); + int i; + int sclass = cls(); // starting class if ((i = dec_cursor()) == -1) { return FAIL; } @@ -562,10 +555,8 @@ static void back_in_line(void) static void find_first_blank(pos_T *posp) { - int c; - while (decl(posp) != -1) { - c = gchar_pos(posp); + int c = gchar_pos(posp); if (!ascii_iswhite(c)) { incl(posp); break; @@ -598,7 +589,6 @@ static void findsent_forward(long count, bool at_start_sent) int current_word(oparg_T *oap, long count, bool include, bool bigword) { pos_T start_pos; - pos_T pos; bool inclusive = true; int include_white = false; @@ -703,7 +693,7 @@ int current_word(oparg_T *oap, long count, bool include, bool bigword) // word). Also when "2daw" deletes "word." at the end of the line // (cursor is at start of next line). // But don't delete white space at start of line (indent). - pos = curwin->w_cursor; // save cursor position + pos_T pos = curwin->w_cursor; // save cursor position curwin->w_cursor = start_pos; if (oneleft() == OK) { back_in_line(); @@ -1042,7 +1032,6 @@ static bool in_html_tag(bool end_tag) { char *line = get_cursor_line_ptr(); char *p; - int c; int lc = NUL; pos_T pos; @@ -1078,7 +1067,7 @@ static bool in_html_tag(bool end_tag) if (inc(&pos) < 0) { return false; } - c = (uint8_t)(*ml_get_pos(&pos)); + int c = (uint8_t)(*ml_get_pos(&pos)); if (c == '>') { break; } @@ -1443,10 +1432,8 @@ extend: /// @return column number of "quotechar" or -1 when not found. static int find_next_quote(char *line, int col, int quotechar, char *escape) { - int c; - for (;;) { - c = (uint8_t)line[col]; + int c = (uint8_t)line[col]; if (c == NUL) { return -1; } else if (escape != NULL && vim_strchr(escape, c)) { @@ -1471,12 +1458,10 @@ static int find_next_quote(char *line, int col, int quotechar, char *escape) /// @return the found column or zero. static int find_prev_quote(char *line, int col_start, int quotechar, char *escape) { - int n; - while (col_start > 0) { col_start--; col_start -= utf_head_off(line, line + col_start); - n = 0; + int n = 0; if (escape != NULL) { while (col_start - n > 0 && vim_strchr(escape, (uint8_t)line[col_start - n - 1]) != NULL) { -- 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/textobject.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/textobject.c') diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index 37f893ecec..6683fbe8f4 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -25,7 +25,6 @@ #include "nvim/normal.h" #include "nvim/option_defs.h" #include "nvim/pos.h" -#include "nvim/screen.h" #include "nvim/search.h" #include "nvim/strings.h" #include "nvim/textobject.h" -- 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/textobject.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/textobject.c') diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index 6683fbe8f4..428b14a68d 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -104,7 +104,7 @@ int findsent(Direction dir, long count) const int startlnum = pos.lnum; const bool cpo_J = vim_strchr(p_cpo, CPO_ENDOFSENT) != NULL; - for (;;) { // find end of sentence + while (true) { // find end of sentence c = gchar_pos(&pos); if (c == NUL || (pos.col == 0 && startPS(pos.lnum, NUL, false))) { if (dir == BACKWARD && pos.lnum != startlnum) { @@ -540,7 +540,7 @@ static void back_in_line(void) int sclass; // starting class sclass = cls(); - for (;;) { + while (true) { if (curwin->w_cursor.col == 0) { // stop at start of line break; } @@ -1062,7 +1062,7 @@ static bool in_html_tag(bool end_tag) } // check that the matching '>' is not preceded by '/' - for (;;) { + while (true) { if (inc(&pos) < 0) { return false; } @@ -1304,7 +1304,7 @@ extend: start_lnum -= dir; break; } - for (;;) { + while (true) { if (start_lnum == (dir == BACKWARD ? 1 : curbuf->b_ml.ml_line_count)) { break; @@ -1431,7 +1431,7 @@ extend: /// @return column number of "quotechar" or -1 when not found. static int find_next_quote(char *line, int col, int quotechar, char *escape) { - for (;;) { + while (true) { int c = (uint8_t)line[col]; if (c == NUL) { return -1; @@ -1605,7 +1605,7 @@ bool current_quote(oparg_T *oap, long count, bool include, int quotechar) // Also do this when there is a Visual area, a' may leave the cursor // in between two strings. col_start = 0; - for (;;) { + while (true) { // Find open quote character. col_start = find_next_quote(line, col_start, quotechar, NULL); if (col_start < 0 || col_start > first_col) { -- cgit From 5887ecab6ddd294f43ff3f2372149ce8c5f8dc7f Mon Sep 17 00:00:00 2001 From: luukvbaal Date: Tue, 16 May 2023 01:56:06 +0200 Subject: vim-patch:9.0.1561: display wrong when moving cursor to above the top line (#23644) Problem: Display wrong when moving cursor to above the top line and 'smoothscroll' is set. Solution: Call adjust_skipcol() in more places and make it work better. (Luuk van Baal, closes vim/vim#12395) https://github.com/vim/vim/commit/798fa76dbf737f855e47b10bf326453866b429ab --- src/nvim/textobject.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/textobject.c') diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index 428b14a68d..5036c10827 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -22,6 +22,7 @@ #include "nvim/mbyte.h" #include "nvim/memline.h" #include "nvim/memory.h" +#include "nvim/move.h" #include "nvim/normal.h" #include "nvim/option_defs.h" #include "nvim/pos.h" @@ -414,6 +415,7 @@ int bck_word(long count, bool bigword, bool stop) finished: stop = false; } + adjust_skipcol(); return OK; } @@ -518,6 +520,7 @@ int bckend_word(long count, bool bigword, bool eol) } } } + adjust_skipcol(); return OK; } -- 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/textobject.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'src/nvim/textobject.c') diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index 5036c10827..c40888b85d 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -40,7 +40,7 @@ /// sentence when found. If the next sentence is found, return OK. Return FAIL /// otherwise. See ":h sentence" for the precise definition of a "sentence" /// text object. -int findsent(Direction dir, long count) +int findsent(Direction dir, int count) { pos_T pos, tpos; int c; @@ -173,7 +173,7 @@ found: /// @param pincl Return: true if last char is to be included /// /// @return true if the next paragraph or section was found. -bool findpar(bool *pincl, int dir, long count, int what, bool both) +bool findpar(bool *pincl, int dir, int count, int what, bool both) { linenr_T curr; bool first; // true on first line @@ -321,7 +321,7 @@ static int cls(void) /// If eol is true, last word stops at end of line (for operators). /// /// @param bigword "W", "E" or "B" -int fwd_word(long count, bool bigword, bool eol) +int fwd_word(int count, bool bigword, bool eol) { curwin->w_cursor.coladd = 0; cls_bigword = bigword; @@ -375,7 +375,7 @@ int fwd_word(long count, bool bigword, bool eol) /// If stop is true and we are already on the start of a word, move one less. /// /// Returns FAIL if top of the file was reached. -int bck_word(long count, bool bigword, bool stop) +int bck_word(int count, bool bigword, bool stop) { int sclass; // starting class @@ -432,7 +432,7 @@ finished: /// /// If stop is true and we are already on the end of a word, move one less. /// If empty is true stop on an empty line. -int end_word(long count, bool bigword, bool stop, bool empty) +int end_word(int count, bool bigword, bool stop, bool empty) { int sclass; // starting class @@ -487,7 +487,7 @@ finished: /// @param eol if true, then stop at end of line. /// /// @return FAIL if start of the file was reached. -int bckend_word(long count, bool bigword, bool eol) +int bckend_word(int count, bool bigword, bool eol) { curwin->w_cursor.coladd = 0; cls_bigword = bigword; @@ -569,7 +569,7 @@ static void find_first_blank(pos_T *posp) /// Skip count/2 sentences and count/2 separating white spaces. /// /// @param at_start_sent cursor is at start of sentence -static void findsent_forward(long count, bool at_start_sent) +static void findsent_forward(int count, bool at_start_sent) { while (count--) { findsent(FORWARD, 1L); @@ -588,7 +588,7 @@ static void findsent_forward(long count, bool at_start_sent) /// /// @param include true: include word and white space /// @param bigword false == word, true == WORD -int current_word(oparg_T *oap, long count, bool include, bool bigword) +int current_word(oparg_T *oap, int count, bool include, bool bigword) { pos_T start_pos; bool inclusive = true; @@ -727,7 +727,7 @@ int current_word(oparg_T *oap, long count, bool include, bool bigword) /// Find sentence(s) under the cursor, cursor at end. /// When Visual active, extend it by one or more sentences. -int current_sent(oparg_T *oap, long count, bool include) +int current_sent(oparg_T *oap, int count, bool include) { pos_T start_pos; pos_T pos; @@ -839,7 +839,7 @@ extend: } } if (ncount > 0) { - findsent_forward(ncount, true); + findsent_forward((int)ncount, true); } else { decl(&curwin->w_cursor); } @@ -890,7 +890,7 @@ extend: /// @param include true == include white space /// @param what '(', '{', etc. /// @param other ')', '}', etc. -int current_block(oparg_T *oap, long count, bool include, int what, int other) +int current_block(oparg_T *oap, int count, bool include, int what, int other) { pos_T old_pos; pos_T *pos = NULL; @@ -1081,9 +1081,9 @@ static bool in_html_tag(bool end_tag) /// Find tag block under the cursor, cursor at end. /// /// @param include true == include white space -int current_tagblock(oparg_T *oap, long count_arg, bool include) +int current_tagblock(oparg_T *oap, int count_arg, bool include) { - long count = count_arg; + int count = count_arg; pos_T old_pos; pos_T start_pos; pos_T end_pos; @@ -1265,7 +1265,7 @@ theend: /// @param include true == include white space /// @param type 'p' for paragraph, 'S' for section -int current_par(oparg_T *oap, long count, bool include, int type) +int current_par(oparg_T *oap, int count, bool include, int type) { linenr_T start_lnum; linenr_T end_lnum; @@ -1292,7 +1292,7 @@ extend: } else { dir = FORWARD; } - for (i = (int)count; --i >= 0;) { + for (i = count; --i >= 0;) { if (start_lnum == (dir == BACKWARD ? 1 : curbuf->b_ml.ml_line_count)) { retval = FAIL; @@ -1357,7 +1357,7 @@ extend: } end_lnum--; - i = (int)count; + i = count; if (!include && white_in_front) { i--; } @@ -1485,7 +1485,7 @@ static int find_prev_quote(char *line, int col_start, int quotechar, char *escap /// @param quotechar Quote character /// /// @return true if found, else false. -bool current_quote(oparg_T *oap, long count, bool include, int quotechar) +bool current_quote(oparg_T *oap, int count, bool include, int quotechar) FUNC_ATTR_NONNULL_ALL { char *line = get_cursor_line_ptr(); -- 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/textobject.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/textobject.c') diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index c40888b85d..a3b0f4b658 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -9,7 +9,6 @@ #include #include "nvim/ascii.h" -#include "nvim/buffer_defs.h" #include "nvim/cursor.h" #include "nvim/drawscreen.h" #include "nvim/edit.h" -- 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/textobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/textobject.c') diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index a3b0f4b658..18a56c74ca 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -23,7 +23,7 @@ #include "nvim/memory.h" #include "nvim/move.h" #include "nvim/normal.h" -#include "nvim/option_defs.h" +#include "nvim/option_vars.h" #include "nvim/pos.h" #include "nvim/search.h" #include "nvim/strings.h" -- 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/textobject.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/textobject.c') diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index 18a56c74ca..3d156ba24e 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -733,7 +733,7 @@ int current_sent(oparg_T *oap, int count, bool include) bool start_blank; int c; bool at_start_sent; - long ncount; + int ncount; start_pos = curwin->w_cursor; pos = start_pos; @@ -838,7 +838,7 @@ extend: } } if (ncount > 0) { - findsent_forward((int)ncount, true); + findsent_forward(ncount, true); } else { decl(&curwin->w_cursor); } @@ -1142,7 +1142,7 @@ int current_tagblock(oparg_T *oap, int count_arg, bool include) again: // Search backwards for unclosed "". // Put this position in start_pos. - for (long n = 0; n < count; n++) { + for (int n = 0; n < count; n++) { if (do_searchpair("<[^ \t>/!]\\+\\%(\\_s\\_[^>]\\{-}[^/]>\\|$\\|\\_s\\=>\\)", "", "]*>", BACKWARD, NULL, 0, -- 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/textobject.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/nvim/textobject.c') diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index 3d156ba24e..53424506f3 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -571,7 +571,7 @@ static void find_first_blank(pos_T *posp) static void findsent_forward(int count, bool at_start_sent) { while (count--) { - findsent(FORWARD, 1L); + findsent(FORWARD, 1); if (at_start_sent) { find_first_blank(&curwin->w_cursor); } @@ -612,7 +612,7 @@ int current_word(oparg_T *oap, int count, bool include, bool bigword) // (" word"), or start is not on white space, and white space should // not be included ("word"), find end of word. if ((cls() == 0) == include) { - if (end_word(1L, bigword, true, true) == FAIL) { + if (end_word(1, bigword, true, true) == FAIL) { return FAIL; } } else { @@ -621,7 +621,7 @@ int current_word(oparg_T *oap, int count, bool include, bool bigword) // space should not be included (" "), find start of word. // If we end up in the first column of the next line (single char // word) back up to end of the line. - fwd_word(1L, bigword, true); + fwd_word(1, bigword, true); if (curwin->w_cursor.col == 0) { decl(&curwin->w_cursor); } else { @@ -653,11 +653,11 @@ int current_word(oparg_T *oap, int count, bool include, bool bigword) return FAIL; } if (include != (cls() != 0)) { - if (bck_word(1L, bigword, true) == FAIL) { + if (bck_word(1, bigword, true) == FAIL) { return FAIL; } } else { - if (bckend_word(1L, bigword, true) == FAIL) { + if (bckend_word(1, bigword, true) == FAIL) { return FAIL; } (void)incl(&curwin->w_cursor); @@ -668,7 +668,7 @@ int current_word(oparg_T *oap, int count, bool include, bool bigword) return FAIL; } if (include != (cls() == 0)) { - if (fwd_word(1L, bigword, true) == FAIL && count > 1) { + if (fwd_word(1, bigword, true) == FAIL && count > 1) { return FAIL; } // If end is just past a new-line, we don't want to include @@ -678,7 +678,7 @@ int current_word(oparg_T *oap, int count, bool include, bool bigword) inclusive = false; } } else { - if (end_word(1L, bigword, true, true) == FAIL) { + if (end_word(1, bigword, true, true) == FAIL) { return FAIL; } } @@ -737,7 +737,7 @@ int current_sent(oparg_T *oap, int count, bool include) start_pos = curwin->w_cursor; pos = start_pos; - findsent(FORWARD, 1L); // Find start of next sentence. + findsent(FORWARD, 1); // Find start of next sentence. // When the Visual area is bigger than one character: Extend it. if (VIsual_active && !equalpos(start_pos, VIsual)) { @@ -759,12 +759,12 @@ extend: incl(&pos); } if (!at_start_sent) { - findsent(BACKWARD, 1L); + findsent(BACKWARD, 1); if (equalpos(curwin->w_cursor, start_pos)) { at_start_sent = true; // exactly at start of sentence } else { // inside a sentence, go to its end (start of next) - findsent(FORWARD, 1L); + findsent(FORWARD, 1); } } if (include) { // "as" gets twice as much as "is" @@ -776,7 +776,7 @@ extend: } c = gchar_cursor(); if (!at_start_sent || (!include && !ascii_iswhite(c))) { - findsent(BACKWARD, 1L); + findsent(BACKWARD, 1); } at_start_sent = !at_start_sent; } @@ -799,7 +799,7 @@ extend: incl(&pos); } if (at_start_sent) { // in the sentence - findsent(BACKWARD, 1L); + findsent(BACKWARD, 1); } else { // in/before white before a sentence curwin->w_cursor = start_pos; } @@ -826,7 +826,7 @@ extend: find_first_blank(&start_pos); // go back to first blank } else { start_blank = false; - findsent(BACKWARD, 1L); + findsent(BACKWARD, 1); start_pos = curwin->w_cursor; } if (include) { @@ -1146,7 +1146,7 @@ again: if (do_searchpair("<[^ \t>/!]\\+\\%(\\_s\\_[^>]\\{-}[^/]>\\|$\\|\\_s\\=>\\)", "", "]*>", BACKWARD, NULL, 0, - NULL, (linenr_T)0, 0L) <= 0) { + NULL, (linenr_T)0, 0) <= 0) { curwin->w_cursor = old_pos; goto theend; } @@ -1172,7 +1172,7 @@ again: "<%.*s\\>\\%%(\\_s\\_[^>]\\{-}\\_[^/]>\\|\\_s\\?>\\)\\c", len, p); snprintf(epat, epat_len, "\\c", len, p); - const int r = (int)do_searchpair(spat, "", epat, FORWARD, NULL, 0, NULL, (linenr_T)0, 0L); + const int r = do_searchpair(spat, "", epat, FORWARD, NULL, 0, NULL, (linenr_T)0, 0); xfree(spat); xfree(epat); -- 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/textobject.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/textobject.c') diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index 53424506f3..c17273255d 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -1146,7 +1146,7 @@ again: if (do_searchpair("<[^ \t>/!]\\+\\%(\\_s\\_[^>]\\{-}[^/]>\\|$\\|\\_s\\=>\\)", "", "]*>", BACKWARD, NULL, 0, - NULL, (linenr_T)0, 0) <= 0) { + NULL, 0, 0) <= 0) { curwin->w_cursor = old_pos; goto theend; } @@ -1172,7 +1172,7 @@ again: "<%.*s\\>\\%%(\\_s\\_[^>]\\{-}\\_[^/]>\\|\\_s\\?>\\)\\c", len, p); snprintf(epat, epat_len, "\\c", len, p); - const int r = do_searchpair(spat, "", epat, FORWARD, NULL, 0, NULL, (linenr_T)0, 0); + const int r = do_searchpair(spat, "", epat, FORWARD, NULL, 0, NULL, 0, 0); xfree(spat); xfree(epat); -- 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/textobject.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/textobject.c') diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index c17273255d..00038c7d6d 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.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 - // textobject.c: functions for text objects #include -- cgit From ac1113ded5f8f09dd99a9894d7a7e795626fb728 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 13 Nov 2023 23:40:37 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment --- src/nvim/textobject.c | 61 +++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 39 deletions(-) (limited to 'src/nvim/textobject.c') diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index 00038c7d6d..a0a33b17a3 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -38,12 +38,11 @@ /// text object. int findsent(Direction dir, int count) { - pos_T pos, tpos; int c; int (*func)(pos_T *); bool noskip = false; // do not skip blanks - pos = curwin->w_cursor; + pos_T pos = curwin->w_cursor; if (dir == FORWARD) { func = incl; } else { @@ -80,7 +79,7 @@ int findsent(Direction dir, int count) bool found_dot = false; while (c = gchar_pos(&pos), ascii_iswhite(c) || vim_strchr(".!?)]\"'", c) != NULL) { - tpos = pos; + pos_T tpos = pos; if (decl(&tpos) == -1 || (LINEEMPTY(tpos.lnum) && dir == FORWARD)) { break; } @@ -110,7 +109,7 @@ int findsent(Direction dir, int count) break; } if (c == '.' || c == '!' || c == '?') { - tpos = pos; + pos_T tpos = pos; do { if ((c = inc(&tpos)) == -1) { break; @@ -888,17 +887,14 @@ extend: /// @param other ')', '}', etc. int current_block(oparg_T *oap, int count, bool include, int what, int other) { - pos_T old_pos; pos_T *pos = NULL; pos_T start_pos; pos_T *end_pos; - pos_T old_start, old_end; - char *save_cpo; bool sol = false; // '{' at start of line - old_pos = curwin->w_cursor; - old_end = curwin->w_cursor; // remember where we started - old_start = old_end; + pos_T old_pos = curwin->w_cursor; + pos_T old_end = curwin->w_cursor; // remember where we started + pos_T old_start = old_end; // If we start on '(', '{', ')', '}', etc., use the whole block inclusive. if (!VIsual_active || equalpos(VIsual, curwin->w_cursor)) { @@ -925,7 +921,7 @@ int current_block(oparg_T *oap, int count, bool include, int what, int other) // Put this position in start_pos. // Ignore quotes here. Keep the "M" flag in 'cpo', as that is what the // user wants. - save_cpo = p_cpo; + char *save_cpo = p_cpo; p_cpo = vim_strchr(p_cpo, CPO_MATCHBSL) != NULL ? "%M" : "%"; if ((pos = findmatch(NULL, what)) != NULL) { while (count-- > 0) { @@ -1080,13 +1076,7 @@ static bool in_html_tag(bool end_tag) int current_tagblock(oparg_T *oap, int count_arg, bool include) { int count = count_arg; - pos_T old_pos; - pos_T start_pos; - pos_T end_pos; - pos_T old_start, old_end; - char *p; char *cp; - int len; bool do_include = include; bool save_p_ws = p_ws; int retval = FAIL; @@ -1094,9 +1084,9 @@ int current_tagblock(oparg_T *oap, int count_arg, bool include) p_ws = false; - old_pos = curwin->w_cursor; - old_end = curwin->w_cursor; // remember where we started - old_start = old_end; + pos_T old_pos = curwin->w_cursor; + pos_T old_end = curwin->w_cursor; // remember where we started + pos_T old_start = old_end; if (!VIsual_active || *p_sel == 'e') { decl(&old_end); // old_end is inclusive } @@ -1148,15 +1138,15 @@ again: goto theend; } } - start_pos = curwin->w_cursor; + pos_T start_pos = curwin->w_cursor; // Search for matching "". First isolate the "aaa". inc_cursor(); - p = get_cursor_pos_ptr(); + char *p = get_cursor_pos_ptr(); for (cp = p; *cp != NUL && *cp != '>' && !ascii_iswhite(*cp); MB_PTR_ADV(cp)) {} - len = (int)(cp - p); + int len = (int)(cp - p); if (len == 0) { curwin->w_cursor = old_pos; goto theend; @@ -1202,7 +1192,7 @@ again: dec_cursor(); } } - end_pos = curwin->w_cursor; + pos_T end_pos = curwin->w_cursor; if (!do_include) { // Exclude the start tag. @@ -1263,22 +1253,15 @@ theend: /// @param type 'p' for paragraph, 'S' for section int current_par(oparg_T *oap, int count, bool include, int type) { - linenr_T start_lnum; - linenr_T end_lnum; - int white_in_front; int dir; - int start_is_white; - int prev_start_is_white; int retval = OK; int do_white = false; - int t; - int i; if (type == 'S') { // not implemented yet return FAIL; } - start_lnum = curwin->w_cursor.lnum; + linenr_T start_lnum = curwin->w_cursor.lnum; // When visual area is more than one line: extend it. if (VIsual_active && start_lnum != VIsual.lnum) { @@ -1288,17 +1271,17 @@ extend: } else { dir = FORWARD; } - for (i = count; --i >= 0;) { + for (int i = count; --i >= 0;) { if (start_lnum == (dir == BACKWARD ? 1 : curbuf->b_ml.ml_line_count)) { retval = FAIL; break; } - prev_start_is_white = -1; - for (t = 0; t < 2; t++) { + int prev_start_is_white = -1; + for (int t = 0; t < 2; t++) { start_lnum += dir; - start_is_white = linewhite(start_lnum); + int start_is_white = linewhite(start_lnum); if (prev_start_is_white == start_is_white) { start_lnum -= dir; break; @@ -1332,7 +1315,7 @@ extend: } // First move back to the start_lnum of the paragraph or white lines - white_in_front = linewhite(start_lnum); + int white_in_front = linewhite(start_lnum); while (start_lnum > 1) { if (white_in_front) { // stop at first white line if (!linewhite(start_lnum - 1)) { @@ -1347,13 +1330,13 @@ extend: } // Move past the end of any white lines. - end_lnum = start_lnum; + linenr_T end_lnum = start_lnum; while (end_lnum <= curbuf->b_ml.ml_line_count && linewhite(end_lnum)) { end_lnum++; } end_lnum--; - i = count; + int i = count; if (!include && white_in_front) { i--; } -- 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/textobject.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/textobject.c') diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index a0a33b17a3..11db5697f0 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -11,6 +11,7 @@ #include "nvim/edit.h" #include "nvim/eval/funcs.h" #include "nvim/fold.h" +#include "nvim/func_attr.h" #include "nvim/globals.h" #include "nvim/indent.h" #include "nvim/macros.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/textobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/textobject.c') diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index 11db5697f0..d5025fde6b 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -22,7 +22,7 @@ #include "nvim/move.h" #include "nvim/normal.h" #include "nvim/option_vars.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/search.h" #include "nvim/strings.h" #include "nvim/textobject.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/textobject.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/textobject.c') diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index d5025fde6b..3a0a3cc659 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -5,7 +5,7 @@ #include #include -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/cursor.h" #include "nvim/drawscreen.h" #include "nvim/edit.h" @@ -14,7 +14,7 @@ #include "nvim/func_attr.h" #include "nvim/globals.h" #include "nvim/indent.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/mark.h" #include "nvim/mbyte.h" #include "nvim/memline.h" @@ -26,7 +26,7 @@ #include "nvim/search.h" #include "nvim/strings.h" #include "nvim/textobject.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "textobject.c.generated.h" -- cgit From 64b53b71ba5d804b2c8cf186be68931b2621f53c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 12:10:42 +0800 Subject: refactor(IWYU): create normal_defs.h (#26293) --- src/nvim/textobject.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/textobject.c') diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index 3a0a3cc659..d4310d47a4 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -20,7 +20,6 @@ #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/move.h" -#include "nvim/normal.h" #include "nvim/option_vars.h" #include "nvim/pos_defs.h" #include "nvim/search.h" -- cgit