diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-06-07 20:01:46 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-06-09 21:26:23 +0800 |
commit | d6247a575c12f413e21ff5e7e94a86214246579d (patch) | |
tree | f523118e6d5f262eba282be387ad210978f6fa9a /src/nvim/option.c | |
parent | 3da3cfc864e89a2dca6917183915683373c85af8 (diff) | |
download | rneovim-d6247a575c12f413e21ff5e7e94a86214246579d.tar.gz rneovim-d6247a575c12f413e21ff5e7e94a86214246579d.tar.bz2 rneovim-d6247a575c12f413e21ff5e7e94a86214246579d.zip |
vim-patch:8.2.5066: lcs-leadmultispace
https://github.com/vim/vim/commit/aca12fd89b082dd9cc12ae085a84f1805747bbdf
Diffstat (limited to 'src/nvim/option.c')
-rw-r--r-- | src/nvim/option.c | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index a15c6f4854..b68ee9fd8c 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3552,13 +3552,15 @@ static int get_encoded_char_adv(char_u **p) /// @return error message, NULL if it's OK. static char *set_chars_option(win_T *wp, char_u **varp, bool set) { - int round, i, len, entries; + 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:" - int multispace_len = 0; // Length of lcs-multispace string + char_u *last_multispace = NULL; // Last occurrence of "multispace:" + 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 struct chars_tab { int *cp; ///< char value @@ -3646,6 +3648,17 @@ static char *set_chars_option(win_T *wp, char_u **varp, bool set) } else { wp->w_p_lcs_chars.multispace = NULL; } + + if (wp->w_p_lcs_chars.leadmultispace != NULL) { + xfree(wp->w_p_lcs_chars.leadmultispace); + } + if (lead_multispace_len > 0) { + wp->w_p_lcs_chars.leadmultispace + = xmalloc(((size_t)lead_multispace_len + 1) * sizeof(int)); + wp->w_p_lcs_chars.leadmultispace[lead_multispace_len] = NUL; + } else { + wp->w_p_lcs_chars.leadmultispace = NULL; + } } } p = *varp; @@ -3694,6 +3707,7 @@ static 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) && STRNCMP(p, "multispace", len) == 0 && p[len] == ':' @@ -3725,6 +3739,37 @@ static char *set_chars_option(win_T *wp, char_u **varp, bool set) } p = s; } + } else if ((varp == &p_lcs || varp == &wp->w_p_lcs) + && STRNCMP(p, "leadmultispace", len2) == 0 + && p[len2] == ':' + && p[len2 + 1] != NUL) { + s = p + len2 + 1; + if (round == 0) { + // Get length of lcsmultispace string in first round + last_lmultispace = p; + lead_multispace_len = 0; + while (*s != NUL && *s != ',') { + c1 = get_encoded_char_adv(&s); + if (c1 == 0 || char2cells(c1) > 1) { + return e_invarg; + } + lead_multispace_len++; + } + if (lead_multispace_len == 0) { + // lcsmultispace cannot be an empty string + return e_invarg; + } + p = s; + } else { + int multispace_pos = 0; + while (*s != NUL && *s != ',') { + c1 = get_encoded_char_adv(&s); + if (p == last_lmultispace) { + wp->w_p_lcs_chars.leadmultispace[multispace_pos++] = c1; + } + } + p = s; + } } else { return e_invarg; } |