diff src/screen.c @ 34157:e7d64a3fffe4 v9.1.0039

patch 9.1.0039: too vague errors for 'listchars'/'fillchars' Commit: https://github.com/vim/vim/commit/6a8d2e1634f8f0d7463a2786dbcbe0f38dd287a7 Author: zeertzjq <zeertzjq@outlook.com> Date: Wed Jan 17 20:54:49 2024 +0100 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>
author Christian Brabandt <cb@256bit.org>
date Wed, 17 Jan 2024 21:15:03 +0100
parents 36843e079f64
children 8a91d18f1789
line wrap: on
line diff
--- a/src/screen.c
+++ b/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 *valu
 	    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 *valu
 			{
 			    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 *valu
 			{
 			    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 *valu
 
 		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 *valu
 		    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 *valu
  * 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;