From 371823d407d7d7519735131bcad4670c62a731a7 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Wed, 5 Apr 2023 21:13:53 +0200 Subject: refactor: make error message definitions const message.c functions now take const char * as a format. Error message definitions can be made const. --- src/nvim/fold.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 7306131574..2b33f00c67 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -101,7 +101,7 @@ typedef void (*LevelGetter)(fline_T *); #ifdef INCLUDE_GENERATED_DECLARATIONS # include "fold.c.generated.h" #endif -static char *e_nofold = N_("E490: No fold found"); +static const char *e_nofold = N_("E490: No fold found"); // While updating the folds lines between invalid_top and invalid_bot have an // undefined fold level. Only used for the window currently being updated. -- cgit From 9408f2dcf7cade2631688300e9b58eed6bc5219a Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 19:40:57 +0200 Subject: refactor: remove redundant const char * casts --- src/nvim/fold.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 2b33f00c67..71984e806d 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1786,7 +1786,7 @@ char *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldinfo } } if (*p != NUL) { - p = transstr((const char *)text, true); + p = transstr(text, true); xfree(text); text = p; } -- cgit From 8e2903d2fe810cfa3be41fc1e7a4d8394c84cf11 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Apr 2023 09:11:37 +0800 Subject: vim-patch:8.2.1049: Vim9: leaking memory when using continuation line Problem: Vim9: leaking memory when using continuation line. Solution: Keep a pointer to the continuation line in evalarg_T. Centralize checking for a next command. https://github.com/vim/vim/commit/b171fb179053fa631fec74911b5fb9374cb6a8a1 Omit eval_next_line(): Vim9 script only. vim-patch:8.2.1050: missing change in struct Problem: Missing change in struct. Solution: Add missing change. https://github.com/vim/vim/commit/65a8ed37f7bc61fbe5c612a7b0eb0dfc16ad3e11 Co-authored-by: Bram Moolenaar --- src/nvim/fold.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 71984e806d..a0869b54c9 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1749,7 +1749,8 @@ char *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldinfo curbuf = wp->w_buffer; emsg_silent++; // handle exceptions, but don't display errors - text = eval_to_string_safe(wp->w_p_fdt, NULL, was_set_insecurely(wp, "foldtext", OPT_LOCAL)); + text = eval_to_string_safe(wp->w_p_fdt, + was_set_insecurely(wp, "foldtext", OPT_LOCAL)); emsg_silent--; if (text == NULL || did_emsg) { -- cgit From d6e0f3dad2176b2619ea3ca2a8f622c00d4f78af Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 17 Apr 2023 15:09:05 +0800 Subject: vim-patch:8.2.4179: 'foldtext' is evaluated in the current script context Problem: 'foldtext' is evaluated in the current script context. Solution: Use the script context where the option was set. https://github.com/vim/vim/commit/9530b580a7b71960dbbdb2b12a3aafeb540bd135 Script version is N/A. Co-authored-by: Bram Moolenaar --- src/nvim/fold.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index a0869b54c9..2066da280a 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1742,16 +1742,19 @@ char *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldinfo set_vim_var_string(VV_FOLDDASHES, dashes, -1); set_vim_var_nr(VV_FOLDLEVEL, (varnumber_T)level); - // skip evaluating foldtext on errors + // skip evaluating 'foldtext' on errors if (!got_fdt_error) { - win_T *save_curwin = curwin; + win_T *const save_curwin = curwin; + const sctx_T saved_sctx = current_sctx; + curwin = wp; curbuf = wp->w_buffer; + current_sctx = wp->w_p_script_ctx[WV_FDT].script_ctx; - emsg_silent++; // handle exceptions, but don't display errors + emsg_off++; // handle exceptions, but don't display errors text = eval_to_string_safe(wp->w_p_fdt, was_set_insecurely(wp, "foldtext", OPT_LOCAL)); - emsg_silent--; + emsg_off--; if (text == NULL || did_emsg) { got_fdt_error = true; @@ -1759,6 +1762,7 @@ char *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldinfo curwin = save_curwin; curbuf = curwin->w_buffer; + current_sctx = saved_sctx; } last_lnum = lnum; last_wp = wp; -- 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/fold.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 2066da280a..13329040e1 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -201,7 +201,7 @@ bool hasFoldingWin(win_T *const win, const linenr_T lnum, linenr_T *const firstp if (first == 0) { // Recursively search for a fold that contains "lnum". garray_T *gap = &win->w_folds; - for (;;) { + while (true) { if (!foldFind(gap, lnum_rel, &fp)) { break; } @@ -430,7 +430,7 @@ void foldOpenCursor(void) { checkupdate(curwin); if (hasAnyFolding(curwin)) { - for (;;) { + while (true) { int done = DONE_NOTHING; (void)setManualFold(curwin->w_cursor, true, false, &done); if (!(done & DONE_ACTION)) { @@ -562,7 +562,7 @@ void foldCreate(win_T *wp, pos_T start, pos_T end) i = 0; } else { fold_T *fp; - for (;;) { + while (true) { if (!foldFind(gap, start_rel.lnum, &fp)) { break; } @@ -683,7 +683,7 @@ void deleteFold(win_T *const wp, const linenr_T start, const linenr_T end, const garray_T *found_ga = NULL; linenr_T lnum_off = 0; bool use_level = false; - for (;;) { + while (true) { fold_T *fp; if (!foldFind(gap, lnum - lnum_off, &fp)) { break; @@ -865,7 +865,7 @@ int foldMoveTo(const bool updown, const int dir, const long count) linenr_T lnum_found = curwin->w_cursor.lnum; int level = 0; bool last = false; - for (;;) { + while (true) { if (!foldFind(gap, curwin->w_cursor.lnum - lnum_off, &fp)) { if (!updown || gap->ga_len == 0) { break; @@ -1104,7 +1104,7 @@ static int foldLevelWin(win_T *wp, linenr_T lnum) // Recursively search for a fold that contains "lnum". garray_T *gap = &wp->w_folds; - for (;;) { + while (true) { if (!foldFind(gap, lnum_rel, &fp)) { break; } @@ -1201,7 +1201,7 @@ static linenr_T setManualFoldWin(win_T *wp, linenr_T lnum, int opening, int recu // Find the fold, open or close it. garray_T *gap = &wp->w_folds; - for (;;) { + while (true) { if (!foldFind(gap, lnum, &fp)) { // If there is a following fold, continue there next time. if (fp != NULL && fp < (fold_T *)gap->ga_data + gap->ga_len) { @@ -2509,7 +2509,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level, } // delete following folds that end before the current line - for (;;) { + while (true) { fp2 = fp + 1; if (fp2 >= (fold_T *)gap->ga_data + gap->ga_len || fp2->fd_top > flp->lnum) { -- cgit From 58f94861442d182e153ba56b63b5b9845b295d2f Mon Sep 17 00:00:00 2001 From: Brandon Simmons <34775764+simmsbra@users.noreply.github.com> Date: Thu, 20 Jul 2023 19:56:08 -0500 Subject: fix(folds): update folds in Insert mode with fdm=indent (#24402) Previously, when using foldmethod=indent, inserting an unindented line would inadvertently open closed folds below it. As a performance improvement, folds were only updated once, across all lines, after Insert mode was exited. Now, the performance improvement is no longer being used when foldmethod=indent, so folds are updated multiple times during Insert mode, but only across the lines that are changing, which preserves the folds (and their open/close states) instead of recreating them. --- src/nvim/fold.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 13329040e1..bdf2e26ac6 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -771,7 +771,7 @@ void clearFolding(win_T *win) /// The changes in lines from top to bot (inclusive). void foldUpdate(win_T *wp, linenr_T top, linenr_T bot) { - if (disable_fold_update || State & MODE_INSERT) { + if (disable_fold_update || (State & MODE_INSERT && !foldmethodIsIndent(wp))) { return; } -- cgit From cefd774fac76b91f5368833555818c80c992c3b1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 24 Aug 2023 15:14:23 +0200 Subject: refactor(memline): distinguish mutating uses of ml_get_buf() ml_get_buf() takes a third parameters to indicate whether the caller wants to mutate the memline data in place. However the vast majority of the call sites is using this function just to specify a buffer but without any mutation. This makes it harder to grep for the places which actually perform mutation. Solution: Remove the bool param from ml_get_buf(). it now works like ml_get() except for a non-current buffer. Add a new ml_get_buf_mut() function for the mutating use-case, which can be grepped along with the other ml_replace() etc functions which can modify the memline. --- src/nvim/fold.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index bdf2e26ac6..595136d590 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1601,7 +1601,7 @@ static void foldAddMarker(buf_T *buf, pos_T pos, const char *marker, size_t mark linenr_T lnum = pos.lnum; // Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end - char *line = ml_get_buf(buf, lnum, false); + char *line = ml_get_buf(buf, lnum); size_t line_len = strlen(line); size_t added = 0; @@ -1661,7 +1661,7 @@ static void foldDelMarker(buf_T *buf, linenr_T lnum, char *marker, size_t marker } char *cms = buf->b_p_cms; - char *line = ml_get_buf(buf, lnum, false); + char *line = ml_get_buf(buf, lnum); for (char *p = line; *p != NUL; p++) { if (strncmp(p, marker, markerlen) != 0) { continue; @@ -2874,7 +2874,7 @@ static void foldlevelIndent(fline_T *flp) linenr_T lnum = flp->lnum + flp->off; buf_T *buf = flp->wp->w_buffer; - char *s = skipwhite(ml_get_buf(buf, lnum, false)); + char *s = skipwhite(ml_get_buf(buf, lnum)); // empty line or lines starting with a character in 'foldignore': level // depends on surrounding lines @@ -3036,7 +3036,7 @@ static void foldlevelMarker(fline_T *flp) flp->start = 0; flp->lvl_next = flp->lvl; - char *s = ml_get_buf(flp->wp->w_buffer, flp->lnum + flp->off, false); + char *s = ml_get_buf(flp->wp->w_buffer, flp->lnum + flp->off); while (*s) { if (*s == cstart && strncmp(s + 1, startmarker, foldstartmarkerlen - 1) == 0) { -- cgit From 008154954791001efcc46c28146e21403f3a698b Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 21 Aug 2023 14:52:17 +0200 Subject: refactor(change): do API changes to buffer without curbuf switch Most of the messy things when changing a non-current buffer is not about the buffer, it is about windows. In particular, it is about `curwin`. When editing a non-current buffer which is displayed in some other window in the current tabpage, one such window will be "borrowed" as the curwin. But this means if two or more non-current windows displayed the buffers, one of them will be treated differenty. this is not desirable. In particular, with nvim_buf_set_text, cursor _column_ position was only corrected for one single window. Two new tests are added: the test with just one non-current window passes, but the one with two didn't. Two corresponding such tests were also added for nvim_buf_set_lines. This already worked correctly on master, but make sure this is well-tested for future refactors. Also, nvim_create_buf no longer invokes autocmds just because you happened to use `scratch=true`. No option value was changed, therefore OptionSet must not be fired. --- src/nvim/fold.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 595136d590..a6cb0b568c 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -743,8 +743,7 @@ void deleteFold(win_T *const wp, const linenr_T start, const linenr_T end, const } if (last_lnum > 0) { - // TODO(teto): pass the buffer - changed_lines(first_lnum, (colnr_T)0, last_lnum, 0L, false); + changed_lines(wp->w_buffer, first_lnum, (colnr_T)0, last_lnum, 0L, false); // send one nvim_buf_lines_event at the end // last_lnum is the line *after* the last line of the outermost fold @@ -1580,8 +1579,7 @@ static void foldCreateMarkers(win_T *wp, pos_T start, pos_T end) // Update both changes here, to avoid all folds after the start are // changed when the start marker is inserted and the end isn't. - // TODO(teto): pass the buffer - changed_lines(start.lnum, (colnr_T)0, end.lnum, 0L, false); + changed_lines(buf, start.lnum, (colnr_T)0, end.lnum, 0L, false); // Note: foldAddMarker() may not actually change start and/or end if // u_save() is unable to save the buffer line, but we send the -- cgit From 71530cc972576e6656431b6d000aec9b69a0997e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Sep 2023 20:29:18 +0800 Subject: feat(folds): support virtual text format for 'foldtext' (#25209) Co-authored-by: Lewis Russell --- src/nvim/fold.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index a6cb0b568c..1d5ba49301 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -12,12 +12,14 @@ #include #include +#include "nvim/api/extmark.h" #include "nvim/ascii.h" #include "nvim/buffer_defs.h" #include "nvim/buffer_updates.h" #include "nvim/change.h" #include "nvim/charset.h" #include "nvim/cursor.h" +#include "nvim/decoration.h" #include "nvim/diff.h" #include "nvim/drawscreen.h" #include "nvim/eval.h" @@ -1702,8 +1704,9 @@ static void foldDelMarker(buf_T *buf, linenr_T lnum, char *marker, size_t marker /// @return the text for a closed fold /// /// Otherwise the result is in allocated memory. -char *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldinfo, char *buf) - FUNC_ATTR_NONNULL_ARG(1) +char *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldinfo, char *buf, + VirtText *vt) + FUNC_ATTR_NONNULL_ALL { char *text = NULL; // an error occurred when evaluating 'fdt' setting @@ -1750,8 +1753,22 @@ char *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldinfo current_sctx = wp->w_p_script_ctx[WV_FDT].script_ctx; emsg_off++; // handle exceptions, but don't display errors - text = eval_to_string_safe(wp->w_p_fdt, - was_set_insecurely(wp, "foldtext", OPT_LOCAL)); + + Object obj = eval_foldtext(wp); + if (obj.type == kObjectTypeArray) { + Error err = ERROR_INIT; + *vt = parse_virt_text(obj.data.array, &err, NULL); + if (!ERROR_SET(&err)) { + *buf = NUL; + text = buf; + } + api_clear_error(&err); + } else if (obj.type == kObjectTypeString) { + text = obj.data.string.data; + obj = NIL; + } + api_free_object(obj); + emsg_off--; if (text == NULL || did_emsg) { @@ -2929,7 +2946,7 @@ static void foldlevelExpr(fline_T *flp) const bool save_keytyped = KeyTyped; int c; - const int n = eval_foldexpr(flp->wp->w_p_fde, &c); + const int n = eval_foldexpr(flp->wp, &c); KeyTyped = save_keytyped; switch (c) { @@ -3320,10 +3337,20 @@ void f_foldtextresult(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) foldinfo_T info = fold_info(curwin, lnum); if (info.fi_lines > 0) { - char *text = get_foldtext(curwin, lnum, lnum + info.fi_lines - 1, info, buf); + VirtText vt = VIRTTEXT_EMPTY; + char *text = get_foldtext(curwin, lnum, lnum + info.fi_lines - 1, info, buf, &vt); if (text == buf) { text = xstrdup(text); } + if (kv_size(vt) > 0) { + assert(*text == NUL); + for (size_t i = 0; i < kv_size(vt); i++) { + char *new_text = concat_str(text, kv_A(vt, i).text); + xfree(text); + text = new_text; + } + } + clear_virttext(&vt); rettv->vval.v_string = text; } -- cgit From 64e8a3c4d19eab40888fbac36b96e97bd9d68c42 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 22 Sep 2023 15:36:24 +0800 Subject: fix(ui): handle virtual text with multiple hl in more cases (#25304) --- src/nvim/fold.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 1d5ba49301..d874e904d0 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -3344,8 +3344,13 @@ void f_foldtextresult(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } if (kv_size(vt) > 0) { assert(*text == NUL); - for (size_t i = 0; i < kv_size(vt); i++) { - char *new_text = concat_str(text, kv_A(vt, i).text); + for (size_t i = 0; i < kv_size(vt);) { + int attr = 0; + char *new_text = next_virt_text_chunk(vt, &i, &attr); + if (new_text == NULL) { + break; + } + new_text = concat_str(text, new_text); xfree(text); text = new_text; } -- 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/fold.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index d874e904d0..298d6776bd 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -12,7 +12,10 @@ #include #include +#include "klib/kvec.h" #include "nvim/api/extmark.h" +#include "nvim/api/private/defs.h" +#include "nvim/api/private/helpers.h" #include "nvim/ascii.h" #include "nvim/buffer_defs.h" #include "nvim/buffer_updates.h" @@ -24,7 +27,6 @@ #include "nvim/drawscreen.h" #include "nvim/eval.h" #include "nvim/eval/typval.h" -#include "nvim/eval/typval_defs.h" #include "nvim/ex_session.h" #include "nvim/extmark.h" #include "nvim/fold.h" @@ -42,6 +44,7 @@ #include "nvim/option.h" #include "nvim/os/input.h" #include "nvim/plines.h" +#include "nvim/pos.h" #include "nvim/search.h" #include "nvim/strings.h" #include "nvim/syntax.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/fold.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 298d6776bd..6a9dbe9edc 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -41,7 +41,7 @@ #include "nvim/message.h" #include "nvim/move.h" #include "nvim/ops.h" -#include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/os/input.h" #include "nvim/plines.h" #include "nvim/pos.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/fold.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 6a9dbe9edc..2e38f9ca3d 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -363,7 +363,7 @@ int foldmethodIsDiff(win_T *wp) // closeFold() {{{2 /// Close fold for current window at position "pos". /// Repeat "count" times. -void closeFold(pos_T pos, long count) +void closeFold(pos_T pos, int count) { setFoldRepeat(pos, count, false); } @@ -417,7 +417,7 @@ void opFoldRange(pos_T firstpos, pos_T lastpos, int opening, int recurse, int ha // openFold() {{{2 /// Open fold for current window at position "pos". /// Repeat "count" times. -void openFold(pos_T pos, long count) +void openFold(pos_T pos, int count) { setFoldRepeat(pos, count, true); } @@ -847,7 +847,7 @@ void foldUpdateAll(win_T *win) /// @return FAIL if not moved. /// /// @param dir FORWARD or BACKWARD -int foldMoveTo(const bool updown, const int dir, const long count) +int foldMoveTo(const bool updown, const int dir, const int count) { int retval = FAIL; linenr_T lnum; @@ -856,7 +856,7 @@ int foldMoveTo(const bool updown, const int dir, const long count) checkupdate(curwin); // Repeat "count" times. - for (long n = 0; n < count; n++) { + for (int n = 0; n < count; n++) { // Find nested folds. Stop when a fold is closed. The deepest fold // that moves the cursor is used. linenr_T lnum_off = 0; @@ -1136,7 +1136,7 @@ static void checkupdate(win_T *wp) // setFoldRepeat() {{{2 /// Open or close fold for current window at position `pos`. /// Repeat "count" times. -static void setFoldRepeat(pos_T pos, long count, int do_open) +static void setFoldRepeat(pos_T pos, int count, int do_open) { for (int n = 0; n < count; n++) { int done = DONE_NOTHING; @@ -1816,11 +1816,11 @@ char *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldinfo } } if (text == NULL) { - long count = lnume - lnum + 1; + int count = lnume - lnum + 1; vim_snprintf(buf, FOLD_TEXT_LEN, - NGETTEXT("+--%3ld line folded", - "+--%3ld lines folded ", count), + NGETTEXT("+--%3d line folded", + "+--%3d lines folded ", count), count); text = buf; } @@ -3304,8 +3304,8 @@ void f_foldtext(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) } } } - long count = foldend - foldstart + 1; - char *txt = NGETTEXT("+-%s%3ld line: ", "+-%s%3ld lines: ", count); + int count = foldend - foldstart + 1; + char *txt = NGETTEXT("+-%s%3d line: ", "+-%s%3d lines: ", count); size_t len = strlen(txt) + strlen(dashes) // for %s + 20 // for %3ld -- cgit From 5f03a1eaabfc8de2b3a9c666fcd604763f41e152 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Fri, 20 Oct 2023 15:10:33 +0200 Subject: build(lint): remove unnecessary clint.py rules Uncrustify is the source of truth where possible. Remove any redundant checks from clint.py. --- src/nvim/fold.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 2e38f9ca3d..a3aabede5e 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -1783,7 +1783,7 @@ char *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldinfo current_sctx = saved_sctx; } last_lnum = lnum; - last_wp = wp; + last_wp = wp; set_vim_var_string(VV_FOLDDASHES, NULL, -1); if (!did_emsg && save_did_emsg) { -- 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/fold.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index a3aabede5e..fa33abdce7 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -650,7 +650,7 @@ void foldCreate(win_T *wp, pos_T start, pos_T end) // We want the new fold to be closed. If it would remain open because // of using 'foldlevel', need to adjust fd_flags of containing folds. if (use_level && !closed && level < wp->w_p_fdl) { - closeFold(start, 1L); + closeFold(start, 1); } if (!use_level) { wp->w_fold_manual = true; @@ -748,7 +748,7 @@ void deleteFold(win_T *const wp, const linenr_T start, const linenr_T end, const } if (last_lnum > 0) { - changed_lines(wp->w_buffer, first_lnum, (colnr_T)0, last_lnum, 0L, false); + changed_lines(wp->w_buffer, first_lnum, (colnr_T)0, last_lnum, 0, false); // send one nvim_buf_lines_event at the end // last_lnum is the line *after* the last line of the outermost fold @@ -1584,7 +1584,7 @@ static void foldCreateMarkers(win_T *wp, pos_T start, pos_T end) // Update both changes here, to avoid all folds after the start are // changed when the start marker is inserted and the end isn't. - changed_lines(buf, start.lnum, (colnr_T)0, end.lnum, 0L, false); + changed_lines(buf, start.lnum, (colnr_T)0, end.lnum, 0, false); // Note: foldAddMarker() may not actually change start and/or end if // u_save() is unable to save the buffer line, but we send the @@ -2295,7 +2295,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level, // nested folds (with relative line numbers) down. foldMarkAdjustRecurse(flp->wp, &fp->fd_nested, (linenr_T)0, (linenr_T)MAXLNUM, - (fp->fd_top - firstlnum), 0L); + (fp->fd_top - firstlnum), 0); } else { // Will move fold down, move nested folds relatively up. foldMarkAdjustRecurse(flp->wp, &fp->fd_nested, @@ -2367,7 +2367,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level, fp->fd_len = startlnum - fp->fd_top; foldMarkAdjustRecurse(flp->wp, &fp->fd_nested, fp->fd_len, (linenr_T)MAXLNUM, - (linenr_T)MAXLNUM, 0L); + (linenr_T)MAXLNUM, 0); fold_changed = true; } } else { @@ -2861,7 +2861,7 @@ static void foldMerge(win_T *const wp, fold_T *fp1, garray_T *gap, fold_T *fp2) // If the last nested fold in fp1 touches the first nested fold in fp2, // merge them recursively. - if (foldFind(gap1, fp1->fd_len - 1, &fp3) && foldFind(gap2, 0L, &fp4)) { + if (foldFind(gap1, fp1->fd_len - 1, &fp3) && foldFind(gap2, 0, &fp4)) { foldMerge(wp, fp3, gap2, fp4); } -- 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/fold.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index fa33abdce7..b5b55b1b16 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -110,8 +110,8 @@ static const char *e_nofold = N_("E490: No fold found"); // While updating the folds lines between invalid_top and invalid_bot have an // undefined fold level. Only used for the window currently being updated. -static linenr_T invalid_top = (linenr_T)0; -static linenr_T invalid_bot = (linenr_T)0; +static linenr_T invalid_top = 0; +static linenr_T invalid_bot = 0; // When using 'foldexpr' we sometimes get the level of the next line, which // calls foldlevel() to get the level of the current line, which hasn't been @@ -268,7 +268,7 @@ static int foldLevel(linenr_T lnum) { // While updating the folds lines between invalid_top and invalid_bot have // an undefined fold level. Otherwise update the folds first. - if (invalid_top == (linenr_T)0) { + if (invalid_top == 0) { checkupdate(curwin); } else if (lnum == prev_lnum && prev_lnum_lvl >= 0) { return prev_lnum_lvl; @@ -748,7 +748,7 @@ void deleteFold(win_T *const wp, const linenr_T start, const linenr_T end, const } if (last_lnum > 0) { - changed_lines(wp->w_buffer, first_lnum, (colnr_T)0, last_lnum, 0, false); + changed_lines(wp->w_buffer, first_lnum, 0, last_lnum, 0, false); // send one nvim_buf_lines_event at the end // last_lnum is the line *after* the last line of the outermost fold @@ -1129,7 +1129,7 @@ static void checkupdate(win_T *wp) return; } - foldUpdate(wp, (linenr_T)1, (linenr_T)MAXLNUM); // will update all + foldUpdate(wp, 1, (linenr_T)MAXLNUM); // will update all wp->w_foldinvalid = false; } @@ -1364,7 +1364,7 @@ void foldMarkAdjust(win_T *wp, linenr_T line1, linenr_T line2, linenr_T amount, } // If appending a line in Insert mode, it should be included in the fold // just above the line. - if ((State & MODE_INSERT) && amount == (linenr_T)1 && line2 == MAXLNUM) { + if ((State & MODE_INSERT) && amount == 1 && line2 == MAXLNUM) { line1--; } foldMarkAdjustRecurse(wp, &wp->w_folds, line1, line2, amount, amount_after); @@ -1382,7 +1382,7 @@ static void foldMarkAdjustRecurse(win_T *wp, garray_T *gap, linenr_T line1, line // In Insert mode an inserted line at the top of a fold is considered part // of the fold, otherwise it isn't. - if ((State & MODE_INSERT) && amount == (linenr_T)1 && line2 == MAXLNUM) { + if ((State & MODE_INSERT) && amount == 1 && line2 == MAXLNUM) { top = line1 + 1; } else { top = line1; @@ -1584,7 +1584,7 @@ static void foldCreateMarkers(win_T *wp, pos_T start, pos_T end) // Update both changes here, to avoid all folds after the start are // changed when the start marker is inserted and the end isn't. - changed_lines(buf, start.lnum, (colnr_T)0, end.lnum, 0, false); + changed_lines(buf, start.lnum, 0, end.lnum, 0, false); // Note: foldAddMarker() may not actually change start and/or end if // u_save() is unable to save the buffer line, but we send the @@ -1911,7 +1911,7 @@ static void foldtext_cleanup(char *str) static void foldUpdateIEMS(win_T *const wp, linenr_T top, linenr_T bot) { // Avoid problems when being called recursively. - if (invalid_top != (linenr_T)0) { + if (invalid_top != 0) { return; } @@ -2132,7 +2132,7 @@ static void foldUpdateIEMS(win_T *const wp, linenr_T top, linenr_T bot) } } - invalid_top = (linenr_T)0; + invalid_top = 0; } // foldUpdateIEMSRecurse() {{{2 @@ -2294,12 +2294,12 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level, // We will move the start of this fold up, hence we move all // nested folds (with relative line numbers) down. foldMarkAdjustRecurse(flp->wp, &fp->fd_nested, - (linenr_T)0, (linenr_T)MAXLNUM, + 0, (linenr_T)MAXLNUM, (fp->fd_top - firstlnum), 0); } else { // Will move fold down, move nested folds relatively up. foldMarkAdjustRecurse(flp->wp, &fp->fd_nested, - (linenr_T)0, + 0, (firstlnum - fp->fd_top - 1), (linenr_T)MAXLNUM, (fp->fd_top - firstlnum)); @@ -2537,7 +2537,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level, if (fp2->fd_top < flp->lnum) { // Make fold that includes lnum start at lnum. foldMarkAdjustRecurse(flp->wp, &fp2->fd_nested, - (linenr_T)0, (flp->lnum - fp2->fd_top - 1), + 0, (flp->lnum - fp2->fd_top - 1), (linenr_T)MAXLNUM, (fp2->fd_top - flp->lnum)); fp2->fd_len -= flp->lnum - fp2->fd_top; fp2->fd_top = flp->lnum; @@ -2675,7 +2675,7 @@ static void foldRemove(win_T *const wp, garray_T *gap, linenr_T top, linenr_T bo if (fp->fd_top + fp->fd_len - 1 > bot) { // 5: Make fold that includes bot start below bot. foldMarkAdjustRecurse(wp, &fp->fd_nested, - (linenr_T)0, (bot - fp->fd_top), + 0, (bot - fp->fd_top), (linenr_T)MAXLNUM, (fp->fd_top - bot - 1)); fp->fd_len -= bot - fp->fd_top + 1; fp->fd_top = bot + 1; @@ -3132,7 +3132,7 @@ int put_folds(FILE *fd, win_T *wp) { if (foldmethodIsManual(wp)) { if (put_line(fd, "silent! normal! zE") == FAIL - || put_folds_recurse(fd, &wp->w_folds, (linenr_T)0) == FAIL + || put_folds_recurse(fd, &wp->w_folds, 0) == FAIL || put_line(fd, "let &fdl = &fdl") == FAIL) { return FAIL; } @@ -3140,7 +3140,7 @@ int put_folds(FILE *fd, win_T *wp) // If some folds are manually opened/closed, need to restore that. if (wp->w_fold_manual) { - return put_foldopen_recurse(fd, wp, &wp->w_folds, (linenr_T)0); + return put_foldopen_recurse(fd, wp, &wp->w_folds, 0); } return OK; -- 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/fold.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index b5b55b1b16..4c596d9d96 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.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 - // vim: set fdm=marker fdl=1 fdc=3 // fold.c: code for folding @@ -2741,7 +2738,6 @@ static void truncate_fold(win_T *const wp, fold_T *fp, linenr_T end) } #define FOLD_END(fp) ((fp)->fd_top + (fp)->fd_len - 1) -// -V:VALID_FOLD:V560 #define VALID_FOLD(fp, gap) \ ((gap)->ga_len > 0 && (fp) < ((fold_T *)(gap)->ga_data + (gap)->ga_len)) #define FOLD_INDEX(fp, gap) ((size_t)((fp) - ((fold_T *)(gap)->ga_data))) -- cgit From a827003e3052c6d9ee7bdb71518182e9bd76317d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 25 Nov 2023 11:32:32 +0100 Subject: build: rework IWYU mapping files Create mapping to most of the C spec and some POSIX specific functions. This is more robust than relying files shipped with IWYU. --- src/nvim/fold.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 4c596d9d96..477e4a20cd 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -20,6 +20,7 @@ #include "nvim/charset.h" #include "nvim/cursor.h" #include "nvim/decoration.h" +#include "nvim/decoration_defs.h" #include "nvim/diff.h" #include "nvim/drawscreen.h" #include "nvim/eval.h" -- cgit From 6361806aa28edca55ad3316a58bc3e936df9c0eb Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 26 Nov 2023 22:58:52 +0800 Subject: refactor: move garray_T to garray_defs.h (#26227) --- src/nvim/fold.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 477e4a20cd..1cd57946a6 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -20,7 +20,6 @@ #include "nvim/charset.h" #include "nvim/cursor.h" #include "nvim/decoration.h" -#include "nvim/decoration_defs.h" #include "nvim/diff.h" #include "nvim/drawscreen.h" #include "nvim/eval.h" @@ -29,6 +28,7 @@ #include "nvim/extmark.h" #include "nvim/fold.h" #include "nvim/garray.h" +#include "nvim/garray_defs.h" #include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/indent.h" -- 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/fold.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 1cd57946a6..61c67991cd 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -27,6 +27,7 @@ #include "nvim/ex_session.h" #include "nvim/extmark.h" #include "nvim/fold.h" +#include "nvim/func_attr.h" #include "nvim/garray.h" #include "nvim/garray_defs.h" #include "nvim/gettext.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/fold.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 61c67991cd..1fc3f93c4a 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -43,7 +43,7 @@ #include "nvim/option_vars.h" #include "nvim/os/input.h" #include "nvim/plines.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/search.h" #include "nvim/strings.h" #include "nvim/syntax.h" -- cgit From 6c14ae6bfaf51415b555e9a6b85d1d280976358d Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 27 Nov 2023 20:27:32 +0100 Subject: refactor: rename types.h to types_defs.h --- src/nvim/fold.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 1fc3f93c4a..3452a7ae50 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -47,7 +47,7 @@ #include "nvim/search.h" #include "nvim/strings.h" #include "nvim/syntax.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/undo.h" #include "nvim/vim.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/fold.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 3452a7ae50..69857d2628 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -13,7 +13,7 @@ #include "nvim/api/extmark.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/buffer_defs.h" #include "nvim/buffer_updates.h" #include "nvim/change.h" @@ -49,7 +49,7 @@ #include "nvim/syntax.h" #include "nvim/types_defs.h" #include "nvim/undo.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" // local declarations. {{{1 // typedef fold_T {{{2 -- cgit From a6cba103cebce535279db197f9efeb34e9d1171f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 20:32:40 +0800 Subject: refactor: move some constants out of vim_defs.h (#26298) --- src/nvim/fold.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/fold.c') diff --git a/src/nvim/fold.c b/src/nvim/fold.c index 69857d2628..c905b2d3ed 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -45,6 +45,7 @@ #include "nvim/plines.h" #include "nvim/pos_defs.h" #include "nvim/search.h" +#include "nvim/state_defs.h" #include "nvim/strings.h" #include "nvim/syntax.h" #include "nvim/types_defs.h" -- cgit