diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 17:57:01 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-01-25 17:57:01 +0000 |
commit | 9837de570c5972f98e74848edc97c297a13136ea (patch) | |
tree | cc948611912d116a3f98a744e690d3d7b6e2f59a /src/nvim/textformat.c | |
parent | c367400b73d207833d51e09d663f969ffab37531 (diff) | |
parent | 3c48d3c83fc21dbc0841f9210f04bdb073d73cd1 (diff) | |
download | rneovim-9837de570c5972f98e74848edc97c297a13136ea.tar.gz rneovim-9837de570c5972f98e74848edc97c297a13136ea.tar.bz2 rneovim-9837de570c5972f98e74848edc97c297a13136ea.zip |
Merge remote-tracking branch 'upstream/master' into colorcolchar
Diffstat (limited to 'src/nvim/textformat.c')
-rw-r--r-- | src/nvim/textformat.c | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/src/nvim/textformat.c b/src/nvim/textformat.c index 25728ef0f1..fbea1ccfb7 100644 --- a/src/nvim/textformat.c +++ b/src/nvim/textformat.c @@ -4,20 +4,29 @@ // textformat.c: text formatting functions #include <stdbool.h> +#include <stdint.h> +#include <string.h> #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" @@ -117,13 +127,13 @@ 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 = (char_u *)get_cursor_line_ptr(); - leader_len = get_leader_len((char *)line, NULL, false, true); + char *line = get_cursor_line_ptr(); + leader_len = get_leader_len(line, NULL, false, true); if (leader_len == 0 && curbuf->b_p_cin) { // Check for a line comment after code. - int comment_start = check_linecomment((char *)line); + int comment_start = check_linecomment(line); if (comment_start != MAXCOL) { - leader_len = get_leader_len((char *)line + comment_start, NULL, false, true); + leader_len = get_leader_len(line + comment_start, NULL, false, true); if (leader_len != 0) { leader_len += comment_start; } @@ -465,14 +475,14 @@ 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; + char *flags = NULL; // init for GCC + char *ptr; - ptr = (char_u *)ml_get(lnum); + ptr = ml_get(lnum); if (do_comments) { - *leader_len = get_leader_len((char *)ptr, (char **)leader_flags, false, true); + *leader_len = get_leader_len(ptr, leader_flags, false, true); } else { *leader_len = 0; } @@ -485,7 +495,7 @@ static int fmt_check_par(linenr_T lnum, int *leader_len, char_u **leader_flags, } } - return *skipwhite((char *)ptr + *leader_len) == NUL + return *skipwhite(ptr + *leader_len) == NUL || (*leader_len > 0 && *flags == COM_END) || startPS(lnum, NUL, false); } @@ -493,14 +503,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. @@ -534,7 +544,8 @@ static bool same_leader(linenr_T lnum, int leader1_len, char *leader1_flags, int return false; } if (*p == COM_START) { - if (*(ml_get(lnum) + leader1_len) == NUL) { + int line_len = (int)strlen(ml_get(lnum)); + if (line_len <= leader1_len) { return false; } if (leader2_flags == NULL || leader2_len == 0) { @@ -577,16 +588,16 @@ static bool same_leader(linenr_T lnum, int leader1_len, char *leader1_flags, int /// false when the previous line is in the same paragraph. static bool paragraph_start(linenr_T lnum) { - char_u *p; + char *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 } - p = (char_u *)ml_get(lnum - 1); + p = ml_get(lnum - 1); if (*p == NUL) { return true; // after empty line } @@ -605,8 +616,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; @@ -914,8 +925,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; @@ -1018,14 +1029,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; } |