From fb1edb2f5728d74ae811c6ab32395598cea5609b Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/textformat.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/textformat.c') diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c index 125146f712..5ded0c9ab2 100644 --- a/src/nvim/textformat.c +++ b/src/nvim/textformat.c @@ -470,7 +470,7 @@ static int fmt_check_par(linenr_T lnum, int *leader_len, char_u **leader_flags, char_u *flags = NULL; // init for GCC char_u *ptr; - ptr = ml_get(lnum); + ptr = (char_u *)ml_get(lnum); if (do_comments) { *leader_len = get_leader_len((char *)ptr, (char **)leader_flags, false, true); } else { @@ -493,7 +493,7 @@ static int fmt_check_par(linenr_T lnum, int *leader_len, char_u **leader_flags, /// @return true if line "lnum" ends in a white character. static bool ends_in_white(linenr_T lnum) { - char_u *s = ml_get(lnum); + char_u *s = (char_u *)ml_get(lnum); size_t l; if (*s == NUL) { @@ -552,9 +552,9 @@ static bool same_leader(linenr_T lnum, int leader1_len, char_u *leader1_flags, i // Get current line and next line, compare the leaders. // The first line has to be saved, only one line can be locked at a time. - line1 = vim_strsave(ml_get(lnum)); + line1 = vim_strsave((char_u *)ml_get(lnum)); for (idx1 = 0; ascii_iswhite(line1[idx1]); idx1++) {} - line2 = ml_get(lnum + 1); + line2 = (char_u *)ml_get(lnum + 1); for (idx2 = 0; idx2 < leader2_len; idx2++) { if (!ascii_iswhite(line2[idx2])) { if (line1[idx1++] != line2[idx2]) { @@ -586,7 +586,7 @@ static bool paragraph_start(linenr_T lnum) if (lnum <= 1) { return true; // start of the file } - p = ml_get(lnum - 1); + p = (char_u *)ml_get(lnum - 1); if (*p == NUL) { return true; // after empty line } -- cgit From 49e893f296bca9eef5ff45a3d746c261d055bf10 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/textformat.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/textformat.c') diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c index 5ded0c9ab2..6e69fb95c8 100644 --- a/src/nvim/textformat.c +++ b/src/nvim/textformat.c @@ -117,7 +117,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on // Don't break until after the comment leader if (do_comments) { - char_u *line = get_cursor_line_ptr(); + char_u *line = (char_u *)get_cursor_line_ptr(); leader_len = get_leader_len((char *)line, NULL, false, true); if (leader_len == 0 && curbuf->b_p_cin) { // Check for a line comment after code. @@ -624,8 +624,8 @@ void auto_format(bool trailblank, bool prev_line) { pos_T pos; colnr_T len; - char_u *old; - char_u *new, *pnew; + char *old; + char *new, *pnew; int wasatend; int cc; @@ -663,7 +663,7 @@ void auto_format(bool trailblank, bool prev_line) // With the 'c' flag in 'formatoptions' and 't' missing: only format // comments. if (has_format_option(FO_WRAP_COMS) && !has_format_option(FO_WRAP) - && get_leader_len((char *)old, NULL, false, true) == 0) { + && get_leader_len(old, NULL, false, true) == 0) { return; } @@ -700,10 +700,10 @@ void auto_format(bool trailblank, bool prev_line) new = get_cursor_line_ptr(); len = (colnr_T)STRLEN(new); if (curwin->w_cursor.col == len) { - pnew = vim_strnsave(new, (size_t)len + 2); + pnew = xstrnsave(new, (size_t)len + 2); pnew[len] = ' '; pnew[len + 1] = NUL; - ml_replace(curwin->w_cursor.lnum, (char *)pnew, false); + ml_replace(curwin->w_cursor.lnum, pnew, false); // remove the space later did_add_space = true; } else { @@ -1026,7 +1026,7 @@ void format_lines(linenr_T line_count, bool avoid_fex) // paragraph doesn't really end. if (next_leader_flags == NULL || STRNCMP(next_leader_flags, "://", 3) != 0 - || check_linecomment((char *)get_cursor_line_ptr()) == MAXCOL) { + || check_linecomment(get_cursor_line_ptr()) == MAXCOL) { is_end_par = true; } } -- cgit From 73207cae611a1efb8cd17139e8228772daeb9866 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/textformat.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/nvim/textformat.c') diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c index 6e69fb95c8..5c53f84700 100644 --- a/src/nvim/textformat.c +++ b/src/nvim/textformat.c @@ -97,7 +97,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on colnr_T len; colnr_T virtcol; int orig_col = 0; - char_u *saved_text = NULL; + char *saved_text = NULL; colnr_T col; colnr_T end_col; bool did_do_comment = false; @@ -353,7 +353,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on if (State & VREPLACE_FLAG) { // In MODE_VREPLACE state, we will backspace over the text to be // wrapped, so save a copy now to put on the next line. - saved_text = vim_strsave(get_cursor_pos_ptr()); + saved_text = xstrdup(get_cursor_pos_ptr()); curwin->w_cursor.col = orig_col; saved_text[startcol] = NUL; @@ -425,7 +425,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on if (State & VREPLACE_FLAG) { // In MODE_VREPLACE state we have backspaced over the text to be // moved, now we re-insert it into the new line. - ins_bytes((char *)saved_text); + ins_bytes(saved_text); xfree(saved_text); } else { // Check if cursor is not past the NUL off the line, cindent @@ -508,13 +508,13 @@ static bool ends_in_white(linenr_T lnum) /// @param lnum The first line. White-space is ignored. /// /// @note the whole of 'leader1' must match 'leader2_len' characters from 'leader2'. -static bool same_leader(linenr_T lnum, int leader1_len, char_u *leader1_flags, int leader2_len, - char_u *leader2_flags) +static bool same_leader(linenr_T lnum, int leader1_len, char *leader1_flags, int leader2_len, + char *leader2_flags) { int idx1 = 0, idx2 = 0; - char_u *p; - char_u *line1; - char_u *line2; + char *p; + char *line1; + char *line2; if (leader1_len == 0) { return leader2_len == 0; @@ -552,9 +552,9 @@ static bool same_leader(linenr_T lnum, int leader1_len, char_u *leader1_flags, i // Get current line and next line, compare the leaders. // The first line has to be saved, only one line can be locked at a time. - line1 = vim_strsave((char_u *)ml_get(lnum)); + line1 = xstrdup(ml_get(lnum)); for (idx1 = 0; ascii_iswhite(line1[idx1]); idx1++) {} - line2 = (char_u *)ml_get(lnum + 1); + line2 = ml_get(lnum + 1); for (idx2 = 0; idx2 < leader2_len; idx2++) { if (!ascii_iswhite(line2[idx2])) { if (line1[idx1++] != line2[idx2]) { @@ -605,8 +605,8 @@ static bool paragraph_start(linenr_T lnum) if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) { return true; // numbered item starts in "lnum". } - if (!same_leader(lnum - 1, leader_len, leader_flags, - next_leader_len, next_leader_flags)) { + if (!same_leader(lnum - 1, leader_len, (char *)leader_flags, + next_leader_len, (char *)next_leader_flags)) { return true; // change of comment leader. } return false; @@ -1018,9 +1018,9 @@ void format_lines(linenr_T line_count, bool avoid_fex) // When the comment leader changes, it's the end of the paragraph. if (curwin->w_cursor.lnum >= curbuf->b_ml.ml_line_count || !same_leader(curwin->w_cursor.lnum, - leader_len, leader_flags, + leader_len, (char *)leader_flags, next_leader_len, - next_leader_flags)) { + (char *)next_leader_flags)) { // Special case: If the next line starts with a line comment // and this line has a line comment after some text, the // paragraph doesn't really end. -- cgit From 3ff46544c9872b4161fd098569c30b55fe3abd36 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/textformat.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/textformat.c') diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c index 5c53f84700..25728ef0f1 100644 --- a/src/nvim/textformat.c +++ b/src/nvim/textformat.c @@ -431,7 +431,7 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on // Check if cursor is not past the NUL off the line, cindent // may have added or removed indent. curwin->w_cursor.col += startcol; - len = (colnr_T)STRLEN(get_cursor_line_ptr()); + len = (colnr_T)strlen(get_cursor_line_ptr()); if (curwin->w_cursor.col > len) { curwin->w_cursor.col = len; } @@ -644,7 +644,7 @@ void auto_format(bool trailblank, bool prev_line) // in 'formatoptions' and there is a single character before the cursor. // Otherwise the line would be broken and when typing another non-white // next they are not joined back together. - wasatend = (pos.col == (colnr_T)STRLEN(old)); + wasatend = (pos.col == (colnr_T)strlen(old)); if (*old != NUL && !trailblank && wasatend) { dec_cursor(); cc = gchar_cursor(); @@ -698,7 +698,7 @@ void auto_format(bool trailblank, bool prev_line) // formatted. if (!wasatend && has_format_option(FO_WHITE_PAR)) { new = get_cursor_line_ptr(); - len = (colnr_T)STRLEN(new); + len = (colnr_T)strlen(new); if (curwin->w_cursor.col == len) { pnew = xstrnsave(new, (size_t)len + 2); pnew[len] = ' '; @@ -1115,7 +1115,7 @@ void format_lines(linenr_T line_count, bool avoid_fex) } first_par_line = false; // If the line is getting long, format it next time - if (STRLEN(get_cursor_line_ptr()) > (size_t)max_len) { + if (strlen(get_cursor_line_ptr()) > (size_t)max_len) { force_format = true; } else { force_format = false; -- cgit From 04cdea5f4ac49fa62cc4091a5c26791b80b4cc4c Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/textformat.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/textformat.c') diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c index 25728ef0f1..61949fec6a 100644 --- a/src/nvim/textformat.c +++ b/src/nvim/textformat.c @@ -493,14 +493,14 @@ static int fmt_check_par(linenr_T lnum, int *leader_len, char_u **leader_flags, /// @return true if line "lnum" ends in a white character. static bool ends_in_white(linenr_T lnum) { - char_u *s = (char_u *)ml_get(lnum); + char *s = ml_get(lnum); size_t l; if (*s == NUL) { return false; } - l = STRLEN(s) - 1; - return ascii_iswhite(s[l]); + l = strlen(s) - 1; + return ascii_iswhite((uint8_t)s[l]); } /// @return true if the two comment leaders given are the same. -- cgit From 66360675cf4d091b7460e4a8e1435c13216c1929 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 11 Sep 2022 17:12:44 +0200 Subject: build: allow IWYU to fix includes for all .c files Allow Include What You Use to remove unnecessary includes and only include what is necessary. This helps with reducing compilation times and makes it easier to visualise which dependencies are actually required. Work on https://github.com/neovim/neovim/issues/549, but doesn't close it since this only works fully for .c files and not headers. --- src/nvim/textformat.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nvim/textformat.c') diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c index 61949fec6a..56efd4cc45 100644 --- a/src/nvim/textformat.c +++ b/src/nvim/textformat.c @@ -4,20 +4,29 @@ // textformat.c: text formatting functions #include +#include +#include #include "nvim/ascii.h" +#include "nvim/buffer_defs.h" #include "nvim/change.h" #include "nvim/charset.h" #include "nvim/cursor.h" #include "nvim/drawscreen.h" #include "nvim/edit.h" #include "nvim/eval.h" +#include "nvim/eval/typval_defs.h" +#include "nvim/ex_cmds_defs.h" #include "nvim/getchar.h" #include "nvim/globals.h" #include "nvim/indent.h" #include "nvim/indent_c.h" +#include "nvim/macros.h" +#include "nvim/mark.h" #include "nvim/mbyte.h" #include "nvim/memline.h" +#include "nvim/memory.h" +#include "nvim/message.h" #include "nvim/move.h" #include "nvim/normal.h" #include "nvim/ops.h" @@ -28,6 +37,7 @@ #include "nvim/strings.h" #include "nvim/textformat.h" #include "nvim/textobject.h" +#include "nvim/types.h" #include "nvim/undo.h" #include "nvim/vim.h" #include "nvim/window.h" -- cgit From 3b96ccf7d35be90e49029dec76344d3d92ad91dc Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 26 Nov 2022 18:57:46 +0100 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/textformat.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/nvim/textformat.c') diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c index 56efd4cc45..4af629d091 100644 --- a/src/nvim/textformat.c +++ b/src/nvim/textformat.c @@ -475,21 +475,21 @@ void internal_format(int textwidth, int second_indent, int flags, bool format_on /// ('e' in comment flags), so that this line is skipped, and not joined to the /// previous line. A new paragraph starts after a blank line, or when the /// comment leader changes. -static int fmt_check_par(linenr_T lnum, int *leader_len, char_u **leader_flags, bool do_comments) +static int fmt_check_par(linenr_T lnum, int *leader_len, char **leader_flags, bool do_comments) { char_u *flags = NULL; // init for GCC char_u *ptr; ptr = (char_u *)ml_get(lnum); if (do_comments) { - *leader_len = get_leader_len((char *)ptr, (char **)leader_flags, false, true); + *leader_len = get_leader_len((char *)ptr, leader_flags, false, true); } else { *leader_len = 0; } if (*leader_len > 0) { // Search for 'e' flag in comment leader flags. - flags = *leader_flags; + flags = (char_u *)(*leader_flags); while (*flags && *flags != ':' && *flags != COM_END) { flags++; } @@ -589,9 +589,9 @@ static bool paragraph_start(linenr_T lnum) { char_u *p; int leader_len = 0; // leader len of current line - char_u *leader_flags = NULL; // flags for leader of current line + char *leader_flags = NULL; // flags for leader of current line int next_leader_len = 0; // leader len of next line - char_u *next_leader_flags = NULL; // flags for leader of next line + char *next_leader_flags = NULL; // flags for leader of next line if (lnum <= 1) { return true; // start of the file @@ -615,8 +615,8 @@ static bool paragraph_start(linenr_T lnum) if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) { return true; // numbered item starts in "lnum". } - if (!same_leader(lnum - 1, leader_len, (char *)leader_flags, - next_leader_len, (char *)next_leader_flags)) { + if (!same_leader(lnum - 1, leader_len, leader_flags, + next_leader_len, next_leader_flags)) { return true; // change of comment leader. } return false; @@ -924,8 +924,8 @@ void format_lines(linenr_T line_count, bool avoid_fex) bool next_is_start_par = false; int leader_len = 0; // leader len of current line int next_leader_len; // leader len of next line - char_u *leader_flags = NULL; // flags for leader of current line - char_u *next_leader_flags = NULL; // flags for leader of next line + char *leader_flags = NULL; // flags for leader of current line + char *next_leader_flags = NULL; // flags for leader of next line bool advance = true; int second_indent = -1; // indent for second line (comment aware) bool first_par_line = true; @@ -1028,14 +1028,14 @@ void format_lines(linenr_T line_count, bool avoid_fex) // When the comment leader changes, it's the end of the paragraph. if (curwin->w_cursor.lnum >= curbuf->b_ml.ml_line_count || !same_leader(curwin->w_cursor.lnum, - leader_len, (char *)leader_flags, + leader_len, leader_flags, next_leader_len, - (char *)next_leader_flags)) { + next_leader_flags)) { // Special case: If the next line starts with a line comment // and this line has a line comment after some text, the // paragraph doesn't really end. if (next_leader_flags == NULL - || STRNCMP(next_leader_flags, "://", 3) != 0 + || strncmp(next_leader_flags, "://", 3) != 0 || check_linecomment(get_cursor_line_ptr()) == MAXCOL) { is_end_par = true; } -- cgit