From bcf5ee328e228d5a536b4de2069a79234f9f3e9e Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 23 Aug 2022 10:36:46 +0200 Subject: refactor(arena): use a shared block freelist This is both simpler in client code and more effective (always reuse block hottest in cache) --- src/nvim/screen.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index b471b93192..89b24e9440 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -1094,7 +1094,6 @@ void draw_tabline(void) static void ui_ext_tabline_update(void) { Arena arena = ARENA_EMPTY; - arena_start(&arena, &ui_ext_fixblk); size_t n_tabs = 0; FOR_ALL_TABS(tp) { @@ -1135,7 +1134,7 @@ static void ui_ext_tabline_update(void) } ui_call_tabline_update(curtab->handle, tabs, curbuf->handle, buffers); - arena_mem_free(arena_finish(&arena), &ui_ext_fixblk); + arena_mem_free(arena_finish(&arena)); } void get_trans_bufname(buf_T *buf) -- cgit From 93f24403f8cc760ff47979c596976b53a8b16358 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Wed, 24 Aug 2022 22:49:25 +0100 Subject: refactor: pre-incr to post-incr --- src/nvim/screen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 89b24e9440..58e195b745 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -1013,7 +1013,7 @@ void draw_tabline(void) modified = false; - for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) { + for (wincount = 0; wp != NULL; wp = wp->w_next, wincount++) { if (bufIsChanged(wp->w_buffer)) { modified = true; } -- cgit From 40855b0143a864739a6037921e15699445dcf8a7 Mon Sep 17 00:00:00 2001 From: Dundar Goc Date: Sun, 31 Jul 2022 16:20:57 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/screen.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 58e195b745..2ed31ae8a9 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -69,7 +69,7 @@ bool conceal_cursor_line(const win_T *wp) } else { return false; } - return vim_strchr((char *)wp->w_p_cocu, c) != NULL; + return vim_strchr(wp->w_p_cocu, c) != NULL; } /// Whether cursorline is drawn in a special way @@ -535,7 +535,7 @@ bool get_keymap_str(win_T *wp, char *fmt, char *buf, int len) curwin = old_curwin; if (p == NULL || *p == NUL) { if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) { - p = (char *)wp->w_buffer->b_p_keymap; + p = wp->w_buffer->b_p_keymap; } else { p = "lang"; } @@ -1347,16 +1347,16 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) { &wp->w_p_lcs_chars.conceal, "conceal", NUL }, }; - if (varp == &p_lcs || varp == &wp->w_p_lcs) { + if (varp == &p_lcs || varp == (char_u **)&wp->w_p_lcs) { tab = lcs_tab; entries = ARRAY_SIZE(lcs_tab); - if (varp == &wp->w_p_lcs && wp->w_p_lcs[0] == NUL) { + if (varp == (char_u **)&wp->w_p_lcs && wp->w_p_lcs[0] == NUL) { varp = &p_lcs; } } else { tab = fcs_tab; entries = ARRAY_SIZE(fcs_tab); - if (varp == &wp->w_p_fcs && wp->w_p_fcs[0] == NUL) { + if (varp == (char_u **)&wp->w_p_fcs && wp->w_p_fcs[0] == NUL) { varp = &p_fcs; } } @@ -1370,7 +1370,7 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) *(tab[i].cp) = tab[i].def; } } - if (varp == &p_lcs || varp == &wp->w_p_lcs) { + if (varp == &p_lcs || varp == (char_u **)&wp->w_p_lcs) { wp->w_p_lcs_chars.tab1 = NUL; wp->w_p_lcs_chars.tab3 = NUL; @@ -1439,7 +1439,7 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) if (i == entries) { len = (int)STRLEN("multispace"); len2 = (int)STRLEN("leadmultispace"); - if ((varp == &p_lcs || varp == &wp->w_p_lcs) + if ((varp == &p_lcs || varp == (char_u **)&wp->w_p_lcs) && STRNCMP(p, "multispace", len) == 0 && p[len] == ':' && p[len + 1] != NUL) { @@ -1470,7 +1470,7 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) } p = s; } - } else if ((varp == &p_lcs || varp == &wp->w_p_lcs) + } else if ((varp == &p_lcs || varp == (char_u **)&wp->w_p_lcs) && STRNCMP(p, "leadmultispace", len2) == 0 && p[len2] == ':' && p[len2 + 1] != NUL) { @@ -1527,10 +1527,10 @@ char *check_chars_options(void) return e_conflicts_with_value_of_fillchars; } FOR_ALL_TAB_WINDOWS(tp, wp) { - if (set_chars_option(wp, &wp->w_p_lcs, true) != NULL) { + if (set_chars_option(wp, (char_u **)&wp->w_p_lcs, true) != NULL) { return e_conflicts_with_value_of_listchars; } - if (set_chars_option(wp, &wp->w_p_fcs, true) != NULL) { + if (set_chars_option(wp, (char_u **)&wp->w_p_fcs, true) != NULL) { return e_conflicts_with_value_of_fillchars; } } -- cgit From db28c2ca2b6561bc65dd064ca5f45b0a9f3b4790 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 26 Aug 2022 09:04:51 +0800 Subject: refactor: set_chars_option() Rename "set" to "apply" and tidy up variable scopes. --- src/nvim/screen.c | 82 +++++++++++++++++++++++++++---------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 2ed31ae8a9..43c85bedb5 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -1262,17 +1262,15 @@ int number_width(win_T *wp) /// Calls mb_cptr2char_adv(p) and returns the character. /// If "p" starts with "\x", "\u" or "\U" the hex or unicode value is used. /// Returns 0 for invalid hex or invalid UTF-8 byte. -static int get_encoded_char_adv(char_u **p) +static int get_encoded_char_adv(const char_u **p) { - char_u *s = *p; + const char_u *s = *p; if (s[0] == '\\' && (s[1] == 'x' || s[1] == 'u' || s[1] == 'U')) { int64_t num = 0; - int bytes; - int n; - for (bytes = s[1] == 'x' ? 1 : s[1] == 'u' ? 2 : 4; bytes > 0; bytes--) { + for (int bytes = s[1] == 'x' ? 1 : s[1] == 'u' ? 2 : 4; bytes > 0; bytes--) { *p += 2; - n = hexhex2nr(*p); + int n = hexhex2nr(*p); if (n < 0) { return 0; } @@ -1283,8 +1281,8 @@ static int get_encoded_char_adv(char_u **p) } // TODO(bfredl): use schar_T representation and utfc_ptr2len - int clen = utf_ptr2len((char *)s); - int c = mb_cptr2char_adv((const char_u **)p); + int clen = utf_ptr2len((const char *)s); + int c = mb_cptr2char_adv(p); if (clen == 1 && c > 127) { // Invalid UTF-8 byte return 0; } @@ -1294,26 +1292,22 @@ static int get_encoded_char_adv(char_u **p) /// Handle setting 'listchars' or 'fillchars'. /// Assume monocell characters /// -/// @param varp either &curwin->w_p_lcs or &curwin->w_p_fcs +/// @param varp either the global or the window-local value. +/// @param apply if false, do not store the flags, only check for errors. /// @return error message, NULL if it's OK. -char *set_chars_option(win_T *wp, char_u **varp, bool set) +char *set_chars_option(win_T *wp, char_u **varp, bool apply) { - int round, i, len, len2, entries; - char_u *p, *s; - int c1; - int c2 = 0; - int c3 = 0; - char_u *last_multispace = NULL; // Last occurrence of "multispace:" - char_u *last_lmultispace = NULL; // Last occurrence of "leadmultispace:" + const char_u *last_multispace = NULL; // Last occurrence of "multispace:" + const char_u *last_lmultispace = NULL; // Last occurrence of "leadmultispace:" int multispace_len = 0; // Length of lcs-multispace string int lead_multispace_len = 0; // Length of lcs-leadmultispace string + const bool is_listchars = (varp == &p_lcs || varp == (char_u **)&wp->w_p_lcs); struct chars_tab { - int *cp; ///< char value + int *cp; ///< char value char *name; ///< char id - int def; ///< default value + int def; ///< default value }; - struct chars_tab *tab; // XXX: Characters taking 2 columns is forbidden (TUI limitation?). Set old defaults in this case. struct chars_tab fcs_tab[] = { @@ -1335,6 +1329,7 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) { &wp->w_p_fcs_chars.msgsep, "msgsep", ' ' }, { &wp->w_p_fcs_chars.eob, "eob", '~' }, }; + struct chars_tab lcs_tab[] = { { &wp->w_p_lcs_chars.eol, "eol", NUL }, { &wp->w_p_lcs_chars.ext, "extends", NUL }, @@ -1347,30 +1342,33 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) { &wp->w_p_lcs_chars.conceal, "conceal", NUL }, }; - if (varp == &p_lcs || varp == (char_u **)&wp->w_p_lcs) { + struct chars_tab *tab; + int entries; + const char_u *value = *varp; + if (is_listchars) { tab = lcs_tab; entries = ARRAY_SIZE(lcs_tab); if (varp == (char_u **)&wp->w_p_lcs && wp->w_p_lcs[0] == NUL) { - varp = &p_lcs; + value = p_lcs; // local value is empty, use the global value } } else { tab = fcs_tab; entries = ARRAY_SIZE(fcs_tab); if (varp == (char_u **)&wp->w_p_fcs && wp->w_p_fcs[0] == NUL) { - varp = &p_fcs; + value = p_fcs; // local value is empty, use the global value } } // first round: check for valid value, second round: assign values - for (round = 0; round <= (set ? 1 : 0); round++) { + for (int round = 0; round <= (apply ? 1 : 0); round++) { if (round > 0) { // After checking that the value is valid: set defaults - for (i = 0; i < entries; i++) { + for (int i = 0; i < entries; i++) { if (tab[i].cp != NULL) { *(tab[i].cp) = tab[i].def; } } - if (varp == &p_lcs || varp == (char_u **)&wp->w_p_lcs) { + if (is_listchars) { wp->w_p_lcs_chars.tab1 = NUL; wp->w_p_lcs_chars.tab3 = NUL; @@ -1392,19 +1390,20 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) } } } - p = *varp; + const char_u *p = value; while (*p) { + int i; for (i = 0; i < entries; i++) { - len = (int)STRLEN(tab[i].name); + const size_t len = STRLEN(tab[i].name); if (STRNCMP(p, tab[i].name, len) == 0 && p[len] == ':' && p[len + 1] != NUL) { - c2 = c3 = 0; - s = p + len + 1; - c1 = get_encoded_char_adv(&s); + const char_u *s = p + len + 1; + int c1 = get_encoded_char_adv(&s); if (c1 == 0 || char2cells(c1) > 1) { return e_invarg; } + int c2 = 0, c3 = 0; if (tab[i].cp == &wp->w_p_lcs_chars.tab2) { if (*s == NUL) { return e_invarg; @@ -1437,19 +1436,19 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) } if (i == entries) { - len = (int)STRLEN("multispace"); - len2 = (int)STRLEN("leadmultispace"); - if ((varp == &p_lcs || varp == (char_u **)&wp->w_p_lcs) + const size_t len = STRLEN("multispace"); + const size_t len2 = STRLEN("leadmultispace"); + if (is_listchars && STRNCMP(p, "multispace", len) == 0 && p[len] == ':' && p[len + 1] != NUL) { - s = p + len + 1; + const char_u *s = p + len + 1; if (round == 0) { // Get length of lcs-multispace string in the first round last_multispace = p; multispace_len = 0; while (*s != NUL && *s != ',') { - c1 = get_encoded_char_adv(&s); + int c1 = get_encoded_char_adv(&s); if (c1 == 0 || char2cells(c1) > 1) { return e_invarg; } @@ -1463,24 +1462,24 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) } else { int multispace_pos = 0; while (*s != NUL && *s != ',') { - c1 = get_encoded_char_adv(&s); + int c1 = get_encoded_char_adv(&s); if (p == last_multispace) { wp->w_p_lcs_chars.multispace[multispace_pos++] = c1; } } p = s; } - } else if ((varp == &p_lcs || varp == (char_u **)&wp->w_p_lcs) + } else if (is_listchars && STRNCMP(p, "leadmultispace", len2) == 0 && p[len2] == ':' && p[len2 + 1] != NUL) { - s = p + len2 + 1; + const char_u *s = p + len2 + 1; if (round == 0) { // get length of lcs-leadmultispace string in first round last_lmultispace = p; lead_multispace_len = 0; while (*s != NUL && *s != ',') { - c1 = get_encoded_char_adv(&s); + int c1 = get_encoded_char_adv(&s); if (c1 == 0 || char2cells(c1) > 1) { return e_invarg; } @@ -1494,7 +1493,7 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) } else { int multispace_pos = 0; while (*s != NUL && *s != ',') { - c1 = get_encoded_char_adv(&s); + int c1 = get_encoded_char_adv(&s); if (p == last_lmultispace) { wp->w_p_lcs_chars.leadmultispace[multispace_pos++] = c1; } @@ -1505,6 +1504,7 @@ char *set_chars_option(win_T *wp, char_u **varp, bool set) return e_invarg; } } + if (*p == ',') { p++; } -- cgit From 395277036014189c03b8969fc0a5cd2bdc5c8631 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 10:36:35 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/screen.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 43c85bedb5..9c1064d608 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -1301,7 +1301,7 @@ char *set_chars_option(win_T *wp, char_u **varp, bool apply) const char_u *last_lmultispace = NULL; // Last occurrence of "leadmultispace:" int multispace_len = 0; // Length of lcs-multispace string int lead_multispace_len = 0; // Length of lcs-leadmultispace string - const bool is_listchars = (varp == &p_lcs || varp == (char_u **)&wp->w_p_lcs); + const bool is_listchars = (varp == (char_u **)&p_lcs || varp == (char_u **)&wp->w_p_lcs); struct chars_tab { int *cp; ///< char value @@ -1349,13 +1349,13 @@ char *set_chars_option(win_T *wp, char_u **varp, bool apply) tab = lcs_tab; entries = ARRAY_SIZE(lcs_tab); if (varp == (char_u **)&wp->w_p_lcs && wp->w_p_lcs[0] == NUL) { - value = p_lcs; // local value is empty, use the global value + value = (char_u *)p_lcs; // local value is empty, use the global value } } else { tab = fcs_tab; entries = ARRAY_SIZE(fcs_tab); if (varp == (char_u **)&wp->w_p_fcs && wp->w_p_fcs[0] == NUL) { - value = p_fcs; // local value is empty, use the global value + value = (char_u *)p_fcs; // local value is empty, use the global value } } @@ -1520,10 +1520,10 @@ char *set_chars_option(win_T *wp, char_u **varp, bool apply) /// @return an untranslated error message if any of them is invalid, NULL otherwise. char *check_chars_options(void) { - if (set_chars_option(curwin, &p_lcs, false) != NULL) { + if (set_chars_option(curwin, (char_u **)&p_lcs, false) != NULL) { return e_conflicts_with_value_of_listchars; } - if (set_chars_option(curwin, &p_fcs, false) != NULL) { + if (set_chars_option(curwin, (char_u **)&p_fcs, false) != NULL) { return e_conflicts_with_value_of_fillchars; } FOR_ALL_TAB_WINDOWS(tp, wp) { -- cgit From 691f4715c0cf4bc11ea2280db8777e6dd174a8ac Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/screen.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 9c1064d608..3258dc11d6 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -734,13 +734,13 @@ int showmode(void) length = (Rows - msg_row) * Columns - 3; } if (edit_submode_extra != NULL) { - length -= vim_strsize((char *)edit_submode_extra); + length -= vim_strsize(edit_submode_extra); } if (length > 0) { if (edit_submode_pre != NULL) { - length -= vim_strsize((char *)edit_submode_pre); + length -= vim_strsize(edit_submode_pre); } - if (length - vim_strsize((char *)edit_submode) > 0) { + if (length - vim_strsize(edit_submode) > 0) { if (edit_submode_pre != NULL) { msg_puts_attr((const char *)edit_submode_pre, attr); } @@ -1026,7 +1026,7 @@ void draw_tabline(void) if (col + len >= Columns - 3) { break; } - grid_puts_len(&default_grid, NameBuff, len, 0, col, + grid_puts_len(&default_grid, (char_u *)NameBuff, len, 0, col, hl_combine_attr(attr, win_hl_attr(cwp, HLF_T))); col += len; } @@ -1040,9 +1040,9 @@ void draw_tabline(void) if (room > 0) { // Get buffer name in NameBuff[] get_trans_bufname(cwp->w_buffer); - shorten_dir(NameBuff); + shorten_dir((char_u *)NameBuff); len = vim_strsize((char *)NameBuff); - p = NameBuff; + p = (char_u *)NameBuff; while (len > room) { len -= ptr2cells((char *)p); MB_PTR_ADV(p); @@ -1295,13 +1295,13 @@ static int get_encoded_char_adv(const char_u **p) /// @param varp either the global or the window-local value. /// @param apply if false, do not store the flags, only check for errors. /// @return error message, NULL if it's OK. -char *set_chars_option(win_T *wp, char_u **varp, bool apply) +char *set_chars_option(win_T *wp, char **varp, bool apply) { const char_u *last_multispace = NULL; // Last occurrence of "multispace:" const char_u *last_lmultispace = NULL; // Last occurrence of "leadmultispace:" int multispace_len = 0; // Length of lcs-multispace string int lead_multispace_len = 0; // Length of lcs-leadmultispace string - const bool is_listchars = (varp == (char_u **)&p_lcs || varp == (char_u **)&wp->w_p_lcs); + const bool is_listchars = (varp == &p_lcs || varp == &wp->w_p_lcs); struct chars_tab { int *cp; ///< char value @@ -1344,17 +1344,17 @@ char *set_chars_option(win_T *wp, char_u **varp, bool apply) struct chars_tab *tab; int entries; - const char_u *value = *varp; + const char_u *value = (char_u *)(*varp); if (is_listchars) { tab = lcs_tab; entries = ARRAY_SIZE(lcs_tab); - if (varp == (char_u **)&wp->w_p_lcs && wp->w_p_lcs[0] == NUL) { + if (varp == &wp->w_p_lcs && wp->w_p_lcs[0] == NUL) { value = (char_u *)p_lcs; // local value is empty, use the global value } } else { tab = fcs_tab; entries = ARRAY_SIZE(fcs_tab); - if (varp == (char_u **)&wp->w_p_fcs && wp->w_p_fcs[0] == NUL) { + if (varp == &wp->w_p_fcs && wp->w_p_fcs[0] == NUL) { value = (char_u *)p_fcs; // local value is empty, use the global value } } @@ -1520,17 +1520,17 @@ char *set_chars_option(win_T *wp, char_u **varp, bool apply) /// @return an untranslated error message if any of them is invalid, NULL otherwise. char *check_chars_options(void) { - if (set_chars_option(curwin, (char_u **)&p_lcs, false) != NULL) { + if (set_chars_option(curwin, &p_lcs, false) != NULL) { return e_conflicts_with_value_of_listchars; } - if (set_chars_option(curwin, (char_u **)&p_fcs, false) != NULL) { + if (set_chars_option(curwin, &p_fcs, false) != NULL) { return e_conflicts_with_value_of_fillchars; } FOR_ALL_TAB_WINDOWS(tp, wp) { - if (set_chars_option(wp, (char_u **)&wp->w_p_lcs, true) != NULL) { + if (set_chars_option(wp, &wp->w_p_lcs, true) != NULL) { return e_conflicts_with_value_of_listchars; } - if (set_chars_option(wp, (char_u **)&wp->w_p_fcs, true) != NULL) { + if (set_chars_option(wp, &wp->w_p_fcs, true) != NULL) { return e_conflicts_with_value_of_fillchars; } } -- cgit From 58f30a326f34319801e7921f32c83e8320d85f6c Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/screen.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 3258dc11d6..6efaae3725 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -277,7 +277,7 @@ static int wildmenu_match_len(expand_T *xp, char_u *s) /// These are backslashes used for escaping. Do show backslashes in help tags. static int skip_wildmenu_char(expand_T *xp, char_u *s) { - if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) + if ((rem_backslash((char *)s) && xp->xp_context != EXPAND_HELP) || ((xp->xp_context == EXPAND_MENUS || xp->xp_context == EXPAND_MENUNAMES) && (s[0] == '\t' @@ -469,10 +469,10 @@ void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int match, i ScreenGrid *grid = (wild_menu_showing == WM_SCROLLED) ? &msg_grid_adj : &default_grid; - grid_puts(grid, buf, row, 0, attr); + grid_puts(grid, (char *)buf, row, 0, attr); if (selstart != NULL && highlight) { *selend = NUL; - grid_puts(grid, selstart, row, selstart_col, HL_ATTR(HLF_WM)); + grid_puts(grid, (char *)selstart, row, selstart_col, HL_ATTR(HLF_WM)); } grid_fill(grid, row, row + 1, clen, Columns, @@ -1026,12 +1026,12 @@ void draw_tabline(void) if (col + len >= Columns - 3) { break; } - grid_puts_len(&default_grid, (char_u *)NameBuff, len, 0, col, + grid_puts_len(&default_grid, NameBuff, len, 0, col, hl_combine_attr(attr, win_hl_attr(cwp, HLF_T))); col += len; } if (modified) { - grid_puts_len(&default_grid, (char_u *)"+", 1, 0, col++, attr); + grid_puts_len(&default_grid, "+", 1, 0, col++, attr); } grid_putchar(&default_grid, ' ', 0, col++, attr); } @@ -1040,7 +1040,7 @@ void draw_tabline(void) if (room > 0) { // Get buffer name in NameBuff[] get_trans_bufname(cwp->w_buffer); - shorten_dir((char_u *)NameBuff); + shorten_dir(NameBuff); len = vim_strsize((char *)NameBuff); p = (char_u *)NameBuff; while (len > room) { @@ -1051,7 +1051,7 @@ void draw_tabline(void) len = Columns - col - 1; } - grid_puts_len(&default_grid, p, (int)STRLEN(p), 0, col, attr); + grid_puts_len(&default_grid, (char *)p, (int)STRLEN(p), 0, col, attr); col += len; } grid_putchar(&default_grid, ' ', 0, col++, attr); -- cgit From 2828aae7b49921380f229ebf4d7432f39c6c2c2b Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 30 Aug 2022 14:52:09 +0200 Subject: refactor: replace char_u with char 4 (#19987) * refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/screen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 6efaae3725..d268dde845 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -1270,7 +1270,7 @@ static int get_encoded_char_adv(const char_u **p) int64_t num = 0; for (int bytes = s[1] == 'x' ? 1 : s[1] == 'u' ? 2 : 4; bytes > 0; bytes--) { *p += 2; - int n = hexhex2nr(*p); + int n = hexhex2nr((char *)(*p)); if (n < 0) { return 0; } -- cgit From 73207cae611a1efb8cd17139e8228772daeb9866 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/screen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index d268dde845..8e10f2d62d 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -620,7 +620,7 @@ void setcursor_mayforce(bool force) // With 'rightleft' set and the cursor on a double-wide character, // position it on the leftmost column. col = curwin->w_width_inner - curwin->w_wcol - - ((utf_ptr2cells((char *)get_cursor_pos_ptr()) == 2 + - ((utf_ptr2cells(get_cursor_pos_ptr()) == 2 && vim_isprintc(gchar_cursor())) ? 2 : 1); } -- cgit From 3ff46544c9872b4161fd098569c30b55fe3abd36 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/screen.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 8e10f2d62d..0ec6834364 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -1022,7 +1022,7 @@ void draw_tabline(void) if (modified || wincount > 1) { if (wincount > 1) { vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); - len = (int)STRLEN(NameBuff); + len = (int)strlen(NameBuff); if (col + len >= Columns - 3) { break; } @@ -1394,7 +1394,7 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) while (*p) { int i; for (i = 0; i < entries; i++) { - const size_t len = STRLEN(tab[i].name); + const size_t len = strlen(tab[i].name); if (STRNCMP(p, tab[i].name, len) == 0 && p[len] == ':' && p[len + 1] != NUL) { @@ -1436,8 +1436,8 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) } if (i == entries) { - const size_t len = STRLEN("multispace"); - const size_t len2 = STRLEN("leadmultispace"); + const size_t len = strlen("multispace"); + const size_t len2 = strlen("leadmultispace"); if (is_listchars && STRNCMP(p, "multispace", len) == 0 && p[len] == ':' -- cgit From 708bd686516b420c2b65f4bc4d2c58fe43fb945e Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 13 Sep 2022 12:56:30 +0200 Subject: feat(ui): use msg_grid based implementation for cmdheight=0 --- src/nvim/screen.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 0ec6834364..cdfb1e9ee1 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -442,7 +442,7 @@ void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int match, i // Put the wildmenu just above the command line. If there is // no room, scroll the screen one line up. if (cmdline_row == Rows - 1) { - msg_scroll_up(false); + msg_scroll_up(false, false); msg_scrolled++; } else { cmdline_row++; @@ -1173,7 +1173,9 @@ bool redrawing(void) /// Return true if printing messages should currently be done. bool messaging(void) { - return !(p_lz && char_avail() && !KeyTyped) && ui_has_messages(); + // TODO(bfredl): with general support for "async" messages with p_ch, + // this should be re-enabled. + return !(p_lz && char_avail() && !KeyTyped) && (p_ch > 0 || ui_has(kUIMessages)); } #define COL_RULER 17 // columns needed by standard ruler -- cgit From 93b30582db520ae20d66b000053007c11b62c15d Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 17 Aug 2022 15:40:21 +0200 Subject: fix(redraw): make redrawdebug=nodelta handle all the cases Before only win_line lines were considered. this applies nodelta to all screen elements. Causes some failures, which might indeed indicate excessive redraws. --- src/nvim/screen.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index cdfb1e9ee1..1af93f061c 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -155,8 +155,6 @@ void win_draw_end(win_T *wp, int c1, int c2, bool draw_margin, int row, int endr } else { grid_fill(&wp->w_grid, row, endrow, n, wp->w_grid.cols, c1, c2, attr); } - - set_empty_rows(wp, row); } /// Compute the width of the foldcolumn. Based on 'foldcolumn' and how much -- cgit From ddc363dce9020bce7d5bd931929f0d11cc87ad6d Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 4 Oct 2022 21:52:01 +0800 Subject: vim-patch:9.0.0656: cannot specify another character to use instead of '@' Problem: Cannot specify another character to use instead of '@' at the end of the window. Solution: Add "lastline" to 'fillchars'. (Martin Tournoij, closes vim/vim#11264, closes vim/vim#10963) https://github.com/vim/vim/commit/4ba5f1dab656103e8f4a4505452d1816b9e83c1e Use latest code in drawscreen.c instead. --- src/nvim/screen.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 1af93f061c..bc440441e1 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -1328,6 +1328,7 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) { &wp->w_p_fcs_chars.diff, "diff", '-' }, { &wp->w_p_fcs_chars.msgsep, "msgsep", ' ' }, { &wp->w_p_fcs_chars.eob, "eob", '~' }, + { &wp->w_p_fcs_chars.lastline, "lastline", '@' }, }; struct chars_tab lcs_tab[] = { -- cgit From 0578c67767a9cbaeaab167092a7bdb389f556ee4 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Oct 2022 07:29:58 +0800 Subject: vim-patch:9.0.0747: too many #ifdefs (#20641) Problem: Too many #ifdefs. Solution: Gradudate the +cmdline_info feature. (Martin Tournoij, closes vim/vim#11330) https://github.com/vim/vim/commit/ba43e76fcd5b2da57dbaa4d9a555793fe8ac344e --- src/nvim/screen.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index bc440441e1..90011eb2c7 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -860,6 +860,7 @@ int showmode(void) if (redrawing() && last->w_status_height == 0 && global_stl_height() == 0) { win_redr_ruler(last, true); } + redraw_cmdline = false; redraw_mode = false; clear_cmdline = false; -- cgit From 04cdea5f4ac49fa62cc4091a5c26791b80b4cc4c Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/screen.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 90011eb2c7..cd1d6553cb 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -237,12 +237,12 @@ size_t fill_foldcolumn(char_u *p, win_T *wp, foldinfo_T foldinfo, linenr_T lnum) /// Mirror text "str" for right-left displaying. /// Only works for single-byte characters (e.g., numbers). -void rl_mirror(char_u *str) +void rl_mirror(char *str) { - char_u *p1, *p2; - char_u t; + char *p1, *p2; + char t; - for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; p1++, p2--) { + for (p1 = str, p2 = str + strlen(str) - 1; p1 < p2; p1++, p2--) { t = *p1; *p1 = *p2; *p2 = t; -- cgit From 9f125371e08f4bbb38b84f323608d01d35895a3a Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Mon, 7 Nov 2022 04:10:09 +0100 Subject: refactor: click definition functions #20923 Need this part of `win_redr_custom()` in `drawline.c` for #20621. Another refactor is pending in https://github.com/vim/vim/pull/11467 --- src/nvim/screen.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index cd1d6553cb..377927ba4d 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -598,6 +598,49 @@ void stl_clear_click_defs(StlClickDefinition *const click_defs, const long click } } +/// Allocate or resize the click definitions array if needed. +StlClickDefinition *stl_alloc_click_defs(StlClickDefinition *cdp, long width, size_t *size) +{ + if (*size < (size_t)width) { + xfree(cdp); + *size = (size_t)width; + cdp = xcalloc(*size, sizeof(StlClickDefinition)); + } + return cdp; +} + +/// Fill the click definitions array if needed. +void stl_fill_click_defs(StlClickDefinition *click_defs, StlClickRecord *click_recs, char *buf, + int width, bool tabline) +{ + if (click_defs == NULL) { + return; + } + + int col = 0; + int len = 0; + + StlClickDefinition cur_click_def = { + .type = kStlClickDisabled, + }; + for (int i = 0; click_recs[i].start != NULL; i++) { + len += vim_strnsize(buf, (int)(click_recs[i].start - buf)); + while (col < len) { + click_defs[col++] = cur_click_def; + } + buf = (char *)click_recs[i].start; + cur_click_def = click_recs[i].def; + if (!tabline && !(cur_click_def.type == kStlClickDisabled + || cur_click_def.type == kStlClickFuncRun)) { + // window bar and status line only support click functions + cur_click_def.type = kStlClickDisabled; + } + } + while (col < width) { + click_defs[col++] = cur_click_def; + } +} + /// Set cursor to its position in the current window. void setcursor(void) { -- cgit From 8147d3df284a075f89746f9d5e948b5220c45f0b Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Tue, 8 Nov 2022 00:21:22 +0100 Subject: vim-patch:9.0.0844: handling 'statusline' errors is spread out (#20992) Problem: Handling 'statusline' errors is spread out. Solution: Pass the option name to the lower levels so the option can be reset there when an error is encountered. (Luuk van Baal, closes vim/vim#11467) https://github.com/vim/vim/commit/7b224fdf4a29f115567d4fc8629c1cef92d8444a --- src/nvim/screen.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 377927ba4d..39b3291404 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -999,16 +999,7 @@ void draw_tabline(void) // Use the 'tabline' option if it's set. if (*p_tal != NUL) { - int saved_did_emsg = did_emsg; - - // Check for an error. If there is one we would loop in redrawing the - // screen. Avoid that by making 'tabline' empty. - did_emsg = false; win_redr_custom(NULL, false, false); - if (did_emsg) { - set_string_option_direct("tabline", -1, "", OPT_FREE, SID_ERROR); - } - did_emsg |= saved_did_emsg; } else { FOR_ALL_TABS(tp) { tabcount++; -- cgit From 69507c0204cfe284e42865c9c89baec0f351b2c1 Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Thu, 10 Nov 2022 12:05:16 +0100 Subject: refactor: move tabline code to statusline.c (#21008) * refactor: move tabline code to statusline.c Problem: Tabline code is closely related to statusline, but still left over in drawscreen.c and screen.c. Solution: Move it to statusline.c. * refactor: add statusline_defs.h --- src/nvim/screen.c | 270 ------------------------------------------------------ 1 file changed, 270 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 39b3291404..2470fd326b 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -582,65 +582,6 @@ void check_for_delay(bool check_msg_scroll) } } -/// Clear status line, window bar or tab page line click definition table -/// -/// @param[out] tpcd Table to clear. -/// @param[in] tpcd_size Size of the table. -void stl_clear_click_defs(StlClickDefinition *const click_defs, const long click_defs_size) -{ - if (click_defs != NULL) { - for (long i = 0; i < click_defs_size; i++) { - if (i == 0 || click_defs[i].func != click_defs[i - 1].func) { - xfree(click_defs[i].func); - } - } - memset(click_defs, 0, (size_t)click_defs_size * sizeof(click_defs[0])); - } -} - -/// Allocate or resize the click definitions array if needed. -StlClickDefinition *stl_alloc_click_defs(StlClickDefinition *cdp, long width, size_t *size) -{ - if (*size < (size_t)width) { - xfree(cdp); - *size = (size_t)width; - cdp = xcalloc(*size, sizeof(StlClickDefinition)); - } - return cdp; -} - -/// Fill the click definitions array if needed. -void stl_fill_click_defs(StlClickDefinition *click_defs, StlClickRecord *click_recs, char *buf, - int width, bool tabline) -{ - if (click_defs == NULL) { - return; - } - - int col = 0; - int len = 0; - - StlClickDefinition cur_click_def = { - .type = kStlClickDisabled, - }; - for (int i = 0; click_recs[i].start != NULL; i++) { - len += vim_strnsize(buf, (int)(click_recs[i].start - buf)); - while (col < len) { - click_defs[col++] = cur_click_def; - } - buf = (char *)click_recs[i].start; - cur_click_def = click_recs[i].def; - if (!tabline && !(cur_click_def.type == kStlClickDisabled - || cur_click_def.type == kStlClickFuncRun)) { - // window bar and status line only support click functions - cur_click_def.type = kStlClickDisabled; - } - } - while (col < width) { - click_defs[col++] = cur_click_def; - } -} - /// Set cursor to its position in the current window. void setcursor(void) { @@ -959,217 +900,6 @@ static void recording_mode(int attr) } } -/// Draw the tab pages line at the top of the Vim window. -void draw_tabline(void) -{ - int tabcount = 0; - int tabwidth = 0; - int col = 0; - int scol = 0; - int attr; - win_T *wp; - win_T *cwp; - int wincount; - int modified; - int c; - int len; - int attr_nosel = HL_ATTR(HLF_TP); - int attr_fill = HL_ATTR(HLF_TPF); - char_u *p; - int room; - int use_sep_chars = (t_colors < 8); - - if (default_grid.chars == NULL) { - return; - } - redraw_tabline = false; - - if (ui_has(kUITabline)) { - ui_ext_tabline_update(); - return; - } - - if (tabline_height() < 1) { - return; - } - - // Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. - assert(Columns == tab_page_click_defs_size); - stl_clear_click_defs(tab_page_click_defs, tab_page_click_defs_size); - - // Use the 'tabline' option if it's set. - if (*p_tal != NUL) { - win_redr_custom(NULL, false, false); - } else { - FOR_ALL_TABS(tp) { - tabcount++; - } - - if (tabcount > 0) { - tabwidth = (Columns - 1 + tabcount / 2) / tabcount; - } - - if (tabwidth < 6) { - tabwidth = 6; - } - - attr = attr_nosel; - tabcount = 0; - - FOR_ALL_TABS(tp) { - if (col >= Columns - 4) { - break; - } - - scol = col; - - if (tp == curtab) { - cwp = curwin; - wp = firstwin; - } else { - cwp = tp->tp_curwin; - wp = tp->tp_firstwin; - } - - if (tp->tp_topframe == topframe) { - attr = win_hl_attr(cwp, HLF_TPS); - } - if (use_sep_chars && col > 0) { - grid_putchar(&default_grid, '|', 0, col++, attr); - } - - if (tp->tp_topframe != topframe) { - attr = win_hl_attr(cwp, HLF_TP); - } - - grid_putchar(&default_grid, ' ', 0, col++, attr); - - modified = false; - - for (wincount = 0; wp != NULL; wp = wp->w_next, wincount++) { - if (bufIsChanged(wp->w_buffer)) { - modified = true; - } - } - - if (modified || wincount > 1) { - if (wincount > 1) { - vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); - len = (int)strlen(NameBuff); - if (col + len >= Columns - 3) { - break; - } - grid_puts_len(&default_grid, NameBuff, len, 0, col, - hl_combine_attr(attr, win_hl_attr(cwp, HLF_T))); - col += len; - } - if (modified) { - grid_puts_len(&default_grid, "+", 1, 0, col++, attr); - } - grid_putchar(&default_grid, ' ', 0, col++, attr); - } - - room = scol - col + tabwidth - 1; - if (room > 0) { - // Get buffer name in NameBuff[] - get_trans_bufname(cwp->w_buffer); - shorten_dir(NameBuff); - len = vim_strsize((char *)NameBuff); - p = (char_u *)NameBuff; - while (len > room) { - len -= ptr2cells((char *)p); - MB_PTR_ADV(p); - } - if (len > Columns - col - 1) { - len = Columns - col - 1; - } - - grid_puts_len(&default_grid, (char *)p, (int)STRLEN(p), 0, col, attr); - col += len; - } - grid_putchar(&default_grid, ' ', 0, col++, attr); - - // Store the tab page number in tab_page_click_defs[], so that - // jump_to_mouse() knows where each one is. - tabcount++; - while (scol < col) { - tab_page_click_defs[scol++] = (StlClickDefinition) { - .type = kStlClickTabSwitch, - .tabnr = tabcount, - .func = NULL, - }; - } - } - - if (use_sep_chars) { - c = '_'; - } else { - c = ' '; - } - grid_fill(&default_grid, 0, 1, col, Columns, c, c, attr_fill); - - // Put an "X" for closing the current tab if there are several. - if (first_tabpage->tp_next != NULL) { - grid_putchar(&default_grid, 'X', 0, Columns - 1, attr_nosel); - tab_page_click_defs[Columns - 1] = (StlClickDefinition) { - .type = kStlClickTabClose, - .tabnr = 999, - .func = NULL, - }; - } - } - - // Reset the flag here again, in case evaluating 'tabline' causes it to be - // set. - redraw_tabline = false; -} - -static void ui_ext_tabline_update(void) -{ - Arena arena = ARENA_EMPTY; - - size_t n_tabs = 0; - FOR_ALL_TABS(tp) { - n_tabs++; - } - - Array tabs = arena_array(&arena, n_tabs); - FOR_ALL_TABS(tp) { - Dictionary tab_info = arena_dict(&arena, 2); - PUT_C(tab_info, "tab", TABPAGE_OBJ(tp->handle)); - - win_T *cwp = (tp == curtab) ? curwin : tp->tp_curwin; - get_trans_bufname(cwp->w_buffer); - PUT_C(tab_info, "name", STRING_OBJ(arena_string(&arena, cstr_as_string((char *)NameBuff)))); - - ADD_C(tabs, DICTIONARY_OBJ(tab_info)); - } - - size_t n_buffers = 0; - FOR_ALL_BUFFERS(buf) { - n_buffers += buf->b_p_bl ? 1 : 0; - } - - Array buffers = arena_array(&arena, n_buffers); - FOR_ALL_BUFFERS(buf) { - // Do not include unlisted buffers - if (!buf->b_p_bl) { - continue; - } - - Dictionary buffer_info = arena_dict(&arena, 2); - PUT_C(buffer_info, "buffer", BUFFER_OBJ(buf->handle)); - - get_trans_bufname(buf); - PUT_C(buffer_info, "name", STRING_OBJ(arena_string(&arena, cstr_as_string((char *)NameBuff)))); - - ADD_C(buffers, DICTIONARY_OBJ(buffer_info)); - } - - ui_call_tabline_update(curtab->handle, tabs, curbuf->handle, buffers); - arena_mem_free(arena_finish(&arena)); -} - void get_trans_bufname(buf_T *buf) { if (buf_spname(buf) != NULL) { -- cgit From 0d8e8d36ec7d3f4967f27389b4b94edf3ba57433 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 11 Nov 2022 17:50:52 +0800 Subject: vim-patch:8.2.1919: assert_fails() setting emsg_silent changes normal execution (#20998) Problem: Assert_fails() setting emsg_silent changes normal execution. Solution: Use a separate flag in_assert_fails. https://github.com/vim/vim/commit/28ee892ac4197421b3317f195512ca64cc56a5b4 Cherry-pick no_wait_return from patch 9.0.0846. Co-authored-by: Bram Moolenaar --- src/nvim/screen.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 2470fd326b..3f27302617 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -572,7 +572,8 @@ void check_for_delay(bool check_msg_scroll) { if ((emsg_on_display || (check_msg_scroll && msg_scroll)) && !did_wait_return - && emsg_silent == 0) { + && emsg_silent == 0 + && !in_assert_fails) { ui_flush(); os_delay(1006L, true); emsg_on_display = false; -- cgit From ec449c27fdad6cc907a6f4835ce28f31990ad519 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 13 Nov 2022 08:20:00 +0800 Subject: vim-patch:9.0.0867: wildmenu redrawing code is spread out (#21035) Problem: Wildmenu redrawing code is spread out. Solution: Refactor to move code together. (closes vim/vim#11528) https://github.com/vim/vim/commit/d6e91385f0f7256aec8f70373c9e3399770d22e5 Co-authored-by: Bram Moolenaar --- src/nvim/screen.c | 235 ------------------------------------------------------ 1 file changed, 235 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 3f27302617..cbd5b96bef 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -15,9 +15,7 @@ #include "nvim/buffer.h" #include "nvim/charset.h" -#include "nvim/cmdexpand.h" #include "nvim/cursor.h" -#include "nvim/drawscreen.h" #include "nvim/eval.h" #include "nvim/extmark.h" #include "nvim/fileio.h" @@ -27,7 +25,6 @@ #include "nvim/grid.h" #include "nvim/highlight.h" #include "nvim/highlight_group.h" -#include "nvim/menu.h" #include "nvim/move.h" #include "nvim/option.h" #include "nvim/optionstr.h" @@ -249,238 +246,6 @@ void rl_mirror(char *str) } } -/// Get the length of an item as it will be shown in the status line. -static int wildmenu_match_len(expand_T *xp, char_u *s) -{ - int len = 0; - - int emenu = (xp->xp_context == EXPAND_MENUS - || xp->xp_context == EXPAND_MENUNAMES); - - // Check for menu separators - replace with '|'. - if (emenu && menu_is_separator((char *)s)) { - return 1; - } - - while (*s != NUL) { - s += skip_wildmenu_char(xp, s); - len += ptr2cells((char *)s); - MB_PTR_ADV(s); - } - - return len; -} - -/// Return the number of characters that should be skipped in the wildmenu -/// These are backslashes used for escaping. Do show backslashes in help tags. -static int skip_wildmenu_char(expand_T *xp, char_u *s) -{ - if ((rem_backslash((char *)s) && xp->xp_context != EXPAND_HELP) - || ((xp->xp_context == EXPAND_MENUS - || xp->xp_context == EXPAND_MENUNAMES) - && (s[0] == '\t' - || (s[0] == '\\' && s[1] != NUL)))) { -#ifndef BACKSLASH_IN_FILENAME - // TODO(bfredl): Why in the actual fuck are we special casing the - // shell variety deep in the redraw logic? Shell special snowflakiness - // should already be eliminated multiple layers before reaching the - // screen infracstructure. - if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') { - return 2; - } -#endif - return 1; - } - return 0; -} - -/// Show wildchar matches in the status line. -/// Show at least the "match" item. -/// We start at item 'first_match' in the list and show all matches that fit. -/// -/// If inversion is possible we use it. Else '=' characters are used. -/// -/// @param matches list of matches -void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int match, int showtail) -{ -#define L_MATCH(m) (showtail ? sm_gettail(matches[m], false) : matches[m]) - int row; - char_u *buf; - int len; - int clen; // length in screen cells - int fillchar; - int attr; - int i; - bool highlight = true; - char_u *selstart = NULL; - int selstart_col = 0; - char_u *selend = NULL; - static int first_match = 0; - bool add_left = false; - char_u *s; - int emenu; - int l; - - if (matches == NULL) { // interrupted completion? - return; - } - - buf = xmalloc((size_t)Columns * MB_MAXBYTES + 1); - - if (match == -1) { // don't show match but original text - match = 0; - highlight = false; - } - // count 1 for the ending ">" - clen = wildmenu_match_len(xp, (char_u *)L_MATCH(match)) + 3; - if (match == 0) { - first_match = 0; - } else if (match < first_match) { - // jumping left, as far as we can go - first_match = match; - add_left = true; - } else { - // check if match fits on the screen - for (i = first_match; i < match; i++) { - clen += wildmenu_match_len(xp, (char_u *)L_MATCH(i)) + 2; - } - if (first_match > 0) { - clen += 2; - } - // jumping right, put match at the left - if ((long)clen > Columns) { - first_match = match; - // if showing the last match, we can add some on the left - clen = 2; - for (i = match; i < num_matches; i++) { - clen += wildmenu_match_len(xp, (char_u *)L_MATCH(i)) + 2; - if ((long)clen >= Columns) { - break; - } - } - if (i == num_matches) { - add_left = true; - } - } - } - if (add_left) { - while (first_match > 0) { - clen += wildmenu_match_len(xp, (char_u *)L_MATCH(first_match - 1)) + 2; - if ((long)clen >= Columns) { - break; - } - first_match--; - } - } - - fillchar = fillchar_status(&attr, curwin); - - if (first_match == 0) { - *buf = NUL; - len = 0; - } else { - STRCPY(buf, "< "); - len = 2; - } - clen = len; - - i = first_match; - while (clen + wildmenu_match_len(xp, (char_u *)L_MATCH(i)) + 2 < Columns) { - if (i == match) { - selstart = buf + len; - selstart_col = clen; - } - - s = (char_u *)L_MATCH(i); - // Check for menu separators - replace with '|' - emenu = (xp->xp_context == EXPAND_MENUS - || xp->xp_context == EXPAND_MENUNAMES); - if (emenu && menu_is_separator((char *)s)) { - STRCPY(buf + len, transchar('|')); - l = (int)STRLEN(buf + len); - len += l; - clen += l; - } else { - for (; *s != NUL; s++) { - s += skip_wildmenu_char(xp, s); - clen += ptr2cells((char *)s); - if ((l = utfc_ptr2len((char *)s)) > 1) { - STRNCPY(buf + len, s, l); // NOLINT(runtime/printf) - s += l - 1; - len += l; - } else { - STRCPY(buf + len, transchar_byte(*s)); - len += (int)STRLEN(buf + len); - } - } - } - if (i == match) { - selend = buf + len; - } - - *(buf + len++) = ' '; - *(buf + len++) = ' '; - clen += 2; - if (++i == num_matches) { - break; - } - } - - if (i != num_matches) { - *(buf + len++) = '>'; - clen++; - } - - buf[len] = NUL; - - row = cmdline_row - 1; - if (row >= 0) { - if (wild_menu_showing == 0 || wild_menu_showing == WM_LIST) { - if (msg_scrolled > 0) { - // Put the wildmenu just above the command line. If there is - // no room, scroll the screen one line up. - if (cmdline_row == Rows - 1) { - msg_scroll_up(false, false); - msg_scrolled++; - } else { - cmdline_row++; - row++; - } - wild_menu_showing = WM_SCROLLED; - } else { - // Create status line if needed by setting 'laststatus' to 2. - // Set 'winminheight' to zero to avoid that the window is - // resized. - if (lastwin->w_status_height == 0 && global_stl_height() == 0) { - save_p_ls = (int)p_ls; - save_p_wmh = (int)p_wmh; - p_ls = 2; - p_wmh = 0; - last_status(false); - } - wild_menu_showing = WM_SHOWN; - } - } - - // Tricky: wildmenu can be drawn either over a status line, or at empty - // scrolled space in the message output - ScreenGrid *grid = (wild_menu_showing == WM_SCROLLED) - ? &msg_grid_adj : &default_grid; - - grid_puts(grid, (char *)buf, row, 0, attr); - if (selstart != NULL && highlight) { - *selend = NUL; - grid_puts(grid, (char *)selstart, row, selstart_col, HL_ATTR(HLF_WM)); - } - - grid_fill(grid, row, row + 1, clen, Columns, - fillchar, fillchar, attr); - } - - win_redraw_last_status(topframe); - xfree(buf); -} - /// Only call if (wp->w_vsep_width != 0). /// /// @return true if the status line of window "wp" is connected to the status -- cgit From 66360675cf4d091b7460e4a8e1435c13216c1929 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 11 Sep 2022 17:12:44 +0200 Subject: build: allow IWYU to fix includes for all .c files Allow Include What You Use to remove unnecessary includes and only include what is necessary. This helps with reducing compilation times and makes it easier to visualise which dependencies are actually required. Work on https://github.com/neovim/neovim/issues/549, but doesn't close it since this only works fully for .c files and not headers. --- src/nvim/screen.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index cbd5b96bef..3957cec316 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -10,32 +10,44 @@ #include #include +#include #include +#include +#include #include +#include "nvim/ascii.h" #include "nvim/buffer.h" #include "nvim/charset.h" #include "nvim/cursor.h" #include "nvim/eval.h" -#include "nvim/extmark.h" -#include "nvim/fileio.h" #include "nvim/fold.h" -#include "nvim/garray.h" #include "nvim/getchar.h" +#include "nvim/gettext.h" +#include "nvim/globals.h" #include "nvim/grid.h" +#include "nvim/grid_defs.h" #include "nvim/highlight.h" -#include "nvim/highlight_group.h" +#include "nvim/mbyte.h" +#include "nvim/memline_defs.h" +#include "nvim/memory.h" +#include "nvim/message.h" #include "nvim/move.h" +#include "nvim/normal.h" #include "nvim/option.h" -#include "nvim/optionstr.h" +#include "nvim/os/os.h" +#include "nvim/os/time.h" +#include "nvim/pos.h" #include "nvim/profile.h" #include "nvim/regexp.h" #include "nvim/screen.h" #include "nvim/search.h" #include "nvim/state.h" #include "nvim/statusline.h" -#include "nvim/ui_compositor.h" -#include "nvim/undo.h" +#include "nvim/strings.h" +#include "nvim/types.h" +#include "nvim/ui.h" +#include "nvim/vim.h" #include "nvim/window.h" #ifdef INCLUDE_GENERATED_DECLARATIONS -- cgit From 3b96ccf7d35be90e49029dec76344d3d92ad91dc Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 26 Nov 2022 18:57:46 +0100 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/screen.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 3957cec316..8655206574 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -934,15 +934,15 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) } } } - const char_u *p = value; + const char *p = (char *)value; while (*p) { int i; for (i = 0; i < entries; i++) { const size_t len = strlen(tab[i].name); - if (STRNCMP(p, tab[i].name, len) == 0 + if (strncmp(p, tab[i].name, len) == 0 && p[len] == ':' && p[len + 1] != NUL) { - const char_u *s = p + len + 1; + const char_u *s = (char_u *)p + len + 1; int c1 = get_encoded_char_adv(&s); if (c1 == 0 || char2cells(c1) > 1) { return e_invarg; @@ -973,7 +973,7 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) *(tab[i].cp) = c1; } } - p = s; + p = (char *)s; break; } } @@ -983,13 +983,13 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) const size_t len = strlen("multispace"); const size_t len2 = strlen("leadmultispace"); if (is_listchars - && STRNCMP(p, "multispace", len) == 0 + && strncmp(p, "multispace", len) == 0 && p[len] == ':' && p[len + 1] != NUL) { - const char_u *s = p + len + 1; + const char_u *s = (char_u *)p + len + 1; if (round == 0) { // Get length of lcs-multispace string in the first round - last_multispace = p; + last_multispace = (char_u *)p; multispace_len = 0; while (*s != NUL && *s != ',') { int c1 = get_encoded_char_adv(&s); @@ -1002,25 +1002,25 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) // lcs-multispace cannot be an empty string return e_invarg; } - p = s; + p = (char *)s; } else { int multispace_pos = 0; while (*s != NUL && *s != ',') { int c1 = get_encoded_char_adv(&s); - if (p == last_multispace) { + if (p == (char *)last_multispace) { wp->w_p_lcs_chars.multispace[multispace_pos++] = c1; } } - p = s; + p = (char *)s; } } else if (is_listchars - && STRNCMP(p, "leadmultispace", len2) == 0 + && strncmp(p, "leadmultispace", len2) == 0 && p[len2] == ':' && p[len2 + 1] != NUL) { - const char_u *s = p + len2 + 1; + const char_u *s = (char_u *)p + len2 + 1; if (round == 0) { // get length of lcs-leadmultispace string in first round - last_lmultispace = p; + last_lmultispace = (char_u *)p; lead_multispace_len = 0; while (*s != NUL && *s != ',') { int c1 = get_encoded_char_adv(&s); @@ -1033,16 +1033,16 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) // lcs-leadmultispace cannot be an empty string return e_invarg; } - p = s; + p = (char *)s; } else { int multispace_pos = 0; while (*s != NUL && *s != ',') { int c1 = get_encoded_char_adv(&s); - if (p == last_lmultispace) { + if (p == (char *)last_lmultispace) { wp->w_p_lcs_chars.leadmultispace[multispace_pos++] = c1; } } - p = s; + p = (char *)s; } } else { return e_invarg; -- cgit From 149209400383c673fdb4fdd1c9a7639139f17936 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 9 Jan 2023 14:13:06 +0100 Subject: refactor: replace char_u with char 17 - remove STRLCPY (#21235) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/screen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 8655206574..58aec2e84c 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -681,7 +681,7 @@ static void recording_mode(int attr) void get_trans_bufname(buf_T *buf) { if (buf_spname(buf) != NULL) { - STRLCPY(NameBuff, buf_spname(buf), MAXPATHL); + xstrlcpy(NameBuff, buf_spname(buf), MAXPATHL); } else { home_replace(buf, buf->b_fname, (char *)NameBuff, MAXPATHL, true); } -- cgit From 50f03773f4b9f4638489ccfd0503dc9e39e5de78 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 9 Jan 2023 15:37:34 +0100 Subject: refactor: replace char_u with char 18 (#21237) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/screen.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 58aec2e84c..52ab2ad25e 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -547,8 +547,8 @@ int showmode(void) if (curwin->w_p_arab) { msg_puts_attr(_(" Arabic"), attr); } else if (get_keymap_str(curwin, " (%s)", - (char *)NameBuff, MAXPATHL)) { - msg_puts_attr((char *)NameBuff, attr); + NameBuff, MAXPATHL)) { + msg_puts_attr(NameBuff, attr); } } if ((State & MODE_INSERT) && p_paste) { @@ -683,9 +683,9 @@ void get_trans_bufname(buf_T *buf) if (buf_spname(buf) != NULL) { xstrlcpy(NameBuff, buf_spname(buf), MAXPATHL); } else { - home_replace(buf, buf->b_fname, (char *)NameBuff, MAXPATHL, true); + home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, true); } - trans_characters((char *)NameBuff, MAXPATHL); + trans_characters(NameBuff, MAXPATHL); } /// Get the character to use in a separator between vertically split windows. -- cgit From 364b131f42509326c912c9b0fef5dfc94ed23b41 Mon Sep 17 00:00:00 2001 From: luukvbaal <31730729+luukvbaal@users.noreply.github.com> Date: Mon, 9 Jan 2023 18:12:06 +0100 Subject: feat(ui): add 'statuscolumn' option Problem: Unable to customize the column next to a window ('gutter'). Solution: Add 'statuscolumn' option that follows the 'statusline' syntax, allowing to customize the status column. Also supporting the %@ click execute function label. Adds new items @C and @s which will print the fold and sign columns. Line numbers and signs can be clicked, highlighted, aligned, transformed, margined etc. --- src/nvim/screen.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 52ab2ad25e..afdb04ebd8 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -780,6 +780,16 @@ int number_width(win_T *wp) } wp->w_nrwidth_line_count = lnum; + // make best estimate for 'statuscolumn' + if (*wp->w_p_stc != NUL) { + char buf[MAXPATHL]; + wp->w_nrwidth_width = 0; + n = build_statuscol_str(wp, true, false, lnum, 0, 0, NUL, buf, NULL, NULL); + n = MAX(n, (wp->w_p_nu || wp->w_p_rnu) * (int)wp->w_p_nuw); + wp->w_nrwidth_width = MIN(n, MAX_NUMBERWIDTH); + return wp->w_nrwidth_width; + } + n = 0; do { lnum /= 10; -- cgit From e89c39d6f016a4140293755250e968e839009617 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 14 Jan 2023 08:58:28 +0100 Subject: refactor: replace char_u with char 21 (#21779) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/screen.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index afdb04ebd8..b18bf7ed6a 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -189,7 +189,7 @@ int compute_foldcolumn(win_T *wp, int col) /// /// Assume monocell characters /// @return number of chars added to \param p -size_t fill_foldcolumn(char_u *p, win_T *wp, foldinfo_T foldinfo, linenr_T lnum) +size_t fill_foldcolumn(char *p, win_T *wp, foldinfo_T foldinfo, linenr_T lnum) { int i = 0; int level; @@ -223,7 +223,7 @@ size_t fill_foldcolumn(char_u *p, win_T *wp, foldinfo_T foldinfo, linenr_T lnum) symbol = '>'; } - len = utf_char2bytes(symbol, (char *)&p[char_counter]); + len = utf_char2bytes(symbol, &p[char_counter]); char_counter += (size_t)len; if (first_level + i >= level) { i++; @@ -237,7 +237,7 @@ size_t fill_foldcolumn(char_u *p, win_T *wp, foldinfo_T foldinfo, linenr_T lnum) char_counter -= (size_t)len; memset(&p[char_counter], ' ', (size_t)len); } - len = utf_char2bytes(wp->w_p_fcs_chars.foldclosed, (char *)&p[char_counter]); + len = utf_char2bytes(wp->w_p_fcs_chars.foldclosed, &p[char_counter]); char_counter += (size_t)len; } @@ -817,7 +817,7 @@ int number_width(win_T *wp) /// Returns 0 for invalid hex or invalid UTF-8 byte. static int get_encoded_char_adv(const char_u **p) { - const char_u *s = *p; + const char *s = (const char *)(*p); if (s[0] == '\\' && (s[1] == 'x' || s[1] == 'u' || s[1] == 'U')) { int64_t num = 0; @@ -834,7 +834,7 @@ static int get_encoded_char_adv(const char_u **p) } // TODO(bfredl): use schar_T representation and utfc_ptr2len - int clen = utf_ptr2len((const char *)s); + int clen = utf_ptr2len(s); int c = mb_cptr2char_adv(p); if (clen == 1 && c > 127) { // Invalid UTF-8 byte return 0; @@ -850,8 +850,8 @@ static int get_encoded_char_adv(const char_u **p) /// @return error message, NULL if it's OK. char *set_chars_option(win_T *wp, char **varp, bool apply) { - const char_u *last_multispace = NULL; // Last occurrence of "multispace:" - const char_u *last_lmultispace = NULL; // Last occurrence of "leadmultispace:" + const char *last_multispace = NULL; // Last occurrence of "multispace:" + const char *last_lmultispace = NULL; // Last occurrence of "leadmultispace:" int multispace_len = 0; // Length of lcs-multispace string int lead_multispace_len = 0; // Length of lcs-leadmultispace string const bool is_listchars = (varp == &p_lcs || varp == &wp->w_p_lcs); @@ -898,18 +898,18 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) struct chars_tab *tab; int entries; - const char_u *value = (char_u *)(*varp); + const char *value = *varp; if (is_listchars) { tab = lcs_tab; entries = ARRAY_SIZE(lcs_tab); if (varp == &wp->w_p_lcs && wp->w_p_lcs[0] == NUL) { - value = (char_u *)p_lcs; // local value is empty, use the global value + value = p_lcs; // local value is empty, use the global value } } else { tab = fcs_tab; entries = ARRAY_SIZE(fcs_tab); if (varp == &wp->w_p_fcs && wp->w_p_fcs[0] == NUL) { - value = (char_u *)p_fcs; // local value is empty, use the global value + value = p_fcs; // local value is empty, use the global value } } @@ -944,7 +944,7 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) } } } - const char *p = (char *)value; + const char *p = value; while (*p) { int i; for (i = 0; i < entries; i++) { @@ -999,7 +999,7 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) const char_u *s = (char_u *)p + len + 1; if (round == 0) { // Get length of lcs-multispace string in the first round - last_multispace = (char_u *)p; + last_multispace = p; multispace_len = 0; while (*s != NUL && *s != ',') { int c1 = get_encoded_char_adv(&s); @@ -1017,7 +1017,7 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) int multispace_pos = 0; while (*s != NUL && *s != ',') { int c1 = get_encoded_char_adv(&s); - if (p == (char *)last_multispace) { + if (p == last_multispace) { wp->w_p_lcs_chars.multispace[multispace_pos++] = c1; } } @@ -1030,7 +1030,7 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) const char_u *s = (char_u *)p + len2 + 1; if (round == 0) { // get length of lcs-leadmultispace string in first round - last_lmultispace = (char_u *)p; + last_lmultispace = p; lead_multispace_len = 0; while (*s != NUL && *s != ',') { int c1 = get_encoded_char_adv(&s); @@ -1048,7 +1048,7 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) int multispace_pos = 0; while (*s != NUL && *s != ',') { int c1 = get_encoded_char_adv(&s); - if (p == (char *)last_lmultispace) { + if (p == last_lmultispace) { wp->w_p_lcs_chars.leadmultispace[multispace_pos++] = c1; } } -- cgit From 85111ca0f4916ade5caa4e1ca836d615afdba6f8 Mon Sep 17 00:00:00 2001 From: Luuk van Baal Date: Thu, 12 Jan 2023 10:40:53 +0100 Subject: fix(column)!: ensure 'statuscolumn' works with virtual and wrapped lines Problem: The `'statuscolumn'` was not re-evaluated for wrapped lines, when preceded by virtual/filler lines. There was also no way to distinguish virtual and wrapped lines in the status column. Solution: Make sure to rebuild the statuscolumn, and replace variable `v:wrap` with `v:virtnum`. `v:virtnum` is negative when drawing virtual lines, zero when drawing the actual buffer line, and positive when drawing the wrapped part of a buffer line. --- src/nvim/screen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index b18bf7ed6a..6a3103123b 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -784,7 +784,7 @@ int number_width(win_T *wp) if (*wp->w_p_stc != NUL) { char buf[MAXPATHL]; wp->w_nrwidth_width = 0; - n = build_statuscol_str(wp, true, false, lnum, 0, 0, NUL, buf, NULL, NULL); + n = build_statuscol_str(wp, lnum, 0, 0, NUL, buf, NULL, NULL); n = MAX(n, (wp->w_p_nu || wp->w_p_rnu) * (int)wp->w_p_nuw); wp->w_nrwidth_width = MIN(n, MAX_NUMBERWIDTH); return wp->w_nrwidth_width; -- cgit From 0344bfad0fc87d2e256ea2b80de7abd069ba1dd2 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 17 Jan 2023 14:17:40 +0100 Subject: refactor: replace char_u with char 22 (#21786) Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/screen.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 6a3103123b..0b6b1d9e77 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -815,15 +815,15 @@ int number_width(win_T *wp) /// Calls mb_cptr2char_adv(p) and returns the character. /// If "p" starts with "\x", "\u" or "\U" the hex or unicode value is used. /// Returns 0 for invalid hex or invalid UTF-8 byte. -static int get_encoded_char_adv(const char_u **p) +static int get_encoded_char_adv(const char **p) { - const char *s = (const char *)(*p); + const char *s = *p; if (s[0] == '\\' && (s[1] == 'x' || s[1] == 'u' || s[1] == 'U')) { int64_t num = 0; for (int bytes = s[1] == 'x' ? 1 : s[1] == 'u' ? 2 : 4; bytes > 0; bytes--) { *p += 2; - int n = hexhex2nr((char *)(*p)); + int n = hexhex2nr(*p); if (n < 0) { return 0; } @@ -952,7 +952,7 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) if (strncmp(p, tab[i].name, len) == 0 && p[len] == ':' && p[len + 1] != NUL) { - const char_u *s = (char_u *)p + len + 1; + const char *s = p + len + 1; int c1 = get_encoded_char_adv(&s); if (c1 == 0 || char2cells(c1) > 1) { return e_invarg; @@ -983,7 +983,7 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) *(tab[i].cp) = c1; } } - p = (char *)s; + p = s; break; } } @@ -996,7 +996,7 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) && strncmp(p, "multispace", len) == 0 && p[len] == ':' && p[len + 1] != NUL) { - const char_u *s = (char_u *)p + len + 1; + const char *s = p + len + 1; if (round == 0) { // Get length of lcs-multispace string in the first round last_multispace = p; @@ -1012,7 +1012,7 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) // lcs-multispace cannot be an empty string return e_invarg; } - p = (char *)s; + p = s; } else { int multispace_pos = 0; while (*s != NUL && *s != ',') { @@ -1021,13 +1021,13 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) wp->w_p_lcs_chars.multispace[multispace_pos++] = c1; } } - p = (char *)s; + p = s; } } else if (is_listchars && strncmp(p, "leadmultispace", len2) == 0 && p[len2] == ':' && p[len2 + 1] != NUL) { - const char_u *s = (char_u *)p + len2 + 1; + const char *s = p + len2 + 1; if (round == 0) { // get length of lcs-leadmultispace string in first round last_lmultispace = p; @@ -1043,7 +1043,7 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) // lcs-leadmultispace cannot be an empty string return e_invarg; } - p = (char *)s; + p = s; } else { int multispace_pos = 0; while (*s != NUL && *s != ',') { @@ -1052,7 +1052,7 @@ char *set_chars_option(win_T *wp, char **varp, bool apply) wp->w_p_lcs_chars.leadmultispace[multispace_pos++] = c1; } } - p = (char *)s; + p = s; } } else { return e_invarg; -- cgit From fa12b9ca2b1dd5515910875e04fe36564fbaadcc Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 24 Jan 2023 08:43:51 +0800 Subject: vim-patch:partial:9.0.1237: code is indented more than necessary (#21971) Problem: Code is indented more than necessary. Solution: Use an early return where it makes sense. (Yegappan Lakshmanan, closes vim/vim#11858) https://github.com/vim/vim/commit/6ec66660476562e643deceb7c325cd0e8c903663 Co-authored-by: Yegappan Lakshmanan --- src/nvim/screen.c | 74 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 35 deletions(-) (limited to 'src/nvim/screen.c') diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 0b6b1d9e77..ebff52cd69 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -295,52 +295,54 @@ bool get_keymap_str(win_T *wp, char *fmt, char *buf, int len) return false; } - { - buf_T *old_curbuf = curbuf; - win_T *old_curwin = curwin; - char *s; - - curbuf = wp->w_buffer; - curwin = wp; - STRCPY(buf, "b:keymap_name"); // must be writable - emsg_skip++; - s = p = eval_to_string(buf, NULL, false); - emsg_skip--; - curbuf = old_curbuf; - curwin = old_curwin; - if (p == NULL || *p == NUL) { - if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) { - p = wp->w_buffer->b_p_keymap; - } else { - p = "lang"; - } - } - if (vim_snprintf(buf, (size_t)len, fmt, p) > len - 1) { - buf[0] = NUL; + buf_T *old_curbuf = curbuf; + win_T *old_curwin = curwin; + char *s; + + curbuf = wp->w_buffer; + curwin = wp; + STRCPY(buf, "b:keymap_name"); // must be writable + emsg_skip++; + s = p = eval_to_string(buf, NULL, false); + emsg_skip--; + curbuf = old_curbuf; + curwin = old_curwin; + if (p == NULL || *p == NUL) { + if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) { + p = wp->w_buffer->b_p_keymap; + } else { + p = "lang"; } - xfree(s); } + if (vim_snprintf(buf, (size_t)len, fmt, p) > len - 1) { + buf[0] = NUL; + } + xfree(s); return buf[0] != NUL; } /// Prepare for 'hlsearch' highlighting. void start_search_hl(void) { - if (p_hls && !no_hlsearch) { - end_search_hl(); // just in case it wasn't called before - last_pat_prog(&screen_search_hl.rm); - // Set the time limit to 'redrawtime'. - screen_search_hl.tm = profile_setlimit(p_rdt); + if (!p_hls || no_hlsearch) { + return; } + + end_search_hl(); // just in case it wasn't called before + last_pat_prog(&screen_search_hl.rm); + // Set the time limit to 'redrawtime'. + screen_search_hl.tm = profile_setlimit(p_rdt); } /// Clean up for 'hlsearch' highlighting. void end_search_hl(void) { - if (screen_search_hl.rm.regprog != NULL) { - vim_regfree(screen_search_hl.rm.regprog); - screen_search_hl.rm.regprog = NULL; + if (screen_search_hl.rm.regprog == NULL) { + return; } + + vim_regfree(screen_search_hl.rm.regprog); + screen_search_hl.rm.regprog = NULL; } /// Check if there should be a delay. Used before clearing or redrawing the @@ -671,11 +673,13 @@ void clearmode(void) static void recording_mode(int attr) { msg_puts_attr(_("recording"), attr); - if (!shortmess(SHM_RECORDING)) { - char s[4]; - snprintf(s, ARRAY_SIZE(s), " @%c", reg_recording); - msg_puts_attr(s, attr); + if (shortmess(SHM_RECORDING)) { + return; } + + char s[4]; + snprintf(s, ARRAY_SIZE(s), " @%c", reg_recording); + msg_puts_attr(s, attr); } void get_trans_bufname(buf_T *buf) -- cgit