From 39f8aaeb815c2e31cffec12ef36ad4f25df91602 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 24 Jan 2020 09:48:58 +0100 Subject: fix(status): handle unprintable chars in the statusline --- src/nvim/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 5dcb10751f..129a8c6fb2 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3311,7 +3311,7 @@ void maketitle(void) buf_p += MIN(size, SPACE_FOR_FNAME); } else { buf_p += transstr_buf((const char *)path_tail(curbuf->b_fname), - buf_p, SPACE_FOR_FNAME + 1, true); + -1, buf_p, SPACE_FOR_FNAME + 1, true); } switch (bufIsChanged(curbuf) -- cgit From 968cd1ed933c039b8d60b0110bc6b539c71e387d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 16 Feb 2023 07:25:16 +0800 Subject: vim-patch:9.0.1309: scrolling two lines with even line count and 'scrolloff' set Problem: Scrolling two lines with even line count and 'scrolloff' set. Solution: Adjust how the topline is computed. (closes vim/vim#10545) https://github.com/vim/vim/commit/1d6539cf36a7b6d1afe76fb6316fe662f543bf60 Cherry-pick test_scroll_opt.vim changes from patch 8.2.1432. Co-authored-by: Bram Moolenaar --- src/nvim/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 129a8c6fb2..98832a98c9 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1676,7 +1676,7 @@ void enter_buffer(buf_T *buf) maketitle(); // when autocmds didn't change it if (curwin->w_topline == 1 && !curwin->w_topline_was_set) { - scroll_cursor_halfway(false); // redisplay at correct position + scroll_cursor_halfway(false, false); // redisplay at correct position } // Change directories when the 'acd' option is set. -- cgit From 93c627b90b4955967943b7a47fe63b094a0c50e6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 20 Feb 2023 23:02:05 +0800 Subject: vim-patch:9.0.1331: illegal memory access when using :ball in Visual mode (#22343) Problem: Illegal memory access when using :ball in Visual mode. Solution: Stop Visual mode when using :ball. (Pavel Mayorov, closes vim/vim#11923) https://github.com/vim/vim/commit/e1121b139480f53d1b06f84f3e4574048108fa0b Co-authored-by: Pavel Mayorov --- src/nvim/buffer.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 98832a98c9..7a4e5d3eeb 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3600,6 +3600,10 @@ void ex_buffer_all(exarg_T *eap) all = true; } + // Stop Visual mode, the cursor and "VIsual" may very well be invalid after + // switching to another buffer. + reset_VIsual_and_resel(); + setpcmark(); // Close superfluous windows (two windows for the same buffer). -- cgit From d6ecead36406233cc56353dd05f3380f0497630f Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 14 Mar 2023 11:49:46 +0100 Subject: refactor(screen): screen.c delenda est drawscreen.c vs screen.c makes absolutely no sense. The screen exists only to draw upon it, therefore helper functions are distributed randomly between screen.c and the file that does the redrawing. In addition screen.c does a lot of drawing on the screen. It made more sense for vim/vim as our grid.c is their screen.c Not sure if we want to dump all the code for option chars into optionstr.c, so keep these in a optionchar.c for now. --- src/nvim/buffer.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 7a4e5d3eeb..cedbadbaf3 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -87,7 +87,6 @@ #include "nvim/quickfix.h" #include "nvim/regexp.h" #include "nvim/runtime.h" -#include "nvim/screen.h" #include "nvim/search.h" #include "nvim/sign.h" #include "nvim/spell.h" -- cgit From 204a8b17c8ebab1619cc47a920a06dcc348d75f7 Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Sat, 18 Mar 2023 12:44:44 +0100 Subject: fix(column): rebuild status column when sign column is invalidated (#22690) * fix(column): rebuild status column when sign column is invalidated Problem: When implementing a custom sign column through `'statuscolumn'`, the status column is not properly rebuilt when the sign column width changes. Solution: Force a rebuild of the status column when the sign column width is invalidated. * test(column): 'statuscolumn' has correct width when (un)placing signs --- src/nvim/buffer.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index cedbadbaf3..9a757960af 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -4109,6 +4109,7 @@ void buf_signcols_del_check(buf_T *buf, linenr_T line1, linenr_T line2) if (!buf->b_signcols.sentinel) { buf->b_signcols.valid = false; + invalidate_statuscol(NULL, buf); return; } @@ -4117,6 +4118,7 @@ void buf_signcols_del_check(buf_T *buf, linenr_T line1, linenr_T line2) if (sent >= line1 && sent <= line2) { // Only invalidate when removing signs at the sentinel line. buf->b_signcols.valid = false; + invalidate_statuscol(NULL, buf); } } @@ -4132,6 +4134,7 @@ void buf_signcols_add_check(buf_T *buf, sign_entry_T *added) if (!added || !buf->b_signcols.sentinel) { buf->b_signcols.valid = false; + invalidate_statuscol(NULL, buf); return; } -- cgit From eeac80de0cf45951dd696f82e5a823c6de20728c Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Sun, 19 Mar 2023 10:21:49 +0100 Subject: fix(column): invalidate statuscolumn width when UPD_NOT_VALID (#22723) --- src/nvim/buffer.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 9a757960af..cedbadbaf3 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -4109,7 +4109,6 @@ void buf_signcols_del_check(buf_T *buf, linenr_T line1, linenr_T line2) if (!buf->b_signcols.sentinel) { buf->b_signcols.valid = false; - invalidate_statuscol(NULL, buf); return; } @@ -4118,7 +4117,6 @@ void buf_signcols_del_check(buf_T *buf, linenr_T line1, linenr_T line2) if (sent >= line1 && sent <= line2) { // Only invalidate when removing signs at the sentinel line. buf->b_signcols.valid = false; - invalidate_statuscol(NULL, buf); } } @@ -4134,7 +4132,6 @@ void buf_signcols_add_check(buf_T *buf, sign_entry_T *added) if (!added || !buf->b_signcols.sentinel) { buf->b_signcols.valid = false; - invalidate_statuscol(NULL, buf); return; } -- cgit 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/buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index cedbadbaf3..fb674774c6 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -106,8 +106,8 @@ # include "buffer.c.generated.h" #endif -static char *e_auabort = N_("E855: Autocommands caused command to abort"); -static char e_attempt_to_delete_buffer_that_is_in_use_str[] +static const char *e_auabort = N_("E855: Autocommands caused command to abort"); +static const char e_attempt_to_delete_buffer_that_is_in_use_str[] = N_("E937: Attempt to delete a buffer that is in use: %s"); // Number of times free_buffer() was called. -- 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/buffer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index fb674774c6..d8282734d4 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -268,7 +268,7 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags_arg) int save_bin = curbuf->b_p_bin; int perm; - perm = os_getperm((const char *)curbuf->b_ffname); + perm = os_getperm(curbuf->b_ffname); if (perm >= 0 && (0 || S_ISFIFO(perm) || S_ISSOCK(perm) # ifdef OPEN_CHR_FILES @@ -3309,8 +3309,7 @@ void maketitle(void) SPACE_FOR_FNAME + 1); buf_p += MIN(size, SPACE_FOR_FNAME); } else { - buf_p += transstr_buf((const char *)path_tail(curbuf->b_fname), - -1, buf_p, SPACE_FOR_FNAME + 1, true); + buf_p += transstr_buf(path_tail(curbuf->b_fname), -1, buf_p, SPACE_FOR_FNAME + 1, true); } switch (bufIsChanged(curbuf) @@ -3557,7 +3556,7 @@ void fname_expand(buf_T *buf, char **ffname, char **sfname) #ifdef MSWIN if (!buf->b_p_bin) { // If the file name is a shortcut file, use the file it links to. - char *rfname = os_resolve_shortcut((const char *)(*ffname)); + char *rfname = os_resolve_shortcut(*ffname); if (rfname != NULL) { xfree(*ffname); *ffname = rfname; -- cgit From 2d78e656b715119ca11d131a1a932f22f1b4ad36 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Fri, 7 Apr 2023 21:43:00 +0200 Subject: refactor: remove redundant casts --- src/nvim/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index d8282734d4..d1c93733c0 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -2231,7 +2231,7 @@ int buflist_findpat(const char *pattern, const char *pattern_end, bool unlisted, // Repeat this for finding an unlisted buffer if there was no matching // listed buffer. - pat = file_pat_to_reg_pat((char *)pattern, (char *)pattern_end, NULL, false); + pat = file_pat_to_reg_pat(pattern, pattern_end, NULL, false); if (pat == NULL) { return -1; } -- 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/buffer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index d1c93733c0..c63ab804af 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1403,7 +1403,7 @@ int do_buffer(int action, int start, int dir, int count, int forceit) if (buf == NULL) { // No previous buffer, Try 2'nd approach forward = true; buf = curbuf->b_next; - for (;;) { + while (true) { if (buf == NULL) { if (!forward) { // tried both directions break; @@ -2241,7 +2241,7 @@ int buflist_findpat(const char *pattern, const char *pattern_end, bool unlisted, // First try finding a listed buffer. If not found and "unlisted" // is true, try finding an unlisted buffer. find_listed = true; - for (;;) { + while (true) { for (attempt = 0; attempt <= 3; attempt++) { // may add '^' and '$' if (toggledollar) { @@ -3180,7 +3180,7 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate) bool dontwrite = bt_dontwrite(curbuf); vim_snprintf_add(buffer, IOSIZE, "\"%s%s%s%s%s%s", curbufIsChanged() - ? (shortmess(SHM_MOD) ? " [+]" : _(" [Modified]")) : " ", + ? (shortmess(SHM_MOD) ? " [+]" : _(" [Modified]")) : " ", (curbuf->b_flags & BF_NOTEDITED) && !dontwrite ? _("[Not edited]") : "", (curbuf->b_flags & BF_NEW) && !dontwrite @@ -3609,7 +3609,7 @@ void ex_buffer_all(exarg_T *eap) if (had_tab > 0) { goto_tabpage_tp(first_tabpage, true, true); } - for (;;) { + while (true) { tpnext = curtab->tp_next; for (wp = firstwin; wp != NULL; wp = wpnext) { wpnext = wp->w_next; -- cgit From ff34c91194f9ab9d02808f2880029c38a4655eb5 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 17 Apr 2023 17:23:47 +0100 Subject: vim-patch:9.0.1330: handling new value of an option has a long "else if" chain Problem: Handling new value of an option has a long "else if" chain. Solution: Use a function pointer. (Yegappan Lakshmanan, closes vim/vim#12015) https://github.com/vim/vim/commit/af93691b53f38784efce0b93fe7644c44a7e382e --- src/nvim/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index c63ab804af..14a07489a0 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1687,7 +1687,7 @@ void enter_buffer(buf_T *buf) // May need to set the spell language. Can only do this after the buffer // has been properly setup. if (!curbuf->b_help && curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) { - (void)did_set_spelllang(curwin); + (void)parse_spelllang(curwin); } curbuf->b_last_used = time(NULL); -- cgit From 65fdd019b3f74a653b511282745004994d649857 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 29 Apr 2023 19:46:47 +0800 Subject: vim-patch:9.0.1497: the ruler percentage can't be localized (#23389) Problem: The ruler percentage can't be localized. Solution: Use a string that can be translated. (Emir Sari, closes vim/vim#12311) https://github.com/vim/vim/commit/971cd2b8bc3e3a7faa886162cd7568938c627882 Co-authored-by: Emir SARI --- src/nvim/buffer.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 14a07489a0..8d730733d0 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3470,8 +3470,8 @@ void free_titles(void) #endif -/// Get relative cursor position in window into "buf[buflen]", in the form 99%, -/// using "Top", "Bot" or "All" when appropriate. +/// Get relative cursor position in window into "buf[buflen]", in the localized +/// percentage form like %99, 99%; using "Top", "Bot" or "All" when appropriate. void get_rel_pos(win_T *wp, char *buf, int buflen) { // Need at least 3 chars for writing. @@ -3495,9 +3495,20 @@ void get_rel_pos(win_T *wp, char *buf, int buflen) } else if (above <= 0) { xstrlcpy(buf, _("Top"), (size_t)buflen); } else { - vim_snprintf(buf, (size_t)buflen, "%2d%%", above > 1000000L - ? (int)(above / ((above + below) / 100L)) - : (int)(above * 100L / (above + below))); + int perc = (above > 1000000L + ? (int)(above / ((above + below) / 100L)) + : (int)(above * 100L / (above + below))); + + char *p = buf; + size_t l = (size_t)buflen; + if (perc < 10) { + // prepend one space + buf[0] = ' '; + p++; + l--; + } + // localized percentage value + vim_snprintf(p, l, _("%d%%"), perc); } } -- cgit From 189e21ae50efe14d8446db11aee6b50f8022d99f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 15 May 2023 08:13:33 +0800 Subject: vim-patch:9.0.1554: code for handling 'switchbuf' is repeated (#23632) Problem: Code for handling 'switchbuf' is repeated. Solution: Add a function to handle 'switchbuf'. (Yegappan Lakshmanan, closes vim/vim#12397) https://github.com/vim/vim/commit/e42c27d9e8a18e3786f13f17663914cdd0f63f9e Co-authored-by: Yegappan Lakshmanan --- src/nvim/buffer.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 8d730733d0..b2edbf4053 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1459,16 +1459,11 @@ int do_buffer(int action, int start, int dir, int count, int forceit) // make "buf" the current buffer if (action == DOBUF_SPLIT) { // split window first - // If 'switchbuf' contains "useopen": jump to first window containing - // "buf" if one exists - if ((swb_flags & SWB_USEOPEN) && buf_jump_open_win(buf)) { - return OK; - } - // If 'switchbuf' contains "usetab": jump to first window in any tab - // page containing "buf" if one exists - if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf)) { + // If 'switchbuf' is set jump to the window containing "buf". + if (swbuf_goto_win_with_buf(buf) != NULL) { return OK; } + if (win_split(0, 0) == FAIL) { return FAIL; } @@ -2072,17 +2067,8 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit) } if (options & GETF_SWITCH) { - // If 'switchbuf' contains "useopen": jump to first window containing - // "buf" if one exists - if (swb_flags & SWB_USEOPEN) { - wp = buf_jump_open_win(buf); - } - - // If 'switchbuf' contains "usetab": jump to first window in any tab - // page containing "buf" if one exists - if (wp == NULL && (swb_flags & SWB_USETAB)) { - wp = buf_jump_open_tab(buf); - } + // If 'switchbuf' is set jump to the window containing "buf". + wp = swbuf_goto_win_with_buf(buf); // If 'switchbuf' contains "split", "vsplit" or "newtab" and the // current buffer isn't empty: open new tab or window -- cgit From d36dd2bae8e899b40cc21603e600a5046213bc36 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Tue, 16 May 2023 05:33:03 +0200 Subject: refactor: use xstrl{cpy,cat} on IObuff (#23648) Replace usage of STR{CPY,CAT} with xstrl{cpy,cat} when using on IObuff Co-authored-by: ii14 --- src/nvim/buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index b2edbf4053..082e47ed0f 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1084,11 +1084,11 @@ char *do_bufdel(int command, char *arg, int addr_count, int start_bnr, int end_b if (deleted == 0) { if (command == DOBUF_UNLOAD) { - STRCPY(IObuff, _("E515: No buffers were unloaded")); + xstrlcpy(IObuff, _("E515: No buffers were unloaded"), IOSIZE); } else if (command == DOBUF_DEL) { - STRCPY(IObuff, _("E516: No buffers were deleted")); + xstrlcpy(IObuff, _("E516: No buffers were deleted"), IOSIZE); } else { - STRCPY(IObuff, _("E517: No buffers were wiped out")); + xstrlcpy(IObuff, _("E517: No buffers were wiped out"), IOSIZE); } errormsg = IObuff; } else if (deleted >= p_report) { -- cgit From e2fdd53d8c015913e8be4ff708fc3488558c8906 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 14 May 2023 18:45:56 +0200 Subject: refactor(map): avoid duplicated khash_t types for values This reduces the total number of khash_t instantiations from 22 to 8. Make the khash internal functions take the size of values as a runtime parameter. This is abstracted with typesafe Map containers which are still specialized for both key, value type. Introduce `Set(key)` type for when there is no value. Refactor shada.c to use Map/Set instead of khash directly. This requires `map_ref` operation to be more flexible. Return pointers to both key and value, plus an indicator for new_item. As a bonus, `map_key` is now redundant. Instead of Map(cstr_t, FileMarks), use a pointer map as the FileMarks struct is humongous. Make `event_strings` actually work like an intern pool instead of wtf it was doing before. --- src/nvim/buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index b2edbf4053..e734a340d9 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -833,7 +833,7 @@ void buf_freeall(buf_T *buf, int flags) /// itself (not the file, that must have been done already). static void free_buffer(buf_T *buf) { - pmap_del(handle_T)(&buffer_handles, buf->b_fnum); + pmap_del(int)(&buffer_handles, buf->b_fnum, NULL); buf_free_count++; // b:changedtick uses an item in buf_T. free_buffer_stuff(buf, kBffClearWinInfo); @@ -1865,7 +1865,7 @@ buf_T *buflist_new(char *ffname_arg, char *sfname_arg, linenr_T lnum, int flags) lastbuf = buf; buf->b_fnum = top_file_num++; - pmap_put(handle_T)(&buffer_handles, buf->b_fnum, buf); + pmap_put(int)(&buffer_handles, buf->b_fnum, buf); if (top_file_num < 0) { // wrap around (may cause duplicates) emsg(_("W14: Warning: List of file names overflow")); if (emsg_silent == 0 && !in_assert_fails) { -- cgit From 6661cdf2bdfc2a9cd9805c7afd6d6ae556a50126 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 24 May 2023 07:09:31 +0800 Subject: vim-patch:9.0.1575: "file N of M" message is not translated (#23737) Problem: "file N of M" message is not translated. Solution: Make argument count message translatable. (close vim/vim#12429) https://github.com/vim/vim/commit/a8490a4952c320f234ae4528d4a1e812a27f3a0a Co-authored-by: Bram Moolenaar --- src/nvim/buffer.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 49fd09ebd0..11b79fcede 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3514,23 +3514,20 @@ bool append_arg_number(win_T *wp, char *buf, int buflen, bool add_file) return false; } - char *p = buf + strlen(buf); // go to the end of the buffer - - // Early out if the string is getting too long - if (p - buf + 35 >= buflen) { - return false; + const char *msg; + switch ((wp->w_arg_idx_invalid ? 1 : 0) + (add_file ? 2 : 0)) { + case 0: + msg = _(" (%d of %d)"); break; + case 1: + msg = _(" ((%d) of %d)"); break; + case 2: + msg = _(" (file %d of %d)"); break; + case 3: + msg = _(" (file (%d) of %d)"); break; } - *p++ = ' '; - *p++ = '('; - if (add_file) { - STRCPY(p, "file "); - p += 5; - } - vim_snprintf(p, (size_t)(buflen - (p - buf)), - wp->w_arg_idx_invalid - ? "(%d) of %d)" - : "%d of %d)", wp->w_arg_idx + 1, ARGCOUNT); + char *p = buf + strlen(buf); // go to the end of the buffer + vim_snprintf(p, (size_t)(buflen - (p - buf)), msg, wp->w_arg_idx + 1, ARGCOUNT); return true; } -- cgit From 43d66c0ebbe43f40a1f76e1635ccef6181c01317 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 11 May 2023 10:48:48 +0800 Subject: fix(ui-ext): send title to newly-attached UI --- src/nvim/buffer.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 11b79fcede..dab07487cd 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3444,7 +3444,6 @@ void resettitle(void) { ui_call_set_icon(cstr_as_string(lasticon)); ui_call_set_title(cstr_as_string(lasttitle)); - ui_flush(); } #if defined(EXITFREE) -- cgit From 7a8402ac31aa2e155baafbc925c48527511c1e92 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 28 May 2023 08:06:30 +0800 Subject: vim-patch:9.0.1583: get E304 when using 'cryptmethod' "xchacha20v2" (#23790) Problem: Get E304 when using 'cryptmethod' "xchacha20v2". (Steve Mynott) Solution: Add 4th crypt method to block zero ID check. Avoid syncing a swap file before reading the file. (closes vim/vim#12433) https://github.com/vim/vim/commit/3a2a60ce4a8e73594bca16814672fcc243d093ac Co-authored-by: Bram Moolenaar --- src/nvim/buffer.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index dab07487cd..bc52ab0771 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -248,6 +248,11 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags_arg) return FAIL; } + // Do not sync this buffer yet, may first want to read the file. + if (curbuf->b_ml.ml_mfp != NULL) { + curbuf->b_ml.ml_mfp->mf_dirty = MF_DIRTY_YES_NOSYNC; + } + // The autocommands in readfile() may change the buffer, but only AFTER // reading the file. set_bufref(&old_curbuf, curbuf); @@ -316,6 +321,12 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags_arg) } } + // Can now sync this buffer in ml_sync_all(). + if (curbuf->b_ml.ml_mfp != NULL + && curbuf->b_ml.ml_mfp->mf_dirty == MF_DIRTY_YES_NOSYNC) { + curbuf->b_ml.ml_mfp->mf_dirty = MF_DIRTY_YES; + } + // if first time loading this buffer, init b_chartab[] if (curbuf->b_flags & BF_NEVERLOADED) { (void)buf_init_chartab(curbuf, false); -- cgit From b3d5138fd0066fda26ef7724a542ae45eb42fc84 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Wed, 7 Jun 2023 06:05:16 +0600 Subject: refactor(options): remove `getoption_T` and introduce `OptVal` (#23850) Removes the `getoption_T` struct and also introduces the `OptVal` struct to unify the methods of getting/setting different option value types. This is the first of many PRs to reduce code duplication in the Vim option code as well as to make options easier to maintain. It also increases the flexibility and extensibility of options. Which opens the door for things like Array and Dictionary options. --- src/nvim/buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index bc52ab0771..e3d375e2df 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -4304,9 +4304,9 @@ int buf_open_scratch(handle_T bufnr, char *bufname) apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, false, curbuf); (void)setfname(curbuf, bufname, NULL, true); apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, false, curbuf); - set_option_value_give_err("bh", 0L, "hide", OPT_LOCAL); - set_option_value_give_err("bt", 0L, "nofile", OPT_LOCAL); - set_option_value_give_err("swf", 0L, NULL, OPT_LOCAL); + set_option_value_give_err("bh", STATIC_CSTR_AS_OPTVAL("hide"), OPT_LOCAL); + set_option_value_give_err("bt", STATIC_CSTR_AS_OPTVAL("nofile"), OPT_LOCAL); + set_option_value_give_err("swf", BOOLEAN_OPTVAL(false), OPT_LOCAL); RESET_BINDING(curwin); return OK; } -- cgit From bbaee29add9b6911ce0778bd93e21b93e034e548 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 2 Jul 2023 07:42:49 +0800 Subject: vim-patch:9.0.1672: tabline highlight wrong after truncated double width label (#24223) Problem: Tabline highlight wrong after truncated double width label. Solution: Fill up half a double width character later. (closes vim/vim#12614) https://github.com/vim/vim/commit/d392a74c5a8af8271a33a20d37ae1a8ea422cb4b --- src/nvim/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index e3d375e2df..a07b1c5720 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -475,7 +475,7 @@ static bool can_unload_buffer(buf_T *buf) /// Possible values: /// 0 buffer becomes hidden /// DOBUF_UNLOAD buffer is unloaded -/// DOBUF_DELETE buffer is unloaded and removed from buffer list +/// DOBUF_DEL buffer is unloaded and removed from buffer list /// DOBUF_WIPE buffer is unloaded and really deleted /// When doing all but the first one on the current buffer, the /// caller should get a new buffer very soon! -- cgit From fcf3519c65a2d6736de437f686e788684a6c8564 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Mon, 17 Apr 2023 22:18:58 +0200 Subject: refactor: remove long long is 32-bits even on 64-bit windows which makes the type suboptimal for a codebase meant to be cross-platform. --- src/nvim/buffer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index a07b1c5720..fd912a65e0 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3192,12 +3192,12 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate) ? " " : ""); // With 32 bit longs and more than 21,474,836 lines multiplying by 100 // causes an overflow, thus for large numbers divide instead. - if (curwin->w_cursor.lnum > 1000000L) { - n = (int)(((long)curwin->w_cursor.lnum) / - ((long)curbuf->b_ml.ml_line_count / 100L)); + if (curwin->w_cursor.lnum > 1000000) { + n = ((curwin->w_cursor.lnum) / + (curbuf->b_ml.ml_line_count / 100)); } else { - n = (int)(((long)curwin->w_cursor.lnum * 100L) / - (long)curbuf->b_ml.ml_line_count); + n = ((curwin->w_cursor.lnum * 100) / + curbuf->b_ml.ml_line_count); } if (curbuf->b_ml.ml_flags & ML_EMPTY) { vim_snprintf_add(buffer, IOSIZE, "%s", _(no_lines_msg)); -- 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/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index fd912a65e0..1e093916d3 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -4250,7 +4250,7 @@ bool buf_contents_changed(buf_T *buf) if (buf->b_ml.ml_line_count == curbuf->b_ml.ml_line_count) { differ = false; for (linenr_T lnum = 1; lnum <= curbuf->b_ml.ml_line_count; lnum++) { - if (strcmp(ml_get_buf(buf, lnum, false), ml_get(lnum)) != 0) { + if (strcmp(ml_get_buf(buf, lnum), ml_get(lnum)) != 0) { differ = true; break; } -- 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/buffer.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 1e093916d3..9c061269f1 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -164,7 +164,7 @@ static int read_buffer(int read_stdin, exarg_T *eap, int flags) // Set or reset 'modified' before executing autocommands, so that // it can be changed there. if (!readonlymode && !buf_is_empty(curbuf)) { - changed(); + changed(curbuf); } else if (retval != FAIL) { unchanged(curbuf, false, true); } @@ -175,20 +175,22 @@ static int read_buffer(int read_stdin, exarg_T *eap, int flags) return retval; } -/// Ensure buffer "buf" is loaded. Does not trigger the swap-exists action. -void buffer_ensure_loaded(buf_T *buf) +/// Ensure buffer "buf" is loaded. +bool buf_ensure_loaded(buf_T *buf) { if (buf->b_ml.ml_mfp != NULL) { - return; + // already open (common case) + return true; } aco_save_T aco; // Make sure the buffer is in a window. aucmd_prepbuf(&aco, buf); - swap_exists_action = SEA_NONE; - open_buffer(false, NULL, 0); + // status can be OK or NOTDONE (which also means ok/done) + int status = open_buffer(false, NULL, 0); aucmd_restbuf(&aco); + return (status != FAIL); } /// Open current buffer, that is: open the memfile and read the file into @@ -343,7 +345,7 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags_arg) if ((got_int && vim_strchr(p_cpo, CPO_INTMOD) != NULL) || modified_was_set // ":set modified" used in autocmd || (aborting() && vim_strchr(p_cpo, CPO_INTMOD) != NULL)) { - changed(); + changed(curbuf); } else if (retval != FAIL && !read_stdin && !read_fifo) { unchanged(curbuf, false, true); } @@ -749,8 +751,6 @@ void buf_clear(void) ml_delete((linenr_T)1, false); } deleted_lines_mark(1, line_count); // prepare for display - ml_close(curbuf, true); // free memline_T - buf_clear_file(curbuf); } /// buf_freeall() - free all things allocated for a buffer that are related to @@ -2124,7 +2124,7 @@ void buflist_getfpos(void) fpos = &buflist_findfmark(curbuf)->mark; curwin->w_cursor.lnum = fpos->lnum; - check_cursor_lnum(); + check_cursor_lnum(curwin); if (p_sol) { curwin->w_cursor.col = 0; -- cgit From f32a69630d0360cd73db6e7507bceb4104ec790d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 3 Sep 2023 11:12:53 +0800 Subject: refactor(marks): don't set timestamp twice with :delmarks (#24994) refactor(mark): don't set same timestamp twice --- src/nvim/buffer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 9c061269f1..8eacec4d5e 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -858,9 +858,9 @@ static void free_buffer(buf_T *buf) xfree(buf->b_prompt_text); callback_free(&buf->b_prompt_callback); callback_free(&buf->b_prompt_interrupt); - clear_fmark(&buf->b_last_cursor); - clear_fmark(&buf->b_last_insert); - clear_fmark(&buf->b_last_change); + clear_fmark(&buf->b_last_cursor, 0); + clear_fmark(&buf->b_last_insert, 0); + clear_fmark(&buf->b_last_change, 0); for (size_t i = 0; i < NMARKS; i++) { free_fmark(buf->b_namedm[i]); } @@ -1910,7 +1910,7 @@ buf_T *buflist_new(char *ffname_arg, char *sfname_arg, linenr_T lnum, int flags) buf->b_flags |= BF_DUMMY; } buf_clear_file(buf); - clrallmarks(buf); // clear marks + clrallmarks(buf, 0); // clear marks fmarks_check_names(buf); // check file marks for this file buf->b_p_bl = (flags & BLN_LISTED) ? true : false; // init 'buflisted' kv_destroy(buf->update_channels); -- cgit From b04286a187d57c50f01cd36cd4668b7a69026579 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 22 Nov 2020 10:10:37 +0100 Subject: feat(extmark): support proper multiline ranges The removes the previous restriction that nvim_buf_set_extmark() could not be used to highlight arbitrary multi-line regions The problem can be summarized as follows: let's assume an extmark with a hl_group is placed covering the region (5,0) to (50,0) Now, consider what happens if nvim needs to redraw a window covering the lines 20-30. It needs to be able to ask the marktree what extmarks cover this region, even if they don't begin or end here. Therefore the marktree needs to be augmented with the information covers a point, not just what marks begin or end there. To do this, we augment each node with a field "intersect" which is a set the ids of the marks which overlap this node, but only if it is not part of the set of any parent. This ensures the number of nodes that need to be explicitly marked grows only logarithmically with the total number of explicitly nodes (and thus the number of of overlapping marks). Thus we can quickly iterate all marks which overlaps any query position by looking up what leaf node contains that position. Then we only need to consider all "start" marks within that leaf node, and the "intersect" set of that node and all its parents. Now, and the major source of complexity is that the tree restructuring operations (to ensure that each node has T-1 <= size <= 2*T-1) also need to update these sets. If a full inner node is split in two, one of the new parents might start to completely overlap some ranges and its ids will need to be moved from its children's sets to its own set. Similarly, if two undersized nodes gets joined into one, it might no longer completely overlap some ranges, and now the children which do needs to have the have the ids in its set instead. And then there are the pivots! Yes the pivot operations when a child gets moved from one parent to another. --- src/nvim/buffer.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 8eacec4d5e..d2a5eab0a5 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -747,6 +747,7 @@ void buf_clear_file(buf_T *buf) void buf_clear(void) { linenr_T line_count = curbuf->b_ml.ml_line_count; + extmark_free_all(curbuf); // delete any extmarks while (!(curbuf->b_ml.ml_flags & ML_EMPTY)) { ml_delete((linenr_T)1, false); } -- cgit From c88bb658ce6fb12cca3e5324d8a15d1859d095cd Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 23 Sep 2023 12:41:09 +0800 Subject: vim-patch:8.2.4609: :unhide does not check for failing to close a window (#25317) Problem: :unhide does not check for failing to close a window. Solution: When closing a window fails continue with the next one. Do not try closing the autocmd window. (closes vim/vim#9984) https://github.com/vim/vim/commit/6f2465d336a9d4afe392db4084ef7e9db17e67c1 Co-authored-by: Bram Moolenaar --- src/nvim/buffer.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index d2a5eab0a5..0564b4305b 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3625,12 +3625,15 @@ void ex_buffer_all(exarg_T *eap) : wp->w_width != Columns) || (had_tab > 0 && wp != firstwin)) && !ONE_WINDOW - && !(wp->w_closing - || wp->w_buffer->b_locked > 0)) { - win_close(wp, false, false); - wpnext = firstwin; // just in case an autocommand does - // something strange with windows - tpnext = first_tabpage; // start all over... + && !(wp->w_closing || wp->w_buffer->b_locked > 0) + && !is_aucmd_win(wp)) { + if (win_close(wp, false, false) == FAIL) { + break; + } + // Just in case an autocommand does something strange with + // windows: start all over... + wpnext = firstwin; + tpnext = first_tabpage; open_wins = 0; } else { open_wins++; @@ -3650,7 +3653,7 @@ void ex_buffer_all(exarg_T *eap) // // Don't execute Win/Buf Enter/Leave autocommands here. autocmd_no_enter++; - win_enter(lastwin, false); + win_enter(lastwin_nofloating(), false); autocmd_no_leave++; for (buf = firstbuf; buf != NULL && open_wins < count; buf = buf->b_next) { // Check if this buffer needs a window @@ -3742,7 +3745,7 @@ void ex_buffer_all(exarg_T *eap) // Close superfluous windows. for (wp = lastwin; open_wins > count;) { r = (buf_hide(wp->w_buffer) || !bufIsChanged(wp->w_buffer) - || autowrite(wp->w_buffer, false) == OK); + || autowrite(wp->w_buffer, false) == OK) && !is_aucmd_win(wp); if (!win_valid(wp)) { // BufWrite Autocommands made the window invalid, start over wp = lastwin; -- cgit From c0a29931e29bbb40650df01918826cdb64e8fc32 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 23 Sep 2023 14:42:59 +0800 Subject: fix(unhide): close floating windows first (#25318) --- src/nvim/buffer.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 0564b4305b..f2174e055b 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3616,8 +3616,11 @@ void ex_buffer_all(exarg_T *eap) } while (true) { tpnext = curtab->tp_next; - for (wp = firstwin; wp != NULL; wp = wpnext) { - wpnext = wp->w_next; + // Try to close floating windows first + for (wp = lastwin->w_floating ? lastwin : firstwin; wp != NULL; wp = wpnext) { + wpnext = wp->w_floating + ? wp->w_prev->w_floating ? wp->w_prev : firstwin + : (wp->w_next == NULL || wp->w_next->w_floating) ? NULL : wp->w_next; if ((wp->w_buffer->b_nwindows > 1 || ((cmdmod.cmod_split & WSP_VERT) ? wp->w_height + wp->w_hsep_height + wp->w_status_height < Rows - p_ch @@ -3632,7 +3635,7 @@ void ex_buffer_all(exarg_T *eap) } // Just in case an autocommand does something strange with // windows: start all over... - wpnext = firstwin; + wpnext = lastwin->w_floating ? lastwin : firstwin; tpnext = first_tabpage; open_wins = 0; } else { -- cgit From fcdfbb430377a82921cf1a72df97bce7952733e8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 23 Sep 2023 22:33:44 +0800 Subject: fix(float): fix some other crashes with :unhide or :all (#25328) --- src/nvim/buffer.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index f2174e055b..68cef67c8a 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3622,6 +3622,7 @@ void ex_buffer_all(exarg_T *eap) ? wp->w_prev->w_floating ? wp->w_prev : firstwin : (wp->w_next == NULL || wp->w_next->w_floating) ? NULL : wp->w_next; if ((wp->w_buffer->b_nwindows > 1 + || wp->w_floating || ((cmdmod.cmod_split & WSP_VERT) ? wp->w_height + wp->w_hsep_height + wp->w_status_height < Rows - p_ch - tabline_height() - global_stl_height() @@ -3656,6 +3657,7 @@ void ex_buffer_all(exarg_T *eap) // // Don't execute Win/Buf Enter/Leave autocommands here. autocmd_no_enter++; + // lastwin may be aucmd_win win_enter(lastwin_nofloating(), false); autocmd_no_leave++; for (buf = firstbuf; buf != NULL && open_wins < count; buf = buf->b_next) { @@ -3674,7 +3676,7 @@ void ex_buffer_all(exarg_T *eap) } else { // Check if this buffer already has a window for (wp = firstwin; wp != NULL; wp = wp->w_next) { - if (wp->w_buffer == buf) { + if (!wp->w_floating && wp->w_buffer == buf) { break; } } -- cgit From f7da4722570617bd8927e7aa533fa9a608c45bba Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 23 Sep 2023 16:42:47 +0200 Subject: refactor(options)!: graduate shortmess+=f flag Not everything needs to be crazy overconfigurable. Also fixes a warning in latest clang which didn't approve of the funky math switch statement in append_arg_number --- src/nvim/buffer.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index f2174e055b..60674486e5 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3221,7 +3221,7 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate) (int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1); } - (void)append_arg_number(curwin, buffer, IOSIZE, !shortmess(SHM_FILE)); + (void)append_arg_number(curwin, buffer, IOSIZE); if (dont_truncate) { // Temporarily set msg_scroll to avoid the message being truncated. @@ -3372,7 +3372,7 @@ void maketitle(void) *buf_p = NUL; } - append_arg_number(curwin, buf_p, (int)(SPACE_FOR_ARGNR - (size_t)(buf_p - buf)), false); + append_arg_number(curwin, buf_p, (int)(SPACE_FOR_ARGNR - (size_t)(buf_p - buf))); xstrlcat(buf_p, " - NVIM", (sizeof(buf) - (size_t)(buf_p - buf))); @@ -3509,15 +3509,14 @@ void get_rel_pos(win_T *wp, char *buf, int buflen) } } -/// Append (file 2 of 8) to "buf[buflen]", if editing more than one file. +/// Append (2 of 8) to "buf[buflen]", if editing more than one file. /// /// @param wp window whose buffers to check /// @param[in,out] buf string buffer to add the text to /// @param buflen length of the string buffer -/// @param add_file if true, add "file" before the arg number /// /// @return true if it was appended. -bool append_arg_number(win_T *wp, char *buf, int buflen, bool add_file) +bool append_arg_number(win_T *wp, char *buf, int buflen) FUNC_ATTR_NONNULL_ALL { // Nothing to do @@ -3525,17 +3524,7 @@ bool append_arg_number(win_T *wp, char *buf, int buflen, bool add_file) return false; } - const char *msg; - switch ((wp->w_arg_idx_invalid ? 1 : 0) + (add_file ? 2 : 0)) { - case 0: - msg = _(" (%d of %d)"); break; - case 1: - msg = _(" ((%d) of %d)"); break; - case 2: - msg = _(" (file %d of %d)"); break; - case 3: - msg = _(" (file (%d) of %d)"); break; - } + const char *msg = wp->w_arg_idx_invalid ? _(" ((%d) of %d)") : _(" (%d of %d)"); char *p = buf + strlen(buf); // go to the end of the buffer vim_snprintf(p, (size_t)(buflen - (p - buf)), msg, wp->w_arg_idx + 1, ARGCOUNT); -- cgit From c3d1d9445c70846d43d1f091ee0762e16513e225 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 25 Sep 2023 12:21:35 +0200 Subject: refactor(options)!: graduate some more shortmess flags A lot of updated places in the docs were already incorrect since long since they did not reflect the default behaviour. "[dos format]" could've been argued being better for discoverability but that ship has already sailed as it is no longer displayed by default. --- src/nvim/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index df6ca4789b..7a3e65e10e 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3182,7 +3182,7 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate) (curbuf->b_flags & BF_NOTEDITED) && !dontwrite ? _("[Not edited]") : "", (curbuf->b_flags & BF_NEW) && !dontwrite - ? new_file_message() : "", + ? _("[New]") : "", (curbuf->b_flags & BF_READERR) ? _("[Read errors]") : "", curbuf->b_p_ro -- cgit From b65f4151d9e52a8521c0682a817c4dab9690e1e7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 27 Sep 2023 18:51:40 +0800 Subject: vim-patch:8.2.3517: TextChanged does not trigger after TextChangedI (#25384) Problem: TextChanged does not trigger after TextChangedI. Solution: Store the tick separately for TextChangedI. (Christian Brabandt, closes vim/vim#8968, closes vim/vim#8932) https://github.com/vim/vim/commit/db3b44640d69ab27270691a3cab8d83cc93a0861 Co-authored-by: Christian Brabandt --- src/nvim/buffer.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 7a3e65e10e..15fbf7df7b 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -354,6 +354,7 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags_arg) // Set last_changedtick to avoid triggering a TextChanged autocommand right // after it was added. curbuf->b_last_changedtick = buf_get_changedtick(curbuf); + curbuf->b_last_changedtick_i = buf_get_changedtick(curbuf); curbuf->b_last_changedtick_pum = buf_get_changedtick(curbuf); // require "!" to overwrite the file, because it wasn't read completely -- cgit From f91cd31d7d9d70006e0000592637d5d997eab52c Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 21:46:39 +0200 Subject: refactor(messages): fold msg_outtrans_attr into msg_outtrans problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- src/nvim/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 15fbf7df7b..f04a3be447 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -2858,7 +2858,7 @@ void buflist_list(exarg_T *eap) buf == curbuf ? (int64_t)curwin->w_cursor.lnum : (int64_t)buflist_findlnum(buf)); } - msg_outtrans(IObuff); + msg_outtrans(IObuff, 0); line_breakcheck(); } -- cgit From b85f1dafc7c0a19704135617454f1c66f41202c1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 22:21:17 +0200 Subject: refactor(messages): fold msg_attr into msg problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- src/nvim/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index f04a3be447..1ef1f26d6b 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3230,7 +3230,7 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate) msg_start(); n = msg_scroll; msg_scroll = true; - msg(buffer); + msg(buffer, 0); msg_scroll = n; } else { p = msg_trunc_attr(buffer, false, 0); -- cgit From 448d4837be7f7bd60ac0b5a3100c0217ac48a495 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 22:24:50 +0200 Subject: refactor(messages): rename msg_trunc_attr and msg_multiline_attr without attr --- src/nvim/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 1ef1f26d6b..87096767f9 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3233,7 +3233,7 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate) msg(buffer, 0); msg_scroll = n; } else { - p = msg_trunc_attr(buffer, false, 0); + p = msg_trunc(buffer, false, 0); if (restart_edit != 0 || (msg_scrolled && !need_wait_return)) { // Need to repeat the message after redrawing when: // - When restart_edit is set (otherwise there will be a delay -- cgit From af7d317f3ff31d5ac5d8724b5057a422e1451b54 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 26 Sep 2023 22:36:08 +0200 Subject: refactor: remove long long is 32-bits even on 64-bit windows which makes the type suboptimal for a codebase meant to be cross-platform. --- src/nvim/buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 87096767f9..2131f4d836 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -206,7 +206,7 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags_arg) int flags = flags_arg; int retval = OK; bufref_T old_curbuf; - long old_tw = curbuf->b_p_tw; + OptInt old_tw = curbuf->b_p_tw; int read_fifo = false; bool silent = shortmess(SHM_FILEINFO); @@ -965,7 +965,7 @@ void goto_buffer(exarg_T *eap, int start, int dir, int count) void handle_swap_exists(bufref_T *old_curbuf) { cleanup_T cs; - long old_tw = curbuf->b_p_tw; + OptInt old_tw = curbuf->b_p_tw; buf_T *buf; if (swap_exists_action == SEA_QUIT) { @@ -1532,7 +1532,7 @@ void set_curbuf(buf_T *buf, int action) buf_T *prevbuf; int unload = (action == DOBUF_UNLOAD || action == DOBUF_DEL || action == DOBUF_WIPE); - long old_tw = curbuf->b_p_tw; + OptInt old_tw = curbuf->b_p_tw; setpcmark(); if ((cmdmod.cmod_flags & CMOD_KEEPALT) == 0) { -- cgit From bc13bc154aa574e0bb58a50f2e0ca4570efa57c3 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 29 Sep 2023 16:10:54 +0200 Subject: refactor(message): smsg_attr -> smsg --- src/nvim/buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 2131f4d836..d6cab233d2 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1106,13 +1106,13 @@ char *do_bufdel(int command, char *arg, int addr_count, int start_bnr, int end_b errormsg = IObuff; } else if (deleted >= p_report) { if (command == DOBUF_UNLOAD) { - smsg(NGETTEXT("%d buffer unloaded", "%d buffers unloaded", deleted), + smsg(0, NGETTEXT("%d buffer unloaded", "%d buffers unloaded", deleted), deleted); } else if (command == DOBUF_DEL) { - smsg(NGETTEXT("%d buffer deleted", "%d buffers deleted", deleted), + smsg(0, NGETTEXT("%d buffer deleted", "%d buffers deleted", deleted), deleted); } else { - smsg(NGETTEXT("%d buffer wiped out", "%d buffers wiped out", deleted), + smsg(0, NGETTEXT("%d buffer wiped out", "%d buffers wiped out", deleted), deleted); } } -- 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/buffer.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index d6cab233d2..e418e415e0 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -47,6 +47,7 @@ #include "nvim/digraph.h" #include "nvim/drawscreen.h" #include "nvim/eval.h" +#include "nvim/eval/typval_defs.h" #include "nvim/eval/vars.h" #include "nvim/ex_cmds.h" #include "nvim/ex_cmds2.h" @@ -71,6 +72,7 @@ #include "nvim/mapping.h" #include "nvim/mark.h" #include "nvim/mbyte.h" +#include "nvim/memfile_defs.h" #include "nvim/memline_defs.h" #include "nvim/memory.h" #include "nvim/message.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/buffer.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index e418e415e0..5025e86771 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -79,6 +79,7 @@ #include "nvim/move.h" #include "nvim/normal.h" #include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/optionstr.h" #include "nvim/os/fs_defs.h" #include "nvim/os/input.h" -- cgit From e72b546354cd90bf0cd8ee6dd045538d713009ad 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/buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 5025e86771..076cf63913 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3480,8 +3480,8 @@ void get_rel_pos(win_T *wp, char *buf, int buflen) return; } - long above; // number of lines above window - long below; // number of lines below window + linenr_T above; // number of lines above window + linenr_T below; // number of lines below window above = wp->w_topline - 1; above += win_get_fill(wp, wp->w_topline) - wp->w_topfill; @@ -3580,7 +3580,7 @@ void ex_buffer_all(exarg_T *eap) bool p_ea_save; int open_wins = 0; int r; - long count; // Maximum number of windows to open. + linenr_T count; // Maximum number of windows to open. int all; // When true also load inactive buffers. int had_tab = cmdmod.cmod_tab; tabpage_T *tpnext; -- 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/buffer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 076cf63913..86b16c18da 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -987,7 +987,7 @@ void handle_swap_exists(bufref_T *old_curbuf) || old_curbuf->br_buf == curbuf) { // Block autocommands here because curwin->w_buffer is NULL. block_autocmds(); - buf = buflist_new(NULL, NULL, 1L, BLN_CURBUF | BLN_LISTED); + buf = buflist_new(NULL, NULL, 1, BLN_CURBUF | BLN_LISTED); unblock_autocmds(); } else { buf = old_curbuf->br_buf; @@ -1886,7 +1886,7 @@ buf_T *buflist_new(char *ffname_arg, char *sfname_arg, linenr_T lnum, int flags) emsg(_("W14: Warning: List of file names overflow")); if (emsg_silent == 0 && !in_assert_fails) { ui_flush(); - os_delay(3001L, true); // make sure it is noticed + os_delay(3001, true); // make sure it is noticed } top_file_num = 1; } @@ -3496,9 +3496,9 @@ void get_rel_pos(win_T *wp, char *buf, int buflen) } else if (above <= 0) { xstrlcpy(buf, _("Top"), (size_t)buflen); } else { - int perc = (above > 1000000L - ? (int)(above / ((above + below) / 100L)) - : (int)(above * 100L / (above + below))); + int perc = (above > 1000000 + ? (above / ((above + below) / 100)) + : (above * 100 / (above + below))); char *p = buf; size_t l = (size_t)buflen; -- 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/buffer.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 86b16c18da..4ce4036ac9 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -146,12 +146,12 @@ static int read_buffer(int read_stdin, exarg_T *eap, int flags) line_count = curbuf->b_ml.ml_line_count; retval = readfile(read_stdin ? NULL : curbuf->b_ffname, read_stdin ? NULL : curbuf->b_fname, - line_count, (linenr_T)0, (linenr_T)MAXLNUM, eap, + line_count, 0, (linenr_T)MAXLNUM, eap, flags | READ_BUFFER, silent); if (retval == OK) { // Delete the binary lines. while (--line_count >= 0) { - ml_delete((linenr_T)1, false); + ml_delete(1, false); } } else { // Delete the converted lines. @@ -294,7 +294,7 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags_arg) #endif retval = readfile(curbuf->b_ffname, curbuf->b_fname, - (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, eap, + 0, 0, (linenr_T)MAXLNUM, eap, flags | READ_NEW | (read_fifo ? READ_FIFO : 0), silent); #ifdef UNIX if (read_fifo) { @@ -317,8 +317,8 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags_arg) // it possible to retry when 'fileformat' or 'fileencoding' was // guessed wrong. curbuf->b_p_bin = true; - retval = readfile(NULL, NULL, (linenr_T)0, - (linenr_T)0, (linenr_T)MAXLNUM, NULL, + retval = readfile(NULL, NULL, 0, + 0, (linenr_T)MAXLNUM, NULL, flags | (READ_NEW + READ_STDIN), silent); curbuf->b_p_bin = save_bin; if (retval == OK) { @@ -753,7 +753,7 @@ void buf_clear(void) linenr_T line_count = curbuf->b_ml.ml_line_count; extmark_free_all(curbuf); // delete any extmarks while (!(curbuf->b_ml.ml_flags & ML_EMPTY)) { - ml_delete((linenr_T)1, false); + ml_delete(1, false); } deleted_lines_mark(1, line_count); // prepare for display } @@ -1801,7 +1801,7 @@ buf_T *buflist_new(char *ffname_arg, char *sfname_arg, linenr_T lnum, int flags) xfree(ffname); if (lnum != 0) { buflist_setfpos(buf, (flags & BLN_NOCURWIN) ? NULL : curwin, - lnum, (colnr_T)0, false); + lnum, 0, false); } if ((flags & BLN_NOOPT) == 0) { // Copy the options now, if 'cpo' doesn't have 's' and not done already. @@ -2532,12 +2532,12 @@ static char *fname_match(regmatch_T *rmp, char *name, bool ignore_case) // Ignore case when 'fileignorecase' or the argument is set. rmp->rm_ic = p_fic || ignore_case; - if (vim_regexec(rmp, name, (colnr_T)0)) { + if (vim_regexec(rmp, name, 0)) { match = name; } else if (rmp->regprog != NULL) { // Replace $(HOME) with '~' and try matching again. p = home_replace_save(NULL, name); - if (vim_regexec(rmp, p, (colnr_T)0)) { + if (vim_regexec(rmp, p, 0)) { match = name; } xfree(p); @@ -3035,7 +3035,7 @@ char *getaltfname(bool errmsg) /// Used by qf_init(), main() and doarglist() int buflist_add(char *fname, int flags) { - buf_T *buf = buflist_new(fname, NULL, (linenr_T)0, flags); + buf_T *buf = buflist_new(fname, NULL, 0, flags); if (buf != NULL) { return buf->b_fnum; } @@ -4231,7 +4231,7 @@ bool buf_contents_changed(buf_T *buf) bool differ = true; // Allocate a buffer without putting it in the buffer list. - buf_T *newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); + buf_T *newbuf = buflist_new(NULL, NULL, 1, BLN_DUMMY); if (newbuf == NULL) { return true; } @@ -4246,7 +4246,7 @@ bool buf_contents_changed(buf_T *buf) if (ml_open(curbuf) == OK && readfile(buf->b_ffname, buf->b_fname, - (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, + 0, 0, (linenr_T)MAXLNUM, &ea, READ_NEW | READ_DUMMY, false) == OK) { // compare the two files line by line if (buf->b_ml.ml_line_count == curbuf->b_ml.ml_line_count) { -- 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/buffer.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 4ce4036ac9..677809459c 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.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 - // // buffer.c: functions for dealing with the buffer structure // @@ -1020,7 +1017,7 @@ void handle_swap_exists(bufref_T *old_curbuf) // new aborting error, interrupt, or uncaught exception. leave_cleanup(&cs); } - swap_exists_action = SEA_NONE; // -V519 + swap_exists_action = SEA_NONE; } /// do_bufdel() - delete or unload buffer(s) -- cgit From 28f4f3c48498086307ed825d1761edb5789ca0e8 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 15:54:54 +0100 Subject: refactor: follow style guide - reduce variable scope - prefer initialization over declaration and assignment - use bool to represent boolean values --- src/nvim/buffer.c | 70 ++++++++++++++++++++----------------------------------- 1 file changed, 25 insertions(+), 45 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 677809459c..230cd4cef7 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -134,13 +134,12 @@ int get_highest_fnum(void) static int read_buffer(int read_stdin, exarg_T *eap, int flags) { int retval = OK; - linenr_T line_count; bool silent = shortmess(SHM_FILEINFO); // Read from the buffer which the text is already filled in and append at // the end. This makes it possible to retry when 'fileformat' or // 'fileencoding' was guessed wrong. - line_count = curbuf->b_ml.ml_line_count; + linenr_T line_count = curbuf->b_ml.ml_line_count; retval = readfile(read_stdin ? NULL : curbuf->b_ffname, read_stdin ? NULL : curbuf->b_fname, line_count, 0, (linenr_T)MAXLNUM, eap, @@ -1039,9 +1038,8 @@ char *do_bufdel(int command, char *arg, int addr_count, int start_bnr, int end_b { int do_current = 0; // delete current buffer? int deleted = 0; // number of buffers deleted - char *errormsg = NULL; // return value + char *errormsg = NULL; // return value int bnr; // buffer number - char *p; if (addr_count == 0) { (void)do_buffer(command, DOBUF_CURRENT, FORWARD, 0, forceit); @@ -1078,7 +1076,7 @@ char *do_bufdel(int command, char *arg, int addr_count, int start_bnr, int end_b break; } if (!ascii_isdigit(*arg)) { - p = skiptowhite_esc(arg); + char *p = skiptowhite_esc(arg); bnr = buflist_findpat(arg, p, command == DOBUF_WIPE, false, false); if (bnr < 0) { // failed break; @@ -1125,7 +1123,6 @@ char *do_bufdel(int command, char *arg, int addr_count, int start_bnr, int end_b /// Used when it is wiped out and it's the last buffer. static int empty_curbuf(int close_others, int forceit, int action) { - int retval; buf_T *buf = curbuf; if (action == DOBUF_UNLOAD) { @@ -1158,8 +1155,7 @@ static int empty_curbuf(int close_others, int forceit, int action) } setpcmark(); - retval = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, - forceit ? ECMD_FORCEIT : 0, curwin); + int retval = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, forceit ? ECMD_FORCEIT : 0, curwin); // do_ecmd() may create a new buffer, then we have to delete // the old one. But do_ecmd() may have done that already, check @@ -2044,12 +2040,11 @@ void free_buf_options(buf_T *buf, int free_p_ff) /// Return FAIL for failure, OK for success. int buflist_getfile(int n, linenr_T lnum, int options, int forceit) { - buf_T *buf; win_T *wp = NULL; fmark_T *fm = NULL; colnr_T col; - buf = buflist_findnr(n); + buf_T *buf = buflist_findnr(n); if (buf == NULL) { if ((options & GETF_ALT) && n == 0) { emsg(_(e_noalt)); @@ -2121,9 +2116,7 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit) /// Go to the last known line number for the current buffer. void buflist_getfpos(void) { - pos_T *fpos; - - fpos = &buflist_findfmark(curbuf)->mark; + pos_T *fpos = &buflist_findfmark(curbuf)->mark; curwin->w_cursor.lnum = fpos->lnum; check_cursor_lnum(curwin); @@ -2143,18 +2136,17 @@ void buflist_getfpos(void) /// @return buffer or NULL if not found buf_T *buflist_findname_exp(char *fname) { - char *ffname; buf_T *buf = NULL; // First make the name into a full path name - ffname = FullName_save(fname, + char *ffname = FullName_save(fname, #ifdef UNIX - // force expansion, get rid of symbolic links - true + // force expansion, get rid of symbolic links + true #else - false + false #endif - ); // NOLINT(whitespace/parens) + ); // NOLINT(whitespace/parens) if (ffname != NULL) { buf = buflist_findname(ffname); xfree(ffname); @@ -2204,12 +2196,6 @@ int buflist_findpat(const char *pattern, const char *pattern_end, bool unlisted, FUNC_ATTR_NONNULL_ARG(1) { int match = -1; - int find_listed; - char *pat; - char *patend; - int attempt; - char *p; - int toggledollar; if (pattern_end == pattern + 1 && (*pattern == '%' || *pattern == '#')) { if (*pattern == '%') { @@ -2230,23 +2216,24 @@ int buflist_findpat(const char *pattern, const char *pattern_end, bool unlisted, // Repeat this for finding an unlisted buffer if there was no matching // listed buffer. - pat = file_pat_to_reg_pat(pattern, pattern_end, NULL, false); + char *pat = file_pat_to_reg_pat(pattern, pattern_end, NULL, false); if (pat == NULL) { return -1; } - patend = pat + strlen(pat) - 1; - toggledollar = (patend > pat && *patend == '$'); + char *patend = pat + strlen(pat) - 1; + int toggledollar = (patend > pat && *patend == '$'); // First try finding a listed buffer. If not found and "unlisted" // is true, try finding an unlisted buffer. - find_listed = true; + + int find_listed = true; while (true) { - for (attempt = 0; attempt <= 3; attempt++) { + for (int attempt = 0; attempt <= 3; attempt++) { // may add '^' and '$' if (toggledollar) { *patend = (attempt < 2) ? NUL : '$'; // add/remove '$' } - p = pat; + char *p = pat; if (*p == '^' && !(attempt & 1)) { // add/remove '^' p++; } @@ -2336,7 +2323,6 @@ int ExpandBufnames(char *pat, int *num_file, char ***file, int options) int count = 0; int round; char *p; - int attempt; bufmatch_T *matches = NULL; *num_file = 0; // return values in case of FAIL @@ -2364,7 +2350,7 @@ int ExpandBufnames(char *pat, int *num_file, char ***file, int options) fuzmatch_str_T *fuzmatch = NULL; // attempt == 0: try match with '\<', match at start of word // attempt == 1: try match without '\<', match anywhere - for (attempt = 0; attempt <= (fuzzy ? 0 : 1); attempt++) { + for (int attempt = 0; attempt <= (fuzzy ? 0 : 1); attempt++) { regmatch_T regmatch; if (!fuzzy) { if (attempt > 0 && patc == pat) { @@ -2520,7 +2506,6 @@ static char *buflist_match(regmatch_T *rmp, buf_T *buf, bool ignore_case) static char *fname_match(regmatch_T *rmp, char *name, bool ignore_case) { char *match = NULL; - char *p; // extra check for valid arguments if (name == NULL || rmp->regprog == NULL) { @@ -2533,7 +2518,7 @@ static char *fname_match(regmatch_T *rmp, char *name, bool ignore_case) match = name; } else if (rmp->regprog != NULL) { // Replace $(HOME) with '~' and try matching again. - p = home_replace_save(NULL, name); + char *p = home_replace_save(NULL, name); if (vim_regexec(rmp, p, 0)) { match = name; } @@ -3151,10 +3136,8 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate) char *name; int n; char *p; - char *buffer; - size_t len; - buffer = xmalloc(IOSIZE); + char *buffer = xmalloc(IOSIZE); if (fullname > 1) { // 2 CTRL-G: include buffer number vim_snprintf(buffer, IOSIZE, "buf %d: ", curbuf->b_fnum); @@ -3217,7 +3200,7 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate) (int64_t)curbuf->b_ml.ml_line_count, n); validate_virtcol(); - len = strlen(buffer); + size_t len = strlen(buffer); col_print(buffer + len, IOSIZE - len, (int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1); } @@ -3266,7 +3249,6 @@ void maketitle(void) char *icon_str = NULL; int maxlen = 0; int len; - int mustset; char buf[IOSIZE]; if (!redrawing()) { @@ -3389,7 +3371,7 @@ void maketitle(void) #undef SPACE_FOR_ARGNR } } - mustset = value_change(title_str, &lasttitle); + int mustset = value_change(title_str, &lasttitle); if (p_icon) { icon_str = buf; @@ -3807,12 +3789,10 @@ static int chk_modeline(linenr_T lnum, int flags) char *s; char *e; char *linecopy; // local copy of any modeline found - int prev; intmax_t vers; - int end; int retval = OK; - prev = -1; + int prev = -1; for (s = ml_get(lnum); *s != NUL; s++) { if (prev == -1 || ascii_isspace(prev)) { if ((prev != -1 && strncmp(s, "ex:", (size_t)3) == 0) @@ -3858,7 +3838,7 @@ static int chk_modeline(linenr_T lnum, int flags) // prepare for emsg() estack_push(ETYPE_MODELINE, "modelines", lnum); - end = false; + bool end = false; while (end == false) { s = skipwhite(s); if (*s == NUL) { -- cgit From 326d46f690b383846f136f2a25523cffe2882f27 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 16 Nov 2023 09:54:47 +0800 Subject: refactor: move some functions to winfloat.c (#26020) --- src/nvim/buffer.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 230cd4cef7..262163f248 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -101,6 +101,7 @@ #include "nvim/version.h" #include "nvim/vim.h" #include "nvim/window.h" +#include "nvim/winfloat.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "buffer.c.generated.h" -- cgit From bb4b4576e384c71890b4df4fa4f1ae76fad3a59d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 16 Nov 2023 10:55:54 +0800 Subject: refactor: iwyu (#26062) --- src/nvim/buffer.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 262163f248..6617907f8f 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -84,6 +84,7 @@ #include "nvim/os/time.h" #include "nvim/path.h" #include "nvim/plines.h" +#include "nvim/pos.h" #include "nvim/quickfix.h" #include "nvim/regexp.h" #include "nvim/runtime.h" -- cgit From d49be1cd2893ad583361ac058279a471ad7877e5 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 17 Nov 2023 09:42:59 +0800 Subject: vim-patch:9.0.2010: [security] use-after-free from buf_contents_changed() Problem: [security] use-after-free from buf_contents_changed() Solution: block autocommands https://github.com/vim/vim/commit/41e6f7d6ba67b61d911f9b1d76325cd79224753d Co-authored-by: Christian Brabandt --- src/nvim/buffer.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 6617907f8f..6d5c7a1766 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -4223,6 +4223,10 @@ bool buf_contents_changed(buf_T *buf) aco_save_T aco; aucmd_prepbuf(&aco, newbuf); + // We don't want to trigger autocommands now, they may have nasty + // side-effects like wiping buffers + block_autocmds(); + if (ml_open(curbuf) == OK && readfile(buf->b_ffname, buf->b_fname, 0, 0, (linenr_T)MAXLNUM, @@ -4247,6 +4251,8 @@ bool buf_contents_changed(buf_T *buf) wipe_buffer(newbuf, false); } + unblock_autocmds(); + return differ; } -- cgit From c4afb9788c4f139eb2e3b7aa4d6a6a20b67ba156 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Sat, 11 Nov 2023 00:52:50 +0100 Subject: refactor(sign): move legacy signs to extmarks Problem: The legacy signlist data structures and associated functions are redundant since the introduction of extmark signs. Solution: Store signs defined through the legacy commands in a hashmap, placed signs in the extmark tree. Replace signlist associated functions. Usage of the legacy sign commands should yield no change in behavior with the exception of: - "orphaned signs" are now always removed when the line it is placed on is deleted. This used to depend on the value of 'signcolumn'. - It is no longer possible to place multiple signs with the same identifier in a single group on multiple lines. This will now move the sign instead. Moreover, both signs placed through the legacy sign commands and through |nvim_buf_set_extmark()|: - Will show up in both |sign-place| and |nvim_buf_get_extmarks()|. - Are displayed by increasing sign identifier, left to right. Extmark signs used to be ordered decreasingly as opposed to legacy signs. --- src/nvim/buffer.c | 95 ++++++++----------------------------------------------- 1 file changed, 14 insertions(+), 81 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 230cd4cef7..8c522a6c44 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -917,7 +917,6 @@ static void free_buffer_stuff(buf_T *buf, int free_flags) buf_init_changedtick(buf); } uc_clear(&buf->b_ucmds); // clear local user commands - buf_delete_signs(buf, "*"); // delete any signs extmark_free_all(buf); // delete any extmarks map_clear_mode(buf, MAP_ALL_MODES, true, false); // clear local mappings map_clear_mode(buf, MAP_ALL_MODES, true, true); // clear local abbrevs @@ -4021,62 +4020,6 @@ char *buf_spname(buf_T *buf) return NULL; } -static int buf_signcols_inner(buf_T *buf, int maximum) -{ - sign_entry_T *sign; // a sign in the sign list - int signcols = 0; - int linesum = 0; - linenr_T curline = 0; - - buf->b_signcols.sentinel = 0; - - FOR_ALL_SIGNS_IN_BUF(buf, sign) { - if (sign->se_lnum > curline) { - // Counted all signs, now add extmark signs - if (curline > 0) { - linesum += decor_signcols(buf, &decor_state, (int)curline - 1, (int)curline - 1, - maximum - linesum); - } - curline = sign->se_lnum; - if (linesum > signcols) { - signcols = linesum; - buf->b_signcols.sentinel = curline; - if (signcols >= maximum) { - return maximum; - } - } - linesum = 0; - } - if (sign->se_has_text_or_icon) { - linesum++; - } - } - - if (curline > 0) { - linesum += decor_signcols(buf, &decor_state, (int)curline - 1, (int)curline - 1, - maximum - linesum); - } - if (linesum > signcols) { - signcols = linesum; - if (signcols >= maximum) { - return maximum; - } - } - - // Check extmarks between signs - linesum = decor_signcols(buf, &decor_state, 0, (int)buf->b_ml.ml_line_count - 1, maximum); - - if (linesum > signcols) { - signcols = linesum; - buf->b_signcols.sentinel = curline; - if (signcols >= maximum) { - return maximum; - } - } - - return signcols; -} - /// Invalidate the signcolumn if needed after deleting /// signs between line1 and line2 (inclusive). /// @@ -4106,18 +4049,18 @@ void buf_signcols_del_check(buf_T *buf, linenr_T line1, linenr_T line2) /// /// @param buf buffer to check /// @param added sign being added -void buf_signcols_add_check(buf_T *buf, sign_entry_T *added) +void buf_signcols_add_check(buf_T *buf, linenr_T lnum) { if (!buf->b_signcols.valid) { return; } - if (!added || !buf->b_signcols.sentinel) { + if (!buf->b_signcols.sentinel) { buf->b_signcols.valid = false; return; } - if (added->se_lnum == buf->b_signcols.sentinel) { + if (lnum == buf->b_signcols.sentinel) { if (buf->b_signcols.size == buf->b_signcols.max) { buf->b_signcols.max++; } @@ -4126,42 +4069,32 @@ void buf_signcols_add_check(buf_T *buf, sign_entry_T *added) return; } - sign_entry_T *s; - - // Get first sign for added lnum - for (s = added; s->se_prev && s->se_lnum == s->se_prev->se_lnum; s = s->se_prev) {} - - // Count signs for lnum - int linesum = 1; - for (; s->se_next && s->se_lnum == s->se_next->se_lnum; s = s->se_next) { - linesum++; - } - linesum += decor_signcols(buf, &decor_state, (int)s->se_lnum - 1, (int)s->se_lnum - 1, - SIGN_SHOW_MAX - linesum); + int signcols = decor_signcols(buf, lnum - 1, lnum - 1, SIGN_SHOW_MAX); - if (linesum > buf->b_signcols.size) { - buf->b_signcols.size = linesum; - buf->b_signcols.max = linesum; - buf->b_signcols.sentinel = added->se_lnum; + if (signcols > buf->b_signcols.size) { + buf->b_signcols.size = signcols; + buf->b_signcols.max = signcols; + buf->b_signcols.sentinel = lnum; redraw_buf_later(buf, UPD_NOT_VALID); } } -int buf_signcols(buf_T *buf, int maximum) +int buf_signcols(buf_T *buf, int max) { // The maximum can be determined from 'signcolumn' which is window scoped so // need to invalidate signcols if the maximum is greater than the previous - // maximum. - if (maximum > buf->b_signcols.max) { + // (valid) maximum. + if (buf->b_signcols.max && max > buf->b_signcols.max) { buf->b_signcols.valid = false; } if (!buf->b_signcols.valid) { - int signcols = buf_signcols_inner(buf, maximum); + buf->b_signcols.sentinel = 0; + int signcols = decor_signcols(buf, 0, (int)buf->b_ml.ml_line_count - 1, max); // Check if we need to redraw if (signcols != buf->b_signcols.size) { buf->b_signcols.size = signcols; - buf->b_signcols.max = maximum; + buf->b_signcols.max = max; redraw_buf_later(buf, UPD_NOT_VALID); } -- cgit From a6e3d93421ba13c407a96fac9cc01fa41ec7ad98 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Thu, 16 Nov 2023 10:59:11 +0100 Subject: refactor: enable formatting for ternaries This requires removing the "Inner expression should be aligned" rule from clint as it prevents essentially any formatting regarding ternary operators. --- src/nvim/buffer.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index deec0662a1..1e27d2e57c 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -423,8 +423,8 @@ bool bufref_valid(bufref_T *bufref) FUNC_ATTR_PURE { return bufref->br_buf_free_count == buf_free_count - ? true - : buf_valid(bufref->br_buf) && bufref->br_fnum == bufref->br_buf->b_fnum; + ? true + : buf_valid(bufref->br_buf) && bufref->br_fnum == bufref->br_buf->b_fnum; } /// Check that "buf" points to a valid buffer in the buffer list. @@ -2777,7 +2777,7 @@ void buflist_list(exarg_T *eap) for (; buf != NULL && !got_int; buf = buflist_data != NULL - ? (++p < buflist_data + buflist.ga_len ? *p : NULL) : buf->b_next) { + ? (++p < buflist_data + buflist.ga_len ? *p : NULL) : buf->b_next) { const bool is_terminal = buf->terminal; const bool job_running = buf->terminal && terminal_running(buf->terminal); @@ -2811,8 +2811,8 @@ void buflist_list(exarg_T *eap) } const int changed_char = (buf->b_flags & BF_READERR) - ? 'x' - : (bufIsChanged(buf) ? '+' : ' '); + ? 'x' + : (bufIsChanged(buf) ? '+' : ' '); int ro_char = !MODIFIABLE(buf) ? '-' : (buf->b_p_ro ? '=' : ' '); if (buf->terminal) { ro_char = channel_job_running((uint64_t)buf->b_p_channel) ? 'R' : 'F'; @@ -3592,8 +3592,8 @@ void ex_buffer_all(exarg_T *eap) // Try to close floating windows first for (wp = lastwin->w_floating ? lastwin : firstwin; wp != NULL; wp = wpnext) { wpnext = wp->w_floating - ? wp->w_prev->w_floating ? wp->w_prev : firstwin - : (wp->w_next == NULL || wp->w_next->w_floating) ? NULL : wp->w_next; + ? wp->w_prev->w_floating ? wp->w_prev : firstwin + : (wp->w_next == NULL || wp->w_next->w_floating) ? NULL : wp->w_next; if ((wp->w_buffer->b_nwindows > 1 || wp->w_floating || ((cmdmod.cmod_split & WSP_VERT) -- cgit From e89071522cb0b6d56fd4e7d7776851e73fb807c3 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Tue, 21 Nov 2023 14:53:43 +0100 Subject: fix(column): always set b_signcols.max Fix #26135 --- src/nvim/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 1e27d2e57c..c89d4f667a 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -4096,10 +4096,10 @@ int buf_signcols(buf_T *buf, int max) // Check if we need to redraw if (signcols != buf->b_signcols.size) { buf->b_signcols.size = signcols; - buf->b_signcols.max = max; redraw_buf_later(buf, UPD_NOT_VALID); } + buf->b_signcols.max = max; buf->b_signcols.valid = true; } -- cgit From ee276f8758aea38205e04d839afc69e8537a2642 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 25 Nov 2023 10:50:51 +0800 Subject: vim-patch:8.2.4685: when a swap file is found for a popup there is no dialog (#26207) Problem: When a swap file is found for a popup there is no dialog and the buffer is loaded anyway. Solution: Silently load the buffer read-only. (closes vim/vim#10073) https://github.com/vim/vim/commit/188639d75c363dffaf813e8e2209f7350ad1e871 Co-authored-by: Bram Moolenaar --- src/nvim/buffer.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index c89d4f667a..9df886ef9a 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -930,10 +930,14 @@ static void free_buffer_stuff(buf_T *buf, int free_flags) /// Go to another buffer. Handles the result of the ATTENTION dialog. void goto_buffer(exarg_T *eap, int start, int dir, int count) { + const int save_sea = swap_exists_action; + bufref_T old_curbuf; set_bufref(&old_curbuf, curbuf); - swap_exists_action = SEA_DIALOG; + if (swap_exists_action == SEA_NONE) { + swap_exists_action = SEA_DIALOG; + } (void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO, start, dir, count, eap->forceit); @@ -946,7 +950,7 @@ void goto_buffer(exarg_T *eap, int start, int dir, int count) // Quitting means closing the split window, nothing else. win_close(curwin, true, false); - swap_exists_action = SEA_NONE; + swap_exists_action = save_sea; swap_exists_did_quit = true; // Restore the error/interrupt/exception state if not discarded by a -- cgit From 38a20dd89f91c45ec8589bf1c50d50732882d38a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 27 Nov 2023 20:58:37 +0800 Subject: build(IWYU): replace most private mappings with pragmas (#26247) --- src/nvim/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 9df886ef9a..8526147287 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -78,7 +78,7 @@ #include "nvim/option.h" #include "nvim/option_vars.h" #include "nvim/optionstr.h" -#include "nvim/os/fs_defs.h" +#include "nvim/os/fs.h" #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/os/time.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/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 8526147287..12013c3c5b 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -84,7 +84,7 @@ #include "nvim/os/time.h" #include "nvim/path.h" #include "nvim/plines.h" -#include "nvim/pos.h" +#include "nvim/pos_defs.h" #include "nvim/quickfix.h" #include "nvim/regexp.h" #include "nvim/runtime.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/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 12013c3c5b..86cf805345 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -95,7 +95,7 @@ #include "nvim/strings.h" #include "nvim/syntax.h" #include "nvim/terminal.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/undo.h" #include "nvim/usercmd.h" -- cgit From 35cec0de4acd351119230330f54b0a45f9823695 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Mon, 27 Nov 2023 16:22:19 +0100 Subject: fix(column): redraw and update signcols for paired extmark Problem: Signcolumn width does not increase when ranged sign does not start at sentinel line. Solution: Handle paired range of added sign when checking signcols. --- src/nvim/buffer.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 86cf805345..2a3cebc0ae 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -4055,7 +4055,7 @@ void buf_signcols_del_check(buf_T *buf, linenr_T line1, linenr_T line2) /// /// @param buf buffer to check /// @param added sign being added -void buf_signcols_add_check(buf_T *buf, linenr_T lnum) +void buf_signcols_add_check(buf_T *buf, linenr_T line1, linenr_T line2) { if (!buf->b_signcols.valid) { return; @@ -4066,7 +4066,9 @@ void buf_signcols_add_check(buf_T *buf, linenr_T lnum) return; } - if (lnum == buf->b_signcols.sentinel) { + linenr_T sent = buf->b_signcols.sentinel; + + if (sent >= line1 && sent <= line2) { if (buf->b_signcols.size == buf->b_signcols.max) { buf->b_signcols.max++; } @@ -4075,12 +4077,11 @@ void buf_signcols_add_check(buf_T *buf, linenr_T lnum) return; } - int signcols = decor_signcols(buf, lnum - 1, lnum - 1, SIGN_SHOW_MAX); + int signcols = decor_signcols(buf, line1 - 1, line2 - 1, SIGN_SHOW_MAX); if (signcols > buf->b_signcols.size) { buf->b_signcols.size = signcols; buf->b_signcols.max = signcols; - buf->b_signcols.sentinel = lnum; redraw_buf_later(buf, UPD_NOT_VALID); } } -- 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/buffer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 2a3cebc0ae..4d553cc91f 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -29,8 +29,8 @@ #include "klib/kvec.h" #include "nvim/api/private/helpers.h" #include "nvim/arglist.h" -#include "nvim/ascii.h" -#include "nvim/assert.h" +#include "nvim/ascii_defs.h" +#include "nvim/assert_defs.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" #include "nvim/buffer_updates.h" @@ -65,7 +65,7 @@ #include "nvim/indent.h" #include "nvim/indent_c.h" #include "nvim/main.h" -#include "nvim/map.h" +#include "nvim/map_defs.h" #include "nvim/mapping.h" #include "nvim/mark.h" #include "nvim/mbyte.h" @@ -100,7 +100,7 @@ #include "nvim/undo.h" #include "nvim/usercmd.h" #include "nvim/version.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #include "nvim/window.h" #include "nvim/winfloat.h" -- cgit From f4001d27efae44c6c07678ad2c72eed5f1a25ea8 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Tue, 28 Nov 2023 05:40:18 +0100 Subject: perf(column): only invalidate lines affected by added sign --- src/nvim/buffer.c | 80 +++++++++++++++++++------------------------------------ 1 file changed, 28 insertions(+), 52 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 4d553cc91f..e6bedca232 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -1844,7 +1844,7 @@ buf_T *buflist_new(char *ffname_arg, char *sfname_arg, linenr_T lnum, int flags) buf = xcalloc(1, sizeof(buf_T)); // init b: variables buf->b_vars = tv_dict_alloc(); - buf->b_signcols.valid = false; + buf->b_signcols.sentinel = 0; init_var_dict(buf->b_vars, &buf->b_bufvar, VAR_SCOPE); buf_init_changedtick(buf); } @@ -4026,88 +4026,64 @@ char *buf_spname(buf_T *buf) return NULL; } -/// Invalidate the signcolumn if needed after deleting -/// signs between line1 and line2 (inclusive). -/// -/// @param buf buffer to check -/// @param line1 start of region being deleted -/// @param line2 end of region being deleted +/// Invalidate the signcolumn if needed after deleting a sign ranging from line1 to line2. void buf_signcols_del_check(buf_T *buf, linenr_T line1, linenr_T line2) { - if (!buf->b_signcols.valid) { - return; - } - - if (!buf->b_signcols.sentinel) { - buf->b_signcols.valid = false; - return; - } - linenr_T sent = buf->b_signcols.sentinel; - if (sent >= line1 && sent <= line2) { - // Only invalidate when removing signs at the sentinel line. - buf->b_signcols.valid = false; + // When removed sign overlaps the sentinel line, entire buffer needs to be checked. + buf->b_signcols.sentinel = buf->b_signcols.size = 0; } } -/// Re-calculate the signcolumn after adding a sign. -/// -/// @param buf buffer to check -/// @param added sign being added +/// Invalidate the signcolumn if needed after adding a sign ranging from line1 to line2. void buf_signcols_add_check(buf_T *buf, linenr_T line1, linenr_T line2) { - if (!buf->b_signcols.valid) { - return; - } - if (!buf->b_signcols.sentinel) { - buf->b_signcols.valid = false; return; } linenr_T sent = buf->b_signcols.sentinel; - if (sent >= line1 && sent <= line2) { + // If added sign overlaps sentinel line, increment without invalidating. if (buf->b_signcols.size == buf->b_signcols.max) { buf->b_signcols.max++; } buf->b_signcols.size++; - redraw_buf_later(buf, UPD_NOT_VALID); return; } - int signcols = decor_signcols(buf, line1 - 1, line2 - 1, SIGN_SHOW_MAX); - - if (signcols > buf->b_signcols.size) { - buf->b_signcols.size = signcols; - buf->b_signcols.max = signcols; - redraw_buf_later(buf, UPD_NOT_VALID); + if (line1 < buf->b_signcols.invalid_top) { + buf->b_signcols.invalid_top = line1; + } + if (line2 > buf->b_signcols.invalid_bot) { + buf->b_signcols.invalid_bot = line2; } } int buf_signcols(buf_T *buf, int max) { - // The maximum can be determined from 'signcolumn' which is window scoped so - // need to invalidate signcols if the maximum is greater than the previous - // (valid) maximum. - if (buf->b_signcols.max && max > buf->b_signcols.max) { - buf->b_signcols.valid = false; - } - - if (!buf->b_signcols.valid) { - buf->b_signcols.sentinel = 0; - int signcols = decor_signcols(buf, 0, (int)buf->b_ml.ml_line_count - 1, max); - // Check if we need to redraw - if (signcols != buf->b_signcols.size) { - buf->b_signcols.size = signcols; - redraw_buf_later(buf, UPD_NOT_VALID); + if (!buf->b_signs_with_text) { + buf->b_signcols.size = 0; + } else if (max <= 1 && buf->b_signs_with_text >= (size_t)max) { + buf->b_signcols.size = max; + } else { + linenr_T sent = buf->b_signcols.sentinel; + if (!sent || max > buf->b_signcols.max) { + // Recheck if the window scoped maximum 'signcolumn' is greater than the + // previous maximum or if there is no sentinel line yet. + buf->b_signcols.invalid_top = sent ? sent : 1; + buf->b_signcols.invalid_bot = sent ? sent : buf->b_ml.ml_line_count; } - buf->b_signcols.max = max; - buf->b_signcols.valid = true; + if (buf->b_signcols.invalid_bot) { + decor_validate_signcols(buf, max); + } } + buf->b_signcols.max = max; + buf->b_signcols.invalid_top = MAXLNUM; + buf->b_signcols.invalid_bot = 0; return buf->b_signcols.size; } -- 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/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index e6bedca232..8a594dea92 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -89,8 +89,8 @@ #include "nvim/regexp.h" #include "nvim/runtime.h" #include "nvim/search.h" -#include "nvim/sign.h" #include "nvim/spell.h" +#include "nvim/state_defs.h" #include "nvim/statusline.h" #include "nvim/strings.h" #include "nvim/syntax.h" -- cgit