forked from aniani/vim
patch 9.1.0039: too vague errors for 'listchars'/'fillchars'
Problem: too vague errors for 'listchars'/'fillchars' Solution: Include the field name in error message. (zeertzjq) related: neovim/neovim#27050 closes: #13877 Co-authored-by: Cole Frankenhoff <cole.nhf@gmail.com> Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
4ea37f88e8
commit
6a8d2e1634
74
src/screen.c
74
src/screen.c
@@ -4690,6 +4690,15 @@ static struct charstab lcstab[] =
|
||||
{NULL, "leadmultispace"},
|
||||
};
|
||||
|
||||
static char *
|
||||
field_value_err(char *errbuf, size_t errbuflen, char *fmt, char *field)
|
||||
{
|
||||
if (errbuf == NULL)
|
||||
return "";
|
||||
vim_snprintf(errbuf, errbuflen, _(fmt), field);
|
||||
return errbuf;
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle setting 'listchars' or 'fillchars'.
|
||||
* "value" points to either the global or the window-local value.
|
||||
@@ -4699,7 +4708,8 @@ static struct charstab lcstab[] =
|
||||
* Returns error message, NULL if it's OK.
|
||||
*/
|
||||
static char *
|
||||
set_chars_option(win_T *wp, char_u *value, int is_listchars, int apply)
|
||||
set_chars_option(win_T *wp, char_u *value, int is_listchars, int apply,
|
||||
char *errbuf, size_t errbuflen)
|
||||
{
|
||||
int round, i, len, entries;
|
||||
char_u *p, *s;
|
||||
@@ -4779,9 +4789,7 @@ set_chars_option(win_T *wp, char_u *value, int is_listchars, int apply)
|
||||
for (i = 0; i < entries; ++i)
|
||||
{
|
||||
len = (int)STRLEN(tab[i].name);
|
||||
if (!(STRNCMP(p, tab[i].name, len) == 0
|
||||
&& p[len] == ':'
|
||||
&& p[len + 1] != NUL))
|
||||
if (!(STRNCMP(p, tab[i].name, len) == 0 && p[len] == ':'))
|
||||
continue;
|
||||
|
||||
if (is_listchars && strcmp(tab[i].name, "multispace") == 0)
|
||||
@@ -4796,12 +4804,16 @@ set_chars_option(win_T *wp, char_u *value, int is_listchars, int apply)
|
||||
{
|
||||
c1 = get_encoded_char_adv(&s);
|
||||
if (char2cells(c1) > 1)
|
||||
return e_invalid_argument;
|
||||
return field_value_err(errbuf, errbuflen,
|
||||
e_wrong_character_width_for_field_str,
|
||||
tab[i].name);
|
||||
++multispace_len;
|
||||
}
|
||||
if (multispace_len == 0)
|
||||
// lcs-multispace cannot be an empty string
|
||||
return e_invalid_argument;
|
||||
return field_value_err(errbuf, errbuflen,
|
||||
e_wrong_number_of_characters_for_field_str,
|
||||
tab[i].name);
|
||||
p = s;
|
||||
}
|
||||
else
|
||||
@@ -4832,12 +4844,16 @@ set_chars_option(win_T *wp, char_u *value, int is_listchars, int apply)
|
||||
{
|
||||
c1 = get_encoded_char_adv(&s);
|
||||
if (char2cells(c1) > 1)
|
||||
return e_invalid_argument;
|
||||
return field_value_err(errbuf, errbuflen,
|
||||
e_wrong_character_width_for_field_str,
|
||||
tab[i].name);
|
||||
++lead_multispace_len;
|
||||
}
|
||||
if (lead_multispace_len == 0)
|
||||
// lcs-leadmultispace cannot be an empty string
|
||||
return e_invalid_argument;
|
||||
return field_value_err(errbuf, errbuflen,
|
||||
e_wrong_number_of_characters_for_field_str,
|
||||
tab[i].name);
|
||||
p = s;
|
||||
}
|
||||
else
|
||||
@@ -4857,21 +4873,33 @@ set_chars_option(win_T *wp, char_u *value, int is_listchars, int apply)
|
||||
|
||||
c2 = c3 = 0;
|
||||
s = p + len + 1;
|
||||
if (*s == NUL)
|
||||
return field_value_err(errbuf, errbuflen,
|
||||
e_wrong_number_of_characters_for_field_str,
|
||||
tab[i].name);
|
||||
c1 = get_encoded_char_adv(&s);
|
||||
if (char2cells(c1) > 1)
|
||||
return e_invalid_argument;
|
||||
return field_value_err(errbuf, errbuflen,
|
||||
e_wrong_character_width_for_field_str,
|
||||
tab[i].name);
|
||||
if (tab[i].cp == &lcs_chars.tab2)
|
||||
{
|
||||
if (*s == NUL)
|
||||
return e_invalid_argument;
|
||||
return field_value_err(errbuf, errbuflen,
|
||||
e_wrong_number_of_characters_for_field_str,
|
||||
tab[i].name);
|
||||
c2 = get_encoded_char_adv(&s);
|
||||
if (char2cells(c2) > 1)
|
||||
return e_invalid_argument;
|
||||
return field_value_err(errbuf, errbuflen,
|
||||
e_wrong_character_width_for_field_str,
|
||||
tab[i].name);
|
||||
if (!(*s == ',' || *s == NUL))
|
||||
{
|
||||
c3 = get_encoded_char_adv(&s);
|
||||
if (char2cells(c3) > 1)
|
||||
return e_invalid_argument;
|
||||
return field_value_err(errbuf, errbuflen,
|
||||
e_wrong_character_width_for_field_str,
|
||||
tab[i].name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4892,6 +4920,10 @@ set_chars_option(win_T *wp, char_u *value, int is_listchars, int apply)
|
||||
p = s;
|
||||
break;
|
||||
}
|
||||
else
|
||||
return field_value_err(errbuf, errbuflen,
|
||||
e_wrong_number_of_characters_for_field_str,
|
||||
tab[i].name);
|
||||
}
|
||||
|
||||
if (i == entries)
|
||||
@@ -4923,18 +4955,20 @@ set_chars_option(win_T *wp, char_u *value, int is_listchars, int apply)
|
||||
* Handle the new value of 'fillchars'.
|
||||
*/
|
||||
char *
|
||||
set_fillchars_option(win_T *wp, char_u *val, int apply)
|
||||
set_fillchars_option(win_T *wp, char_u *val, int apply, char *errbuf,
|
||||
size_t errbuflen)
|
||||
{
|
||||
return set_chars_option(wp, val, FALSE, apply);
|
||||
return set_chars_option(wp, val, FALSE, apply, errbuf, errbuflen);
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle the new value of 'listchars'.
|
||||
*/
|
||||
char *
|
||||
set_listchars_option(win_T *wp, char_u *val, int apply)
|
||||
set_listchars_option(win_T *wp, char_u *val, int apply, char *errbuf,
|
||||
size_t errbuflen)
|
||||
{
|
||||
return set_chars_option(wp, val, TRUE, apply);
|
||||
return set_chars_option(wp, val, TRUE, apply, errbuf, errbuflen);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -4974,15 +5008,15 @@ check_chars_options(void)
|
||||
tabpage_T *tp;
|
||||
win_T *wp;
|
||||
|
||||
if (set_listchars_option(curwin, p_lcs, FALSE) != NULL)
|
||||
if (set_listchars_option(curwin, p_lcs, FALSE, NULL, 0) != NULL)
|
||||
return e_conflicts_with_value_of_listchars;
|
||||
if (set_fillchars_option(curwin, p_fcs, FALSE) != NULL)
|
||||
if (set_fillchars_option(curwin, p_fcs, FALSE, NULL, 0) != NULL)
|
||||
return e_conflicts_with_value_of_fillchars;
|
||||
FOR_ALL_TAB_WINDOWS(tp, wp)
|
||||
{
|
||||
if (set_listchars_option(wp, wp->w_p_lcs, FALSE) != NULL)
|
||||
if (set_listchars_option(wp, wp->w_p_lcs, FALSE, NULL, 0) != NULL)
|
||||
return e_conflicts_with_value_of_listchars;
|
||||
if (set_fillchars_option(wp, wp->w_p_fcs, FALSE) != NULL)
|
||||
if (set_fillchars_option(wp, wp->w_p_fcs, FALSE, NULL, 0) != NULL)
|
||||
return e_conflicts_with_value_of_fillchars;
|
||||
}
|
||||
return NULL;
|
||||
|
Reference in New Issue
Block a user