vim-patch:9.0.1961: 'listchars' completion misses "multispace" and "leadmultispace"

Problem:  Cmdline completion for 'listchars' fields doesn't include
          "multispace" and "leadmultispace" (after 9.0.1958).
Solution: Include "multispace" and "leadmultispace" in lcstab.

closes: vim/vim#13225

1f025b01e2
This commit is contained in:
zeertzjq 2023-10-01 18:20:20 +08:00
parent 6a7d533444
commit 81be840768
2 changed files with 67 additions and 65 deletions

View File

@ -2931,6 +2931,8 @@ static const struct chars_tab lcs_tab[] = {
{ &lcs_chars.lead, "lead", NUL, NUL },
{ &lcs_chars.trail, "trail", NUL, NUL },
{ &lcs_chars.conceal, "conceal", NUL, NUL },
{ NULL, "multispace", NUL, NUL },
{ NULL, "leadmultispace", NUL, NUL },
};
/// Handle setting 'listchars' or 'fillchars'.
@ -3001,9 +3003,74 @@ static const char *set_chars_option(win_T *wp, const char *value, const bool is_
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) {
&& p[len + 1] != NUL)) {
continue;
}
if (is_listchars && strcmp(tab[i].name, "multispace") == 0) {
const char *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 != ',') {
int c1 = get_encoded_char_adv(&s);
if (c1 == 0 || char2cells(c1) > 1) {
return e_invarg;
}
multispace_len++;
}
if (multispace_len == 0) {
// lcs-multispace cannot be an empty string
return e_invarg;
}
p = s;
} else {
int multispace_pos = 0;
while (*s != NUL && *s != ',') {
int c1 = get_encoded_char_adv(&s);
if (p == last_multispace) {
lcs_chars.multispace[multispace_pos++] = c1;
}
}
p = s;
}
break;
}
if (is_listchars && strcmp(tab[i].name, "leadmultispace") == 0) {
const char *s = p + len + 1;
if (round == 0) {
// get length of lcs-leadmultispace string in first round
last_lmultispace = p;
lead_multispace_len = 0;
while (*s != NUL && *s != ',') {
int c1 = get_encoded_char_adv(&s);
if (c1 == 0 || char2cells(c1) > 1) {
return e_invarg;
}
lead_multispace_len++;
}
if (lead_multispace_len == 0) {
// lcs-leadmultispace cannot be an empty string
return e_invarg;
}
p = s;
} else {
int multispace_pos = 0;
while (*s != NUL && *s != ',') {
int c1 = get_encoded_char_adv(&s);
if (p == last_lmultispace) {
lcs_chars.leadmultispace[multispace_pos++] = c1;
}
}
p = s;
}
break;
}
const char *s = p + len + 1;
int c1 = get_encoded_char_adv(&s);
if (c1 == 0 || char2cells(c1) > 1) {
@ -3040,77 +3107,10 @@ static const char *set_chars_option(win_T *wp, const char *value, const bool is_
break;
}
}
}
if (i == entries) {
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) {
const char *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 != ',') {
int c1 = get_encoded_char_adv(&s);
if (c1 == 0 || char2cells(c1) > 1) {
return e_invarg;
}
multispace_len++;
}
if (multispace_len == 0) {
// lcs-multispace cannot be an empty string
return e_invarg;
}
p = s;
} else {
int multispace_pos = 0;
while (*s != NUL && *s != ',') {
int c1 = get_encoded_char_adv(&s);
if (p == last_multispace) {
lcs_chars.multispace[multispace_pos++] = c1;
}
}
p = s;
}
} else if (is_listchars
&& strncmp(p, "leadmultispace", len2) == 0
&& p[len2] == ':'
&& p[len2 + 1] != NUL) {
const char *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 != ',') {
int c1 = get_encoded_char_adv(&s);
if (c1 == 0 || char2cells(c1) > 1) {
return e_invarg;
}
lead_multispace_len++;
}
if (lead_multispace_len == 0) {
// lcs-leadmultispace cannot be an empty string
return e_invarg;
}
p = s;
} else {
int multispace_pos = 0;
while (*s != NUL && *s != ',') {
int c1 = get_encoded_char_adv(&s);
if (p == last_lmultispace) {
lcs_chars.leadmultispace[multispace_pos++] = c1;
}
}
p = s;
}
} else {
return e_invarg;
}
}
if (*p == ',') {
p++;

View File

@ -527,10 +527,12 @@ func Test_set_completion_string_values()
" call assert_equal(getcompletion('set printoptions=', 'cmdline')[0], 'top')
" call assert_equal(getcompletion('set wincolor=', 'cmdline')[0], 'SpecialKey')
call assert_equal(getcompletion('set listchars+=', 'cmdline')[0], 'eol')
call assert_equal(getcompletion('setl listchars+=', 'cmdline')[0], 'eol')
call assert_equal(getcompletion('set fillchars+=', 'cmdline')[0], 'stl')
call assert_equal(getcompletion('setl fillchars+=', 'cmdline')[0], 'stl')
call assert_equal('eol', getcompletion('set listchars+=', 'cmdline')[0])
call assert_equal(['multispace', 'leadmultispace'], getcompletion('set listchars+=', 'cmdline')[-2:])
call assert_equal('eol', getcompletion('setl listchars+=', 'cmdline')[0])
call assert_equal(['multispace', 'leadmultispace'], getcompletion('setl listchars+=', 'cmdline')[-2:])
call assert_equal('stl', getcompletion('set fillchars+=', 'cmdline')[0])
call assert_equal('stl', getcompletion('setl fillchars+=', 'cmdline')[0])
"
" Unique string options below