From 40855b0143a864739a6037921e15699445dcf8a7 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Sun, 31 Jul 2022 16:20:57 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/indent.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index f18a6d7b32..12fad371ae 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -710,7 +710,7 @@ int get_number_indent(linenr_T lnum) if ((State & MODE_INSERT) || has_format_option(FO_Q_COMS)) { lead_len = get_leader_len((char *)ml_get(lnum), NULL, false, true); } - regmatch.regprog = vim_regcomp((char *)curbuf->b_p_flp, RE_MAGIC); + regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC); if (regmatch.regprog != NULL) { regmatch.rm_ic = false; @@ -770,7 +770,7 @@ int get_breakindent_win(win_T *wp, char_u *line) // add additional indent for numbered lists if (wp->w_briopt_list != 0) { regmatch_T regmatch = { - .regprog = vim_regcomp((char *)curbuf->b_p_flp, + .regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT), }; @@ -855,7 +855,7 @@ int get_expr_indent(void) // Need to make a copy, the 'indentexpr' option could be changed while // evaluating it. - char_u *inde_copy = vim_strsave(curbuf->b_p_inde); + char_u *inde_copy = vim_strsave((char_u *)curbuf->b_p_inde); indent = (int)eval_to_number((char *)inde_copy); xfree(inde_copy); @@ -1077,7 +1077,7 @@ static int lisp_match(char_u *p) { char_u buf[LSIZE]; int len; - char *word = (char *)(*curbuf->b_p_lw != NUL ? curbuf->b_p_lw : p_lispwords); + char *word = (char *)(*curbuf->b_p_lw != NUL ? (char_u *)curbuf->b_p_lw : p_lispwords); while (*word != NUL) { (void)copy_option_part(&word, (char *)buf, LSIZE, ","); -- cgit From 6547f4397fe643f194763306f8fcdfc6f6ce4b24 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 26 Aug 2022 18:49:29 +0800 Subject: vim-patch:8.1.2331: the option.c file is still very big (#19954) Problem: The option.c file is still very big. Solution: Move a few functions to where they fit better. (Yegappan Lakshmanan, closes vim/vim#4895) https://github.com/vim/vim/commit/7bae0b1bc84a95d565ffab38cf7f82ad21c656b6 vim-patch:9.0.0271: using INIT() in non-header files Problem: Using INIT() in non-header files. Solution: Remove INIT(). (closes vim/vim#10981) https://github.com/vim/vim/commit/9b7d2a959646560f5770329f4428c4739eed4656 --- src/nvim/indent.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 12fad371ae..c44cd06a2f 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -732,6 +732,47 @@ int get_number_indent(linenr_T lnum) return (int)col; } +/// This is called when 'breakindentopt' is changed and when a window is +/// initialized +bool briopt_check(win_T *wp) +{ + int bri_shift = 0; + int bri_min = 20; + bool bri_sbr = false; + int bri_list = 0; + + char *p = wp->w_p_briopt; + while (*p != NUL) { + if (STRNCMP(p, "shift:", 6) == 0 + && ((p[6] == '-' && ascii_isdigit(p[7])) || ascii_isdigit(p[6]))) { + p += 6; + bri_shift = getdigits_int(&p, true, 0); + } else if (STRNCMP(p, "min:", 4) == 0 && ascii_isdigit(p[4])) { + p += 4; + bri_min = getdigits_int(&p, true, 0); + } else if (STRNCMP(p, "sbr", 3) == 0) { + p += 3; + bri_sbr = true; + } else if (STRNCMP(p, "list:", 5) == 0) { + p += 5; + bri_list = (int)getdigits(&p, false, 0); + } + if (*p != ',' && *p != NUL) { + return false; + } + if (*p == ',') { + p++; + } + } + + wp->w_briopt_shift = bri_shift; + wp->w_briopt_min = bri_min; + wp->w_briopt_sbr = bri_sbr; + wp->w_briopt_list = bri_list; + + return true; +} + // Return appropriate space number for breakindent, taking influencing // parameters into account. Window must be specified, since it is not // necessarily always the current one. -- cgit From 0b72e23bf13ade1e76d11eae6990014098b3928d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 26 Aug 2022 22:37:20 +0800 Subject: vim-patch:8.2.0674: some source files are too big (#19959) Problem: Some source files are too big. Solution: Move text formatting functions to a new file. (Yegappan Lakshmanan, closes vim/vim#6021) https://github.com/vim/vim/commit/11abd095210fc84e5dcee87b9baed86061caefe4 Cherry-pick set_can_cindent() from patch 8.1.2062. Cherry-pick global old_indent from patch 8.2.2127. --- src/nvim/indent.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index c44cd06a2f..c4805283c2 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -25,6 +25,7 @@ #include "nvim/screen.h" #include "nvim/search.h" #include "nvim/strings.h" +#include "nvim/textformat.h" #include "nvim/undo.h" #ifdef INCLUDE_GENERATED_DECLARATIONS -- cgit From 691f4715c0cf4bc11ea2280db8777e6dd174a8ac 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/indent.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index c4805283c2..7c5f291837 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -34,12 +34,13 @@ /// Set the integer values corresponding to the string setting of 'vartabstop'. /// "array" will be set, caller must free it if needed. -/// Return false for an error. -bool tabstop_set(char_u *var, long **array) +/// +/// @return false for an error. +bool tabstop_set(char *var, long **array) { long valcount = 1; int t; - char_u *cp; + char *cp; if (var[0] == NUL || (var[0] == '0' && var[1] == NUL)) { *array = NULL; @@ -50,8 +51,8 @@ bool tabstop_set(char_u *var, long **array) if (cp == var || cp[-1] == ',') { char *end; - if (strtol((char *)cp, &end, 10) <= 0) { - if (cp != (char_u *)end) { + if (strtol(cp, &end, 10) <= 0) { + if (cp != end) { emsg(_(e_positive)); } else { semsg(_(e_invarg2), cp); @@ -76,7 +77,7 @@ bool tabstop_set(char_u *var, long **array) t = 1; for (cp = var; *cp != NUL;) { - int n = atoi((char *)cp); + int n = atoi(cp); // Catch negative values, overflow and ridiculous big values. if (n <= 0 || n > TABSTOP_MAX) { -- cgit From ea4e9c71ccaf406fe7aa6b47d461cdab2d6c01e9 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 27 Aug 2022 11:28:11 +0200 Subject: refactor(plines): use a struct for chartabsize state This is a refactor extracted from vim-patch 9.0.0067: cannot show virtual text The logic for inline virtual text is going to be different in nvim than text property based text in vim, but this refactor is still useful, as calculation of displayed linesize is going to be stateful in a similar way. --- src/nvim/indent.c | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index c4805283c2..8aa8492dae 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -1034,13 +1034,15 @@ int get_lisp_indent(void) amount = 2; } else { char_u *line = that; - - amount = 0; - - while (*that && col) { - amount += lbr_chartabsize_adv(line, &that, (colnr_T)amount); + chartabsize_T cts; + init_chartabsize_arg(&cts, curwin, pos->lnum, 0, line, line); + while (*cts.cts_ptr != NUL && col > 0) { + cts.cts_vcol += lbr_chartabsize_adv(&cts); col--; } + amount = cts.cts_vcol; + that = (char_u *)cts.cts_ptr; + clear_chartabsize_arg(&cts); // Some keywords require "body" indenting rules (the // non-standard-lisp ones are Scheme special forms): @@ -1056,10 +1058,15 @@ int get_lisp_indent(void) } firsttry = amount; - while (ascii_iswhite(*that)) { - amount += lbr_chartabsize(line, that, (colnr_T)amount); - that++; + init_chartabsize_arg(&cts, curwin, (colnr_T)(that - line), + amount, line, that); + while (ascii_iswhite(*cts.cts_ptr)) { + cts.cts_vcol += lbr_chartabsize(&cts); + cts.cts_ptr++; } + that = (char_u *)cts.cts_ptr; + amount = cts.cts_vcol; + clear_chartabsize_arg(&cts); if (*that && (*that != ';')) { // Not a comment line. @@ -1072,33 +1079,38 @@ int get_lisp_indent(void) parencount = 0; quotecount = 0; + init_chartabsize_arg(&cts, curwin, + (colnr_T)(that - line), amount, line, that); if (vi_lisp || ((*that != '"') && (*that != '\'') && (*that != '#') && ((*that < '0') || (*that > '9')))) { - while (*that - && (!ascii_iswhite(*that) || quotecount || parencount) - && (!((*that == '(' || *that == '[') + while (*cts.cts_ptr + && (!ascii_iswhite(*cts.cts_ptr) || quotecount || parencount) + && (!((*cts.cts_ptr == '(' || *cts.cts_ptr == '[') && !quotecount && !parencount && vi_lisp))) { - if (*that == '"') { + if (*cts.cts_ptr == '"') { quotecount = !quotecount; } - if (((*that == '(') || (*that == '[')) && !quotecount) { + if (((*cts.cts_ptr == '(') || (*cts.cts_ptr == '[')) && !quotecount) { parencount++; } - if (((*that == ')') || (*that == ']')) && !quotecount) { + if (((*cts.cts_ptr == ')') || (*cts.cts_ptr == ']')) && !quotecount) { parencount--; } - if ((*that == '\\') && (*(that + 1) != NUL)) { - amount += lbr_chartabsize_adv(line, &that, (colnr_T)amount); + if ((*cts.cts_ptr == '\\') && (*(cts.cts_ptr + 1) != NUL)) { + cts.cts_vcol += lbr_chartabsize_adv(&cts); } - amount += lbr_chartabsize_adv(line, &that, (colnr_T)amount); + cts.cts_vcol += lbr_chartabsize_adv(&cts); } } - while (ascii_iswhite(*that)) { - amount += lbr_chartabsize(line, that, (colnr_T)amount); - that++; + while (ascii_iswhite(*cts.cts_ptr)) { + cts.cts_vcol += lbr_chartabsize(&cts); + cts.cts_ptr++; } + that = (char_u *)cts.cts_ptr; + amount = cts.cts_vcol; + clear_chartabsize_arg(&cts); if (!*that || (*that == ';')) { amount = firsttry; -- cgit From 58f30a326f34319801e7921f32c83e8320d85f6c 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/indent.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index c983de6d5e..792f4d93c4 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -343,7 +343,7 @@ int get_sts_value(void) // Count the size (in window cells) of the indent in the current line. int get_indent(void) { - return get_indent_str_vtab(get_cursor_line_ptr(), + return get_indent_str_vtab((char *)get_cursor_line_ptr(), curbuf->b_p_ts, curbuf->b_p_vts_array, false); @@ -352,7 +352,7 @@ int get_indent(void) // Count the size (in window cells) of the indent in line "lnum". int get_indent_lnum(linenr_T lnum) { - return get_indent_str_vtab(ml_get(lnum), + return get_indent_str_vtab((char *)ml_get(lnum), curbuf->b_p_ts, curbuf->b_p_vts_array, false); @@ -362,7 +362,7 @@ int get_indent_lnum(linenr_T lnum) // "buf". int get_indent_buf(buf_T *buf, linenr_T lnum) { - return get_indent_str_vtab(ml_get_buf(buf, lnum, false), + return get_indent_str_vtab((char *)ml_get_buf(buf, lnum, false), curbuf->b_p_ts, buf->b_p_vts_array, false); @@ -400,7 +400,7 @@ int get_indent_str(const char_u *ptr, int ts, bool list) /// Count the size (in window cells) of the indent in line "ptr", using /// variable tabstops. /// if "list" is true, count only screen size for tabs. -int get_indent_str_vtab(const char_u *ptr, long ts, long *vts, bool list) +int get_indent_str_vtab(const char *ptr, long ts, long *vts, bool list) { int count = 0; @@ -800,7 +800,7 @@ int get_breakindent_win(win_T *wp, char_u *line) prev_ts = wp->w_buffer->b_p_ts; prev_tick = buf_get_changedtick(wp->w_buffer); prev_vts = wp->w_buffer->b_p_vts_array; - prev_indent = get_indent_str_vtab(line, + prev_indent = get_indent_str_vtab((char *)line, wp->w_buffer->b_p_ts, wp->w_buffer->b_p_vts_array, wp->w_p_list); -- cgit 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/indent.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 792f4d93c4..da4bcf6934 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -352,7 +352,7 @@ int get_indent(void) // Count the size (in window cells) of the indent in line "lnum". int get_indent_lnum(linenr_T lnum) { - return get_indent_str_vtab((char *)ml_get(lnum), + return get_indent_str_vtab(ml_get(lnum), curbuf->b_p_ts, curbuf->b_p_vts_array, false); @@ -710,7 +710,7 @@ int get_number_indent(linenr_T lnum) // In format_lines() (i.e. not insert mode), fo+=q is needed too... if ((State & MODE_INSERT) || has_format_option(FO_Q_COMS)) { - lead_len = get_leader_len((char *)ml_get(lnum), NULL, false, true); + lead_len = get_leader_len(ml_get(lnum), NULL, false, true); } regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC); @@ -719,9 +719,9 @@ int get_number_indent(linenr_T lnum) // vim_regexec() expects a pointer to a line. This lets us // start matching for the flp beyond any comment leader... - if (vim_regexec(®match, (char *)ml_get(lnum) + lead_len, (colnr_T)0)) { + if (vim_regexec(®match, ml_get(lnum) + lead_len, (colnr_T)0)) { pos.lnum = lnum; - pos.col = (colnr_T)(*regmatch.endp - ml_get(lnum)); + pos.col = (colnr_T)(*regmatch.endp - (char_u *)ml_get(lnum)); pos.coladd = 0; } vim_regfree(regmatch.regprog); @@ -1036,7 +1036,7 @@ int get_lisp_indent(void) } else { char_u *line = that; chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, pos->lnum, 0, line, line); + init_chartabsize_arg(&cts, curwin, pos->lnum, 0, (char *)line, (char *)line); while (*cts.cts_ptr != NUL && col > 0) { cts.cts_vcol += lbr_chartabsize_adv(&cts); col--; @@ -1060,7 +1060,7 @@ int get_lisp_indent(void) firsttry = amount; init_chartabsize_arg(&cts, curwin, (colnr_T)(that - line), - amount, line, that); + amount, (char *)line, (char *)that); while (ascii_iswhite(*cts.cts_ptr)) { cts.cts_vcol += lbr_chartabsize(&cts); cts.cts_ptr++; @@ -1081,7 +1081,7 @@ int get_lisp_indent(void) quotecount = 0; init_chartabsize_arg(&cts, curwin, - (colnr_T)(that - line), amount, line, that); + (colnr_T)(that - line), amount, (char *)line, (char *)that); if (vi_lisp || ((*that != '"') && (*that != '\'') && (*that != '#') && ((*that < '0') || (*that > '9')))) { while (*cts.cts_ptr -- 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/indent.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index da4bcf6934..a41a396abc 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -343,7 +343,7 @@ int get_sts_value(void) // Count the size (in window cells) of the indent in the current line. int get_indent(void) { - return get_indent_str_vtab((char *)get_cursor_line_ptr(), + return get_indent_str_vtab(get_cursor_line_ptr(), curbuf->b_p_ts, curbuf->b_p_vts_array, false); @@ -454,7 +454,7 @@ int set_indent(int size, int flags) // characters needed for the indent. todo = size; ind_len = 0; - p = oldline = get_cursor_line_ptr(); + p = oldline = (char_u *)get_cursor_line_ptr(); // Calculate the buffer size for the new indent, and check to see if it // isn't already set. @@ -857,7 +857,7 @@ int inindent(int extra) char_u *ptr; colnr_T col; - for (col = 0, ptr = get_cursor_line_ptr(); ascii_iswhite(*ptr); col++) { + for (col = 0, ptr = (char_u *)get_cursor_line_ptr(); ascii_iswhite(*ptr); col++) { ptr++; } @@ -979,7 +979,7 @@ int get_lisp_indent(void) continue; } - for (that = get_cursor_line_ptr(); *that != NUL; that++) { + for (that = (char_u *)get_cursor_line_ptr(); *that != NUL; that++) { if (*that == ';') { while (*(that + 1) != NUL) { that++; @@ -1029,7 +1029,7 @@ int get_lisp_indent(void) curwin->w_cursor.col = pos->col; col = pos->col; - that = get_cursor_line_ptr(); + that = (char_u *)get_cursor_line_ptr(); if (vi_lisp && (get_indent() == 0)) { amount = 2; -- 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/indent.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index a41a396abc..af5bcd7d2a 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -362,7 +362,7 @@ int get_indent_lnum(linenr_T lnum) // "buf". int get_indent_buf(buf_T *buf, linenr_T lnum) { - return get_indent_str_vtab((char *)ml_get_buf(buf, lnum, false), + return get_indent_str_vtab(ml_get_buf(buf, lnum, false), curbuf->b_p_ts, buf->b_p_vts_array, false); @@ -874,7 +874,7 @@ bool may_do_si(void) return curbuf->b_p_si && !curbuf->b_p_cin && *curbuf->b_p_inde == NUL && !p_paste; } -// Get indent level from 'indentexpr'. +/// Get indent level from 'indentexpr'. int get_expr_indent(void) { int indent = -1; @@ -898,8 +898,8 @@ int get_expr_indent(void) // Need to make a copy, the 'indentexpr' option could be changed while // evaluating it. - char_u *inde_copy = vim_strsave((char_u *)curbuf->b_p_inde); - indent = (int)eval_to_number((char *)inde_copy); + char *inde_copy = xstrdup(curbuf->b_p_inde); + indent = (int)eval_to_number(inde_copy); xfree(inde_copy); if (use_sandbox) { -- cgit From 684bc749efef0fa31395d349f4495d79ec5f3fd5 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/indent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index af5bcd7d2a..0f7a5a8e44 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -721,7 +721,7 @@ int get_number_indent(linenr_T lnum) // start matching for the flp beyond any comment leader... if (vim_regexec(®match, ml_get(lnum) + lead_len, (colnr_T)0)) { pos.lnum = lnum; - pos.col = (colnr_T)(*regmatch.endp - (char_u *)ml_get(lnum)); + pos.col = (colnr_T)(*regmatch.endp - ml_get(lnum)); pos.coladd = 0; } vim_regfree(regmatch.regprog); -- 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/indent.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 0f7a5a8e44..2509388009 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -434,10 +434,10 @@ int get_indent_str_vtab(const char *ptr, long ts, long *vts, bool list) // Returns true if the line was changed. int set_indent(int size, int flags) { - char_u *p; - char_u *newline; - char_u *oldline; - char_u *s; + char *p; + char *newline; + char *oldline; + char *s; int todo; int ind_len; // Measured in characters. int line_len; @@ -454,7 +454,7 @@ int set_indent(int size, int flags) // characters needed for the indent. todo = size; ind_len = 0; - p = oldline = (char_u *)get_cursor_line_ptr(); + p = oldline = get_cursor_line_ptr(); // Calculate the buffer size for the new indent, and check to see if it // isn't already set. @@ -549,7 +549,7 @@ int set_indent(int size, int flags) if (flags & SIN_INSERT) { p = oldline; } else { - p = (char_u *)skipwhite((char *)p); + p = skipwhite(p); } line_len = (int)STRLEN(p) + 1; @@ -631,7 +631,7 @@ int set_indent(int size, int flags) todo -= tab_pad; ind_done += tab_pad; } - p = (char_u *)skipwhite((char *)p); + p = skipwhite(p); } for (;;) { @@ -659,7 +659,7 @@ int set_indent(int size, int flags) const colnr_T new_offset = (colnr_T)(s - newline); // this may free "newline" - ml_replace(curwin->w_cursor.lnum, (char *)newline, false); + ml_replace(curwin->w_cursor.lnum, newline, false); if (!(flags & SIN_NOMARK)) { extmark_splice_cols(curbuf, (int)curwin->w_cursor.lnum - 1, @@ -1130,13 +1130,13 @@ int get_lisp_indent(void) static int lisp_match(char_u *p) { - char_u buf[LSIZE]; + char buf[LSIZE]; int len; char *word = (char *)(*curbuf->b_p_lw != NUL ? (char_u *)curbuf->b_p_lw : p_lispwords); while (*word != NUL) { - (void)copy_option_part(&word, (char *)buf, LSIZE, ","); - len = (int)STRLEN(buf); + (void)copy_option_part(&word, buf, LSIZE, ","); + len = (int)strlen(buf); if ((STRNCMP(buf, p, len) == 0) && (p[len] == ' ')) { return true; -- cgit From eaac0958256f2fb3b0fa9d20790bc38ed9eb3005 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 15 Oct 2022 19:25:51 +0800 Subject: vim-patch:partial:9.0.0737: Lisp word only recognized when a space follows Problem: Lisp word only recognized when a space follows. Solution: Also match a word at the end of a line. Rename the test. Use a compiled function to avoid backslashes. https://github.com/vim/vim/commit/d26c5805bcbd630dab0478c2d22503a6e32a83c1 Keep the old Test_lisp_indent(). --- src/nvim/indent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 0f7a5a8e44..74249777d6 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -1138,7 +1138,7 @@ static int lisp_match(char_u *p) (void)copy_option_part(&word, (char *)buf, LSIZE, ","); len = (int)STRLEN(buf); - if ((STRNCMP(buf, p, len) == 0) && (p[len] == ' ')) { + if ((STRNCMP(buf, p, len) == 0) && ascii_iswhite_or_nul(p[len])) { return true; } } -- cgit From 19eb7054ff7b1fbc78e56e7f9ed6537b085147bc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 16 Oct 2022 08:06:07 +0800 Subject: vim-patch:9.0.0761: cannot use 'indentexpr' for Lisp indenting Problem: Cannot use 'indentexpr' for Lisp indenting. Solution: Add the 'lispoptions' option. https://github.com/vim/vim/commit/49846fb1a31de99f49d6a7e70efe685197423c84 vim-patch:9.0.0762: build failure Problem: Build failure. Solution: Add missing change. https://github.com/vim/vim/commit/4b082c4bd05f504fda1acaa9d28fca55a2d04857 --- src/nvim/indent.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 3f5a8afbc1..3f08aa7043 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -15,6 +15,7 @@ #include "nvim/eval.h" #include "nvim/extmark.h" #include "nvim/indent.h" +#include "nvim/indent_c.h" #include "nvim/mark.h" #include "nvim/memline.h" #include "nvim/memory.h" @@ -1144,3 +1145,45 @@ static int lisp_match(char_u *p) } return false; } + +/// Re-indent the current line, based on the current contents of it and the +/// surrounding lines. Fixing the cursor position seems really easy -- I'm very +/// confused what all the part that handles Control-T is doing that I'm not. +/// "get_the_indent" should be get_c_indent, get_expr_indent or get_lisp_indent. +void fixthisline(IndentGetter get_the_indent) +{ + int amount = get_the_indent(); + + if (amount >= 0) { + change_indent(INDENT_SET, amount, false, 0, true); + if (linewhite(curwin->w_cursor.lnum)) { + did_ai = true; // delete the indent if the line stays empty + } + } +} + +/// Return true if 'indentexpr' should be used for Lisp indenting. +/// Caller may want to check 'autoindent'. +bool use_indentexpr_for_lisp(void) +{ + return curbuf->b_p_lisp + && *curbuf->b_p_inde != NUL + && strcmp(curbuf->b_p_lop, "expr:1") == 0; +} + +/// Fix indent for 'lisp' and 'cindent'. +void fix_indent(void) +{ + if (p_paste) { + return; // no auto-indenting when 'paste' is set + } + if (curbuf->b_p_lisp && curbuf->b_p_ai) { + if (use_indentexpr_for_lisp()) { + do_c_expr_indent(); + } else { + fixthisline(get_lisp_indent); + } + } else if (cindent_on()) { + do_c_expr_indent(); + } +} -- cgit From 784e498c4a9c1f03266ced5ec3f55c3a6c94b80d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 21 Oct 2022 14:47:44 +0200 Subject: refactor: clang-tidy fixes to silence clangd warning (#20683) * refactor: readability-uppercase-literal-suffix * refactor: readability-named-parameter * refactor: bugprone-suspicious-string-compare * refactor: google-readability-casting * refactor: readability-redundant-control-flow * refactor: bugprone-too-small-loop-variable * refactor: readability-non-const-parameter * refactor: readability-avoid-const-params-in-decls * refactor: google-readability-todo * refactor: readability-inconsistent-declaration-parameter-name * refactor: bugprone-suspicious-missing-comma * refactor: remove noisy or slow warnings --- src/nvim/indent.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 3f08aa7043..cb5819e946 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -101,7 +101,7 @@ bool tabstop_set(char *var, long **array) /// Calculate the number of screen spaces a tab will occupy. /// If "vts" is set then the tab widths are taken from that array, /// otherwise the value of ts is used. -int tabstop_padding(colnr_T col, long ts_arg, long *vts) +int tabstop_padding(colnr_T col, long ts_arg, const long *vts) { long ts = ts_arg == 0 ? 8 : ts_arg; colnr_T tabcol = 0; @@ -129,7 +129,7 @@ int tabstop_padding(colnr_T col, long ts_arg, long *vts) } /// Find the size of the tab that covers a particular column. -int tabstop_at(colnr_T col, long ts, long *vts) +int tabstop_at(colnr_T col, long ts, const long *vts) { colnr_T tabcol = 0; int t; @@ -178,7 +178,7 @@ colnr_T tabstop_start(colnr_T col, long ts, long *vts) /// Find the number of tabs and spaces necessary to get from one column /// to another. -void tabstop_fromto(colnr_T start_col, colnr_T end_col, long ts_arg, long *vts, int *ntabs, +void tabstop_fromto(colnr_T start_col, colnr_T end_col, long ts_arg, const long *vts, int *ntabs, int *nspcs) { int spaces = end_col - start_col; @@ -242,7 +242,7 @@ void tabstop_fromto(colnr_T start_col, colnr_T end_col, long ts_arg, long *vts, } /// See if two tabstop arrays contain the same values. -bool tabstop_eq(long *ts1, long *ts2) +bool tabstop_eq(const long *ts1, const long *ts2) { int t; @@ -266,7 +266,7 @@ bool tabstop_eq(long *ts1, long *ts2) } /// Copy a tabstop array, allocating space for the new array. -int *tabstop_copy(long *oldts) +int *tabstop_copy(const long *oldts) { long *newts; int t; -- cgit From 3e60b9f1cc7a24e801d1ee38b4d03032cc6962f2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 1 Apr 2022 17:58:19 +0800 Subject: vim-patch:8.2.4029: debugging NFA regexp my crash, cached indent may be wrong Problem: Debugging NFA regexp my crash, cached indent may be wrong. Solution: Fix some debug warnings in the NFA regexp code. Make sure log_fd is set when used. Fix breakindent and indent caching. (Christian Brabandt, closes vim/vim#9482) https://github.com/vim/vim/commit/b2d85e3784ac89f5209489844c1ee0f54d117abb --- src/nvim/indent.c | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index cb5819e946..c929a0d14a 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -783,19 +783,22 @@ int get_breakindent_win(win_T *wp, char_u *line) FUNC_ATTR_NONNULL_ALL { static int prev_indent = 0; // Cached indent value. - static long prev_ts = 0; // Cached tabstop value. + static long prev_ts = 0L; // Cached tabstop value. static const char_u *prev_line = NULL; // cached pointer to line. static varnumber_T prev_tick = 0; // Changedtick of cached value. - static long *prev_vts = NULL; // Cached vartabs values. + static long *prev_vts = NULL; // Cached vartabs values. + static int prev_list = 0; // cached list value + static int prev_listopt = 0; // cached w_p_briopt_list value int bri = 0; // window width minus window margin space, i.e. what rests for text const int eff_wwidth = wp->w_width_inner - ((wp->w_p_nu || wp->w_p_rnu) && (vim_strchr(p_cpo, CPO_NUMCOL) == NULL) ? number_width(wp) + 1 : 0); - // used cached indent, unless pointer or 'tabstop' changed + // used cached indent, unless line, 'tabstop' or briopt_list changed if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts || prev_tick != buf_get_changedtick(wp->w_buffer) + || prev_listopt != wp->w_briopt_list || prev_vts != wp->w_buffer->b_p_vts_array) { prev_line = line; prev_ts = wp->w_buffer->b_p_ts; @@ -805,6 +808,25 @@ int get_breakindent_win(win_T *wp, char_u *line) wp->w_buffer->b_p_ts, wp->w_buffer->b_p_vts_array, wp->w_p_list); + prev_listopt = wp->w_briopt_list; + // add additional indent for numbered lists + if (wp->w_briopt_list != 0) { + regmatch_T regmatch = { + .regprog = vim_regcomp(curbuf->b_p_flp, + RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT), + }; + if (regmatch.regprog != NULL) { + regmatch.rm_ic = false; + if (vim_regexec(®match, (char *)line, 0)) { + if (wp->w_briopt_list > 0) { + prev_list += wp->w_briopt_list; + } else { + prev_list = (int)(*regmatch.endp - *regmatch.startp); + } + } + vim_regfree(regmatch.regprog); + } + } } bri = prev_indent + wp->w_briopt_shift; @@ -813,21 +835,10 @@ int get_breakindent_win(win_T *wp, char_u *line) // add additional indent for numbered lists if (wp->w_briopt_list != 0) { - regmatch_T regmatch = { - .regprog = vim_regcomp(curbuf->b_p_flp, - RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT), - }; - - if (regmatch.regprog != NULL) { - regmatch.rm_ic = false; - if (vim_regexec(®match, (char *)line, 0)) { - if (wp->w_briopt_list > 0) { - bri += wp->w_briopt_list; - } else { - bri = (int)(*regmatch.endp - *regmatch.startp); - } - } - vim_regfree(regmatch.regprog); + if (wp->w_briopt_list > 0) { + bri += prev_list; + } else { + bri = prev_list; } } -- cgit From b92ed35a0bb873589bba9b51fdb92ffd00dc3e57 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 1 Apr 2022 18:12:55 +0800 Subject: vim-patch:8.2.4093: cached breakindent values not initialized properly Problem: Cached breakindent values not initialized properly. Solution: Initialize and cache formatlistpat. (Christian Brabandt, closes vim/vim#9526, closes vim/vim#9512) https://github.com/vim/vim/commit/c53b467473160b5cfce77277fbae414bf43e66ce Co-authored-by: Christian Brabandt --- src/nvim/indent.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index c929a0d14a..359dd32fdf 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -789,16 +789,22 @@ int get_breakindent_win(win_T *wp, char_u *line) static long *prev_vts = NULL; // Cached vartabs values. static int prev_list = 0; // cached list value static int prev_listopt = 0; // cached w_p_briopt_list value + static char *prev_flp = NULL; // cached formatlistpat value int bri = 0; // window width minus window margin space, i.e. what rests for text const int eff_wwidth = wp->w_width_inner - ((wp->w_p_nu || wp->w_p_rnu) && (vim_strchr(p_cpo, CPO_NUMCOL) == NULL) ? number_width(wp) + 1 : 0); - // used cached indent, unless line, 'tabstop' or briopt_list changed + // used cached indent, unless + // - line pointer changed + // - 'tabstop' changed + // - 'briopt_list changed' changed or + // - 'formatlistpattern' changed if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts || prev_tick != buf_get_changedtick(wp->w_buffer) || prev_listopt != wp->w_briopt_list + || (prev_flp == NULL || (strcmp(prev_flp, get_flp_value(wp->w_buffer)) != 0)) || prev_vts != wp->w_buffer->b_p_vts_array) { prev_line = line; prev_ts = wp->w_buffer->b_p_ts; @@ -809,11 +815,13 @@ int get_breakindent_win(win_T *wp, char_u *line) wp->w_buffer->b_p_vts_array, wp->w_p_list); prev_listopt = wp->w_briopt_list; + prev_list = 0; + xfree(prev_flp); + prev_flp = xstrdup(get_flp_value(wp->w_buffer)); // add additional indent for numbered lists if (wp->w_briopt_list != 0) { regmatch_T regmatch = { - .regprog = vim_regcomp(curbuf->b_p_flp, - RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT), + .regprog = vim_regcomp(prev_flp, RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT), }; if (regmatch.regprog != NULL) { regmatch.rm_ic = false; -- cgit From e0ec83a9701ffd9b30a41763ad2e2326d85d8480 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 5 Nov 2022 19:19:55 +0800 Subject: vim-patch:8.2.4882: cannot make 'breakindent' use a specific column Problem: Cannot make 'breakindent' use a specific column. Solution: Add the "column" entry in 'breakindentopt'. (Christian Brabandt, closes vim/vim#10362, closes vim/vim#10325) https://github.com/vim/vim/commit/e7d6dbc5721342e3d6b04cf285e4510b5569e707 Co-authored-by: Christian Brabandt --- src/nvim/indent.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 359dd32fdf..d372e41459 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -743,6 +743,7 @@ bool briopt_check(win_T *wp) int bri_min = 20; bool bri_sbr = false; int bri_list = 0; + int bri_vcol = 0; char *p = wp->w_p_briopt; while (*p != NUL) { @@ -759,6 +760,9 @@ bool briopt_check(win_T *wp) } else if (STRNCMP(p, "list:", 5) == 0) { p += 5; bri_list = (int)getdigits(&p, false, 0); + } else if (STRNCMP(p, "column:", 7) == 0) { + p += 7; + bri_vcol = (int)getdigits(&p, false, 0); } if (*p != ',' && *p != NUL) { return false; @@ -771,7 +775,8 @@ bool briopt_check(win_T *wp) wp->w_briopt_shift = bri_shift; wp->w_briopt_min = bri_min; wp->w_briopt_sbr = bri_sbr; - wp->w_briopt_list = bri_list; + wp->w_briopt_list = bri_list; + wp->w_briopt_vcol = bri_vcol; return true; } @@ -810,16 +815,18 @@ int get_breakindent_win(win_T *wp, char_u *line) prev_ts = wp->w_buffer->b_p_ts; prev_tick = buf_get_changedtick(wp->w_buffer); prev_vts = wp->w_buffer->b_p_vts_array; - prev_indent = get_indent_str_vtab((char *)line, - wp->w_buffer->b_p_ts, - wp->w_buffer->b_p_vts_array, - wp->w_p_list); + if (wp->w_briopt_vcol == 0) { + prev_indent = get_indent_str_vtab((char *)line, + wp->w_buffer->b_p_ts, + wp->w_buffer->b_p_vts_array, + wp->w_p_list); + } prev_listopt = wp->w_briopt_list; prev_list = 0; xfree(prev_flp); prev_flp = xstrdup(get_flp_value(wp->w_buffer)); // add additional indent for numbered lists - if (wp->w_briopt_list != 0) { + if (wp->w_briopt_list != 0 && wp->w_briopt_vcol == 0) { regmatch_T regmatch = { .regprog = vim_regcomp(prev_flp, RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT), }; @@ -836,7 +843,13 @@ int get_breakindent_win(win_T *wp, char_u *line) } } } - bri = prev_indent + wp->w_briopt_shift; + if (wp->w_briopt_vcol != 0) { + // column value has priority + bri = wp->w_briopt_vcol; + prev_list = 0; + } else { + bri = prev_indent + wp->w_briopt_shift; + } // Add offset for number column, if 'n' is in 'cpoptions' bri += win_col_off2(wp); -- cgit From 731cdde28ea8d48cc23ba2752a08c261c87eee92 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 22 Oct 2022 12:36:38 +0200 Subject: refactor: fix clang-tidy warnings Enable and fix bugprone-misplaced-widening-cast warning. Fix some modernize-macro-to-enum and readability-else-after-return warnings, but don't enable them. While the warnings can be useful, they are in general too noisy to enable. --- src/nvim/indent.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index d372e41459..0bf36c42f4 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -896,9 +896,8 @@ int inindent(int extra) if (col >= curwin->w_cursor.col + extra) { return true; - } else { - return false; } + return false; } /// @return true if the conditions are OK for smart indenting. -- 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/indent.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 0bf36c42f4..f6b1b81780 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -2,8 +2,10 @@ // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com #include -#include +#include #include +#include +#include #include "nvim/ascii.h" #include "nvim/assert.h" @@ -13,21 +15,28 @@ #include "nvim/cursor.h" #include "nvim/edit.h" #include "nvim/eval.h" +#include "nvim/eval/typval_defs.h" #include "nvim/extmark.h" +#include "nvim/gettext.h" +#include "nvim/globals.h" #include "nvim/indent.h" #include "nvim/indent_c.h" #include "nvim/mark.h" #include "nvim/memline.h" #include "nvim/memory.h" +#include "nvim/message.h" #include "nvim/move.h" #include "nvim/option.h" #include "nvim/plines.h" +#include "nvim/pos.h" #include "nvim/regexp.h" #include "nvim/screen.h" #include "nvim/search.h" #include "nvim/strings.h" #include "nvim/textformat.h" +#include "nvim/types.h" #include "nvim/undo.h" +#include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "indent.c.generated.h" -- cgit From bd22585061b66d7f71d4832b4a81e950b3c9d19d 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/indent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index f6b1b81780..062e073156 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -561,7 +561,7 @@ int set_indent(int size, int flags) } else { p = skipwhite(p); } - line_len = (int)STRLEN(p) + 1; + line_len = (int)strlen(p) + 1; // If 'preserveindent' and 'expandtab' are both set keep the original // characters and allocate accordingly. We will fill the rest with spaces -- 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/indent.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 062e073156..1905128c3c 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -756,20 +756,20 @@ bool briopt_check(win_T *wp) char *p = wp->w_p_briopt; while (*p != NUL) { - if (STRNCMP(p, "shift:", 6) == 0 + if (strncmp(p, "shift:", 6) == 0 && ((p[6] == '-' && ascii_isdigit(p[7])) || ascii_isdigit(p[6]))) { p += 6; bri_shift = getdigits_int(&p, true, 0); - } else if (STRNCMP(p, "min:", 4) == 0 && ascii_isdigit(p[4])) { + } else if (strncmp(p, "min:", 4) == 0 && ascii_isdigit(p[4])) { p += 4; bri_min = getdigits_int(&p, true, 0); - } else if (STRNCMP(p, "sbr", 3) == 0) { + } else if (strncmp(p, "sbr", 3) == 0) { p += 3; bri_sbr = true; - } else if (STRNCMP(p, "list:", 5) == 0) { + } else if (strncmp(p, "list:", 5) == 0) { p += 5; bri_list = (int)getdigits(&p, false, 0); - } else if (STRNCMP(p, "column:", 7) == 0) { + } else if (strncmp(p, "column:", 7) == 0) { p += 7; bri_vcol = (int)getdigits(&p, false, 0); } @@ -1091,7 +1091,7 @@ int get_lisp_indent(void) // (let ((a 1)) instead (let ((a 1)) // (...)) of (...)) if (!vi_lisp && ((*that == '(') || (*that == '[')) - && lisp_match(that + 1)) { + && lisp_match((char *)that + 1)) { amount += 2; } else { if (*that != NUL) { @@ -1169,7 +1169,7 @@ int get_lisp_indent(void) return amount; } -static int lisp_match(char_u *p) +static int lisp_match(char *p) { char buf[LSIZE]; int len; @@ -1179,7 +1179,7 @@ static int lisp_match(char_u *p) (void)copy_option_part(&word, buf, LSIZE, ","); len = (int)strlen(buf); - if ((STRNCMP(buf, p, len) == 0) && ascii_iswhite_or_nul(p[len])) { + if ((strncmp(buf, p, (size_t)len) == 0) && ascii_iswhite_or_nul(p[len])) { return true; } } -- cgit From e0c7b8955d0193ebbc7df703179ecb035f73fec7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 30 Nov 2022 10:12:09 +0800 Subject: refactor: move ex_retab() to indent.c --- src/nvim/indent.c | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 1905128c3c..32cdf6f2d6 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -13,6 +13,7 @@ #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" @@ -27,6 +28,8 @@ #include "nvim/message.h" #include "nvim/move.h" #include "nvim/option.h" +#include "nvim/optionstr.h" +#include "nvim/os/input.h" #include "nvim/plines.h" #include "nvim/pos.h" #include "nvim/regexp.h" @@ -915,6 +918,192 @@ bool may_do_si(void) return curbuf->b_p_si && !curbuf->b_p_cin && *curbuf->b_p_inde == NUL && !p_paste; } +/// ":retab". +void ex_retab(exarg_T *eap) +{ + linenr_T lnum; + bool got_tab = false; + long num_spaces = 0; + long num_tabs; + long len; + long col; + long vcol; + long start_col = 0; // For start of white-space string + long start_vcol = 0; // For start of white-space string + long old_len; + char *ptr; + char *new_line = (char *)1; // init to non-NULL + bool did_undo; // called u_save for current line + long *new_vts_array = NULL; + char *new_ts_str; // string value of tab argument + + int save_list; + linenr_T first_line = 0; // first changed line + linenr_T last_line = 0; // last changed line + + save_list = curwin->w_p_list; + curwin->w_p_list = 0; // don't want list mode here + + new_ts_str = eap->arg; + if (!tabstop_set(eap->arg, &new_vts_array)) { + return; + } + while (ascii_isdigit(*(eap->arg)) || *(eap->arg) == ',') { + (eap->arg)++; + } + + // This ensures that either new_vts_array and new_ts_str are freshly + // allocated, or new_vts_array points to an existing array and new_ts_str + // is null. + if (new_vts_array == NULL) { + new_vts_array = curbuf->b_p_vts_array; + new_ts_str = NULL; + } else { + new_ts_str = xstrnsave(new_ts_str, (size_t)(eap->arg - new_ts_str)); + } + for (lnum = eap->line1; !got_int && lnum <= eap->line2; lnum++) { + ptr = ml_get(lnum); + col = 0; + vcol = 0; + did_undo = false; + for (;;) { + if (ascii_iswhite(ptr[col])) { + if (!got_tab && num_spaces == 0) { + // First consecutive white-space + start_vcol = vcol; + start_col = col; + } + if (ptr[col] == ' ') { + num_spaces++; + } else { + got_tab = true; + } + } else { + if (got_tab || (eap->forceit && num_spaces > 1)) { + // Retabulate this string of white-space + + // len is virtual length of white string + len = num_spaces = vcol - start_vcol; + num_tabs = 0; + if (!curbuf->b_p_et) { + int t, s; + + tabstop_fromto((colnr_T)start_vcol, (colnr_T)vcol, + curbuf->b_p_ts, new_vts_array, &t, &s); + num_tabs = t; + num_spaces = s; + } + if (curbuf->b_p_et || got_tab + || (num_spaces + num_tabs < len)) { + if (did_undo == false) { + did_undo = true; + if (u_save((linenr_T)(lnum - 1), + (linenr_T)(lnum + 1)) == FAIL) { + new_line = NULL; // flag out-of-memory + break; + } + } + + // len is actual number of white characters used + len = num_spaces + num_tabs; + old_len = (long)strlen(ptr); + const long new_len = old_len - col + start_col + len + 1; + if (new_len <= 0 || new_len >= MAXCOL) { + emsg(_(e_resulting_text_too_long)); + break; + } + new_line = xmalloc((size_t)new_len); + + if (start_col > 0) { + memmove(new_line, ptr, (size_t)start_col); + } + memmove(new_line + start_col + len, + ptr + col, (size_t)(old_len - col + 1)); + ptr = new_line + start_col; + for (col = 0; col < len; col++) { + ptr[col] = (col < num_tabs) ? '\t' : ' '; + } + if (ml_replace(lnum, new_line, false) == OK) { + // "new_line" may have been copied + new_line = curbuf->b_ml.ml_line_ptr; + extmark_splice_cols(curbuf, lnum - 1, 0, (colnr_T)old_len, + (colnr_T)new_len - 1, kExtmarkUndo); + } + if (first_line == 0) { + first_line = lnum; + } + last_line = lnum; + ptr = new_line; + col = start_col + len; + } + } + got_tab = false; + num_spaces = 0; + } + if (ptr[col] == NUL) { + break; + } + vcol += win_chartabsize(curwin, ptr + col, (colnr_T)vcol); + if (vcol >= MAXCOL) { + emsg(_(e_resulting_text_too_long)); + // when not inside a try/catch set got_int to break out of any + // loop + if (trylevel == 0) { + got_int = true; + } + break; + } + col += utfc_ptr2len(ptr + col); + } + if (new_line == NULL) { // out of memory + break; + } + line_breakcheck(); + } + if (got_int) { + emsg(_(e_interr)); + } + + // If a single value was given then it can be considered equal to + // either the value of 'tabstop' or the value of 'vartabstop'. + if (tabstop_count(curbuf->b_p_vts_array) == 0 + && tabstop_count(new_vts_array) == 1 + && curbuf->b_p_ts == tabstop_first(new_vts_array)) { + // not changed + } else if (tabstop_count(curbuf->b_p_vts_array) > 0 + && tabstop_eq(curbuf->b_p_vts_array, new_vts_array)) { + // not changed + } else { + redraw_curbuf_later(UPD_NOT_VALID); + } + if (first_line != 0) { + changed_lines(first_line, 0, last_line + 1, 0L, true); + } + + curwin->w_p_list = save_list; // restore 'list' + + if (new_ts_str != NULL) { // set the new tabstop + // If 'vartabstop' is in use or if the value given to retab has more + // than one tabstop then update 'vartabstop'. + long *old_vts_ary = curbuf->b_p_vts_array; + + if (tabstop_count(old_vts_ary) > 0 || tabstop_count(new_vts_array) > 1) { + set_string_option_direct("vts", -1, new_ts_str, OPT_FREE | OPT_LOCAL, 0); + curbuf->b_p_vts_array = new_vts_array; + xfree(old_vts_ary); + } else { + // 'vartabstop' wasn't in use and a single value was given to + // retab then update 'tabstop'. + curbuf->b_p_ts = tabstop_first(new_vts_array); + xfree(new_vts_array); + } + xfree(new_ts_str); + } + coladvance(curwin->w_curswant); + + u_clearline(); +} + /// Get indent level from 'indentexpr'. int get_expr_indent(void) { -- cgit From 22622df950fe90abcaaf2e6710cd6cd9451cdc34 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 30 Nov 2022 10:07:24 +0800 Subject: vim-patch:8.2.5108: retab test disabled because it hangs on MS-Windows Problem: Retab test disabled because it hangs on MS-Windows. Solution: Also set got_int at the other place a overlong text is detected. https://github.com/vim/vim/commit/308660bd263367a4f1a75498cbd2e29cade47f4d Co-authored-by: Bram Moolenaar --- src/nvim/indent.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 32cdf6f2d6..0ffa152af7 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -918,6 +918,16 @@ bool may_do_si(void) return curbuf->b_p_si && !curbuf->b_p_cin && *curbuf->b_p_inde == NUL && !p_paste; } +/// Give a "resulting text too long" error and maybe set got_int. +static void emsg_text_too_long(void) +{ + emsg(_(e_resulting_text_too_long)); + // when not inside a try/catch set got_int to break out of any loop + if (trylevel == 0) { + got_int = true; + } +} + /// ":retab". void ex_retab(exarg_T *eap) { @@ -1009,7 +1019,7 @@ void ex_retab(exarg_T *eap) old_len = (long)strlen(ptr); const long new_len = old_len - col + start_col + len + 1; if (new_len <= 0 || new_len >= MAXCOL) { - emsg(_(e_resulting_text_too_long)); + emsg_text_too_long(); break; } new_line = xmalloc((size_t)new_len); @@ -1045,12 +1055,7 @@ void ex_retab(exarg_T *eap) } vcol += win_chartabsize(curwin, ptr + col, (colnr_T)vcol); if (vcol >= MAXCOL) { - emsg(_(e_resulting_text_too_long)); - // when not inside a try/catch set got_int to break out of any - // loop - if (trylevel == 0) { - got_int = true; - } + emsg_text_too_long(); break; } col += utfc_ptr2len(ptr + col); -- cgit From c0d17cec0b691488dbb3a57433e39d97aff36c47 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 30 Nov 2022 11:47:30 +0800 Subject: vim-patch:8.2.3259 when 'indentexpr' causes an error did_throw may hang (#21240) vim-patch:8.2.3259: when 'indentexpr' causes an error did_throw may hang Problem: When 'indentexpr' causes an error the did_throw flag may remain set. Solution: Reset did_throw and show the error. (closes vim/vim#8677) https://github.com/vim/vim/commit/620c959c6c00e469c4d3b1ab2e08e4767ee142a4 Co-authored-by: Bram Moolenaar --- src/nvim/indent.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 0ffa152af7..bd91d1d4da 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -17,6 +17,7 @@ #include "nvim/edit.h" #include "nvim/eval.h" #include "nvim/eval/typval_defs.h" +#include "nvim/ex_docmd.h" #include "nvim/extmark.h" #include "nvim/gettext.h" #include "nvim/globals.h" @@ -1153,6 +1154,12 @@ int get_expr_indent(void) check_cursor(); State = save_State; + // Reset did_throw, unless 'debug' has "throw" and inside a try/catch. + if (did_throw && (vim_strchr(p_debug, 't') == NULL || trylevel == 0)) { + handle_did_throw(); + did_throw = false; + } + // If there is an error, just keep the current indent. if (indent < 0) { indent = get_indent(); -- cgit From bd2d0edcbf4e98e05edff13f344865fcafac56b5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Dec 2022 09:05:25 +0800 Subject: fix: clang warnings (#21247) --- src/nvim/indent.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index bd91d1d4da..2777ebd18c 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -199,6 +199,7 @@ void tabstop_fromto(colnr_T start_col, colnr_T end_col, long ts_arg, const long long padding = 0; int t; long ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg; + assert(ts != 0); // suppress clang "Division by zero" if (vts == NULL || vts[0] == 0) { int tabs = 0; -- cgit From b201cbfc61916a831d4a36f58284a5c1a3e006e1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 20 Dec 2022 05:22:13 +0800 Subject: vim-patch:9.0.1078: with the +vartabs feature indent folding may use wrong 'ts' Problem: With the +vartabs feature indent folding may use wrong 'tabstop'. Solution: Use the "buf" argument instead of "curbuf". https://github.com/vim/vim/commit/07146ad1d33ba0d36b324873e5c461931e6b025e --- src/nvim/indent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 2777ebd18c..7d3b1f4a3f 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -378,7 +378,7 @@ int get_indent_lnum(linenr_T lnum) int get_indent_buf(buf_T *buf, linenr_T lnum) { return get_indent_str_vtab(ml_get_buf(buf, lnum, false), - curbuf->b_p_ts, + buf->b_p_ts, buf->b_p_vts_array, false); } -- cgit From a5f4ba74472f965953f0d3e45704c93b95f9b9a7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 12 Jan 2023 21:33:38 +0800 Subject: vim-patch:9.0.1183: code is indented more than necessary (#21773) Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes vim/vim#11805) https://github.com/vim/vim/commit/0233bdfa2b487c392dc4fd1a29113e08fbace334 Co-authored-by: Yegappan Lakshmanan --- src/nvim/indent.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 7d3b1f4a3f..27d6f60011 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -1396,11 +1396,13 @@ void fixthisline(IndentGetter get_the_indent) { int amount = get_the_indent(); - if (amount >= 0) { - change_indent(INDENT_SET, amount, false, 0, true); - if (linewhite(curwin->w_cursor.lnum)) { - did_ai = true; // delete the indent if the line stays empty - } + if (amount < 0) { + return; + } + + change_indent(INDENT_SET, amount, false, 0, true); + if (linewhite(curwin->w_cursor.lnum)) { + did_ai = true; // delete the indent if the line stays empty } } -- cgit From e89c39d6f016a4140293755250e968e839009617 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 14 Jan 2023 08:58:28 +0100 Subject: refactor: replace char_u with char 21 (#21779) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/indent.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 27d6f60011..be1dfb77cf 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -798,7 +798,7 @@ bool briopt_check(win_T *wp) // Return appropriate space number for breakindent, taking influencing // parameters into account. Window must be specified, since it is not // necessarily always the current one. -int get_breakindent_win(win_T *wp, char_u *line) +int get_breakindent_win(win_T *wp, char *line) FUNC_ATTR_NONNULL_ALL { static int prev_indent = 0; // Cached indent value. @@ -820,17 +820,17 @@ int get_breakindent_win(win_T *wp, char_u *line) // - 'tabstop' changed // - 'briopt_list changed' changed or // - 'formatlistpattern' changed - if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts + if (prev_line != (char_u *)line || prev_ts != wp->w_buffer->b_p_ts || prev_tick != buf_get_changedtick(wp->w_buffer) || prev_listopt != wp->w_briopt_list || (prev_flp == NULL || (strcmp(prev_flp, get_flp_value(wp->w_buffer)) != 0)) || prev_vts != wp->w_buffer->b_p_vts_array) { - prev_line = line; + prev_line = (char_u *)line; prev_ts = wp->w_buffer->b_p_ts; prev_tick = buf_get_changedtick(wp->w_buffer); prev_vts = wp->w_buffer->b_p_vts_array; if (wp->w_briopt_vcol == 0) { - prev_indent = get_indent_str_vtab((char *)line, + prev_indent = get_indent_str_vtab(line, wp->w_buffer->b_p_ts, wp->w_buffer->b_p_vts_array, wp->w_p_list); @@ -846,7 +846,7 @@ int get_breakindent_win(win_T *wp, char_u *line) }; if (regmatch.regprog != NULL) { regmatch.rm_ic = false; - if (vim_regexec(®match, (char *)line, 0)) { + if (vim_regexec(®match, line, 0)) { if (wp->w_briopt_list > 0) { prev_list += wp->w_briopt_list; } else { -- cgit From 3269902a13df3bccf8705db73488c0a47f495514 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 15 Jan 2023 14:16:33 +0100 Subject: refactor: fix IWYU mapping file and use IWYU (#21802) Also add the EXITFREE definition to main_lib rather than the nvim target, as the header generation needs the EXITFREE flag to work properly. --- src/nvim/indent.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index be1dfb77cf..ed4005d139 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -17,6 +17,7 @@ #include "nvim/edit.h" #include "nvim/eval.h" #include "nvim/eval/typval_defs.h" +#include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" #include "nvim/extmark.h" #include "nvim/gettext.h" @@ -24,6 +25,7 @@ #include "nvim/indent.h" #include "nvim/indent_c.h" #include "nvim/mark.h" +#include "nvim/mbyte.h" #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/message.h" -- cgit From 8a4285d5637c146a0ae606918a8e77063c6a5f0d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 18 Jan 2023 14:17:11 +0100 Subject: refactor: replace char_u with char 24 (#21823) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/indent.c | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index ed4005d139..2d1b5efb0a 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -388,7 +388,7 @@ int get_indent_buf(buf_T *buf, linenr_T lnum) /// Count the size (in window cells) of the indent in line "ptr", with /// 'tabstop' at "ts". /// If @param list is true, count only screen size for tabs. -int get_indent_str(const char_u *ptr, int ts, bool list) +int get_indent_str(const char *ptr, int ts, bool list) FUNC_ATTR_NONNULL_ALL { int count = 0; @@ -402,7 +402,7 @@ int get_indent_str(const char_u *ptr, int ts, bool list) } else { // In list mode, when tab is not set, count screen char width // for Tab, displays: ^I - count += ptr2cells((char *)ptr); + count += ptr2cells(ptr); } } else if (*ptr == ' ') { // Count a space for one. @@ -805,7 +805,7 @@ int get_breakindent_win(win_T *wp, char *line) { static int prev_indent = 0; // Cached indent value. static long prev_ts = 0L; // Cached tabstop value. - static const char_u *prev_line = NULL; // cached pointer to line. + static const char *prev_line = NULL; // cached pointer to line. static varnumber_T prev_tick = 0; // Changedtick of cached value. static long *prev_vts = NULL; // Cached vartabs values. static int prev_list = 0; // cached list value @@ -822,12 +822,12 @@ int get_breakindent_win(win_T *wp, char *line) // - 'tabstop' changed // - 'briopt_list changed' changed or // - 'formatlistpattern' changed - if (prev_line != (char_u *)line || prev_ts != wp->w_buffer->b_p_ts + if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts || prev_tick != buf_get_changedtick(wp->w_buffer) || prev_listopt != wp->w_briopt_list || (prev_flp == NULL || (strcmp(prev_flp, get_flp_value(wp->w_buffer)) != 0)) || prev_vts != wp->w_buffer->b_p_vts_array) { - prev_line = (char_u *)line; + prev_line = line; prev_ts = wp->w_buffer->b_p_ts; prev_tick = buf_get_changedtick(wp->w_buffer); prev_vts = wp->w_buffer->b_p_vts_array; @@ -881,7 +881,7 @@ int get_breakindent_win(win_T *wp, char *line) // indent minus the length of the showbreak string if (wp->w_briopt_sbr) { - bri -= vim_strsize((char *)get_showbreak_value(wp)); + bri -= vim_strsize(get_showbreak_value(wp)); } // never indent past left window margin @@ -903,10 +903,10 @@ int get_breakindent_win(win_T *wp, char *line) // the line. int inindent(int extra) { - char_u *ptr; + char *ptr; colnr_T col; - for (col = 0, ptr = (char_u *)get_cursor_line_ptr(); ascii_iswhite(*ptr); col++) { + for (col = 0, ptr = get_cursor_line_ptr(); ascii_iswhite(*ptr); col++) { ptr++; } @@ -1189,7 +1189,7 @@ int get_lisp_indent(void) { pos_T *pos, realpos, paren; int amount; - char_u *that; + char *that; colnr_T col; colnr_T firsttry; int parencount; @@ -1224,7 +1224,7 @@ int get_lisp_indent(void) continue; } - for (that = (char_u *)get_cursor_line_ptr(); *that != NUL; that++) { + for (that = get_cursor_line_ptr(); *that != NUL; that++) { if (*that == ';') { while (*(that + 1) != NUL) { that++; @@ -1274,20 +1274,20 @@ int get_lisp_indent(void) curwin->w_cursor.col = pos->col; col = pos->col; - that = (char_u *)get_cursor_line_ptr(); + that = get_cursor_line_ptr(); if (vi_lisp && (get_indent() == 0)) { amount = 2; } else { - char_u *line = that; + char *line = that; chartabsize_T cts; - init_chartabsize_arg(&cts, curwin, pos->lnum, 0, (char *)line, (char *)line); + init_chartabsize_arg(&cts, curwin, pos->lnum, 0, line, line); while (*cts.cts_ptr != NUL && col > 0) { cts.cts_vcol += lbr_chartabsize_adv(&cts); col--; } amount = cts.cts_vcol; - that = (char_u *)cts.cts_ptr; + that = cts.cts_ptr; clear_chartabsize_arg(&cts); // Some keywords require "body" indenting rules (the @@ -1295,7 +1295,7 @@ int get_lisp_indent(void) // (let ((a 1)) instead (let ((a 1)) // (...)) of (...)) if (!vi_lisp && ((*that == '(') || (*that == '[')) - && lisp_match((char *)that + 1)) { + && lisp_match(that + 1)) { amount += 2; } else { if (*that != NUL) { @@ -1305,12 +1305,12 @@ int get_lisp_indent(void) firsttry = amount; init_chartabsize_arg(&cts, curwin, (colnr_T)(that - line), - amount, (char *)line, (char *)that); + amount, line, that); while (ascii_iswhite(*cts.cts_ptr)) { cts.cts_vcol += lbr_chartabsize(&cts); cts.cts_ptr++; } - that = (char_u *)cts.cts_ptr; + that = cts.cts_ptr; amount = cts.cts_vcol; clear_chartabsize_arg(&cts); @@ -1326,9 +1326,10 @@ int get_lisp_indent(void) quotecount = 0; init_chartabsize_arg(&cts, curwin, - (colnr_T)(that - line), amount, (char *)line, (char *)that); + (colnr_T)(that - line), amount, line, that); if (vi_lisp || ((*that != '"') && (*that != '\'') - && (*that != '#') && ((*that < '0') || (*that > '9')))) { + && (*that != '#') + && (((uint8_t)(*that) < '0') || ((uint8_t)(*that) > '9')))) { while (*cts.cts_ptr && (!ascii_iswhite(*cts.cts_ptr) || quotecount || parencount) && (!((*cts.cts_ptr == '(' || *cts.cts_ptr == '[') @@ -1354,7 +1355,7 @@ int get_lisp_indent(void) cts.cts_vcol += lbr_chartabsize(&cts); cts.cts_ptr++; } - that = (char_u *)cts.cts_ptr; + that = cts.cts_ptr; amount = cts.cts_vcol; clear_chartabsize_arg(&cts); @@ -1377,7 +1378,7 @@ static int lisp_match(char *p) { char buf[LSIZE]; int len; - char *word = (char *)(*curbuf->b_p_lw != NUL ? (char_u *)curbuf->b_p_lw : p_lispwords); + char *word = *curbuf->b_p_lw != NUL ? curbuf->b_p_lw : p_lispwords; while (*word != NUL) { (void)copy_option_part(&word, buf, LSIZE, ","); -- cgit From 51d082b466c59f739205a6ec0abeeee1281df68b Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 20 Jan 2023 10:35:52 +0800 Subject: vim-patch:9.0.0358: 'breakindent' does not indent non-lists (#21913) Problem: 'breakindent' does not indent non-lists with "breakindentopt=list:-1". Solution: Adjust indent computation. (Maxim Kim, closes vim/vim#11038) https://github.com/vim/vim/commit/119167265ebc7eced210a7f8ed2f4b90378f98f1 Co-authored-by: Maxim Kim --- src/nvim/indent.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 2d1b5efb0a..ec6c72da6d 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -852,7 +852,7 @@ int get_breakindent_win(win_T *wp, char *line) if (wp->w_briopt_list > 0) { prev_list += wp->w_briopt_list; } else { - prev_list = (int)(*regmatch.endp - *regmatch.startp); + prev_indent = (int)(*regmatch.endp - *regmatch.startp); } } vim_regfree(regmatch.regprog); @@ -871,12 +871,8 @@ int get_breakindent_win(win_T *wp, char *line) bri += win_col_off2(wp); // add additional indent for numbered lists - if (wp->w_briopt_list != 0) { - if (wp->w_briopt_list > 0) { - bri += prev_list; - } else { - bri = prev_list; - } + if (wp->w_briopt_list > 0) { + bri += prev_list; } // indent minus the length of the showbreak string -- cgit