@@ -4843,11 +4843,13 @@ get_encoded_char_adv(char_u **p)
48434843
48444844/*
48454845 * Handle setting 'listchars' or 'fillchars'.
4846+ * "varp" points to either the global or the window-local value.
4847+ * When "apply" is FALSE do not store the flags, only check for errors.
48464848 * Assume monocell characters.
48474849 * Returns error message, NULL if it's OK.
48484850 */
48494851 char *
4850- set_chars_option (win_T * wp , char_u * * varp )
4852+ set_chars_option (win_T * wp , char_u * * varp , int apply )
48514853{
48524854 int round , i , len , len2 , entries ;
48534855 char_u * p , * s ;
@@ -4856,11 +4858,16 @@ set_chars_option(win_T *wp, char_u **varp)
48564858 char_u * last_lmultispace = NULL ; // Last occurrence of "leadmultispace:"
48574859 int multispace_len = 0 ; // Length of lcs-multispace string
48584860 int lead_multispace_len = 0 ; // Length of lcs-leadmultispace string
4861+ int is_listchars = (varp == & p_lcs || varp == & wp -> w_p_lcs );
4862+ char_u * value = * varp ;
4863+
48594864 struct charstab
48604865 {
48614866 int * cp ;
48624867 char * name ;
48634868 };
4869+ struct charstab * tab ;
4870+
48644871 static fill_chars_T fill_chars ;
48654872 static struct charstab filltab [] =
48664873 {
@@ -4874,6 +4881,7 @@ set_chars_option(win_T *wp, char_u **varp)
48744881 {& fill_chars .diff , "diff" },
48754882 {& fill_chars .eob , "eob" },
48764883 };
4884+
48774885 static lcs_chars_T lcs_chars ;
48784886 struct charstab lcstab [] =
48794887 {
@@ -4891,22 +4899,21 @@ set_chars_option(win_T *wp, char_u **varp)
48914899 {NULL , "conceal" },
48924900#endif
48934901 };
4894- struct charstab * tab ;
48954902
4896- if (varp == & p_lcs || varp == & wp -> w_p_lcs )
4903+ if (is_listchars )
48974904 {
48984905 tab = lcstab ;
48994906 CLEAR_FIELD (lcs_chars );
49004907 entries = ARRAY_LENGTH (lcstab );
49014908 if (varp == & wp -> w_p_lcs && wp -> w_p_lcs [0 ] == NUL )
4902- varp = & p_lcs ;
4909+ value = p_lcs ; // local value is empty, us the global value
49034910 }
49044911 else
49054912 {
49064913 tab = filltab ;
49074914 entries = ARRAY_LENGTH (filltab );
49084915 if (varp == & wp -> w_p_fcs && wp -> w_p_fcs [0 ] == NUL )
4909- varp = & p_fcs ;
4916+ value = p_fcs ; // local value is empty, us the global value
49104917 }
49114918
49124919 // first round: check for valid value, second round: assign values
@@ -4915,7 +4922,7 @@ set_chars_option(win_T *wp, char_u **varp)
49154922 if (round > 0 )
49164923 {
49174924 // After checking that the value is valid: set defaults.
4918- if (varp == & p_lcs || varp == & wp -> w_p_lcs )
4925+ if (is_listchars )
49194926 {
49204927 for (i = 0 ; i < entries ; ++ i )
49214928 if (tab [i ].cp != NULL )
@@ -4926,7 +4933,8 @@ set_chars_option(win_T *wp, char_u **varp)
49264933 if (multispace_len > 0 )
49274934 {
49284935 lcs_chars .multispace = ALLOC_MULT (int , multispace_len + 1 );
4929- lcs_chars .multispace [multispace_len ] = NUL ;
4936+ if (lcs_chars .multispace != NULL )
4937+ lcs_chars .multispace [multispace_len ] = NUL ;
49304938 }
49314939 else
49324940 lcs_chars .multispace = NULL ;
@@ -4953,7 +4961,7 @@ set_chars_option(win_T *wp, char_u **varp)
49534961 fill_chars .eob = '~' ;
49544962 }
49554963 }
4956- p = * varp ;
4964+ p = value ;
49574965 while (* p )
49584966 {
49594967 for (i = 0 ; i < entries ; ++ i )
@@ -5007,7 +5015,7 @@ set_chars_option(win_T *wp, char_u **varp)
50075015 {
50085016 len = (int )STRLEN ("multispace" );
50095017 len2 = (int )STRLEN ("leadmultispace" );
5010- if (( varp == & p_lcs || varp == & wp -> w_p_lcs )
5018+ if (is_listchars
50115019 && STRNCMP (p , "multispace" , len ) == 0
50125020 && p [len ] == ':'
50135021 && p [len + 1 ] != NUL )
@@ -5044,7 +5052,7 @@ set_chars_option(win_T *wp, char_u **varp)
50445052 }
50455053 }
50465054
5047- else if (( varp == & p_lcs || varp == & wp -> w_p_lcs )
5055+ else if (is_listchars
50485056 && STRNCMP (p , "leadmultispace" , len2 ) == 0
50495057 && p [len2 ] == ':'
50505058 && p [len2 + 1 ] != NUL )
@@ -5090,15 +5098,23 @@ set_chars_option(win_T *wp, char_u **varp)
50905098 }
50915099 }
50925100
5093- if (tab == lcstab )
5101+ if (apply )
50945102 {
5095- vim_free (wp -> w_lcs_chars .multispace );
5096- vim_free (wp -> w_lcs_chars .leadmultispace );
5097- wp -> w_lcs_chars = lcs_chars ;
5103+ if (is_listchars )
5104+ {
5105+ vim_free (wp -> w_lcs_chars .multispace );
5106+ vim_free (wp -> w_lcs_chars .leadmultispace );
5107+ wp -> w_lcs_chars = lcs_chars ;
5108+ }
5109+ else
5110+ {
5111+ wp -> w_fill_chars = fill_chars ;
5112+ }
50985113 }
5099- else
5114+ else if ( is_listchars )
51005115 {
5101- wp -> w_fill_chars = fill_chars ;
5116+ vim_free (lcs_chars .multispace );
5117+ vim_free (lcs_chars .leadmultispace );
51025118 }
51035119
51045120 return NULL ; // no error
0 commit comments