Skip to content

Commit b67f0c8

Browse files
committed
patch 9.0.0040: use of set_chars_option() is confusing
Problem: Use of set_chars_option() is confusing. Solution: Add "apply" argument to store the result or not. Merge similar code.
1 parent 4c99e62 commit b67f0c8

6 files changed

Lines changed: 66 additions & 61 deletions

File tree

src/mbyte.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5647,9 +5647,9 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
56475647

56485648
// Check that the new value does not conflict with 'fillchars' or
56495649
// 'listchars'.
5650-
if (set_chars_option(curwin, &p_fcs) != NULL)
5650+
if (set_chars_option(curwin, &p_fcs, FALSE) != NULL)
56515651
error = e_conflicts_with_value_of_fillchars;
5652-
else if (set_chars_option(curwin, &p_lcs) != NULL)
5652+
else if (set_chars_option(curwin, &p_lcs, FALSE) != NULL)
56535653
error = e_conflicts_with_value_of_listchars;
56545654
else
56555655
{
@@ -5658,12 +5658,12 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
56585658

56595659
FOR_ALL_TAB_WINDOWS(tp, wp)
56605660
{
5661-
if (set_chars_option(wp, &wp->w_p_lcs) != NULL)
5661+
if (set_chars_option(wp, &wp->w_p_lcs, FALSE) != NULL)
56625662
{
56635663
error = e_conflicts_with_value_of_listchars;
56645664
break;
56655665
}
5666-
if (set_chars_option(wp, &wp->w_p_fcs) != NULL)
5666+
if (set_chars_option(wp, &wp->w_p_fcs, FALSE) != NULL)
56675667
{
56685668
error = e_conflicts_with_value_of_fillchars;
56695669
break;

src/option.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,10 +2433,10 @@ didset_options2(void)
24332433
check_opt_wim();
24342434

24352435
// Parse default for 'listchars'.
2436-
(void)set_chars_option(curwin, &curwin->w_p_lcs);
2436+
(void)set_chars_option(curwin, &curwin->w_p_lcs, TRUE);
24372437

24382438
// Parse default for 'fillchars'.
2439-
(void)set_chars_option(curwin, &curwin->w_p_fcs);
2439+
(void)set_chars_option(curwin, &curwin->w_p_fcs, TRUE);
24402440

24412441
#ifdef FEAT_CLIPBOARD
24422442
// Parse default for 'clipboard'
@@ -5204,12 +5204,12 @@ unset_global_local_option(char_u *name, void *from)
52045204
break;
52055205
case PV_LCS:
52065206
clear_string_option(&((win_T *)from)->w_p_lcs);
5207-
set_chars_option((win_T *)from, &((win_T *)from)->w_p_lcs);
5207+
set_chars_option((win_T *)from, &((win_T *)from)->w_p_lcs, TRUE);
52085208
redraw_later(NOT_VALID);
52095209
break;
52105210
case PV_FCS:
52115211
clear_string_option(&((win_T *)from)->w_p_fcs);
5212-
set_chars_option((win_T *)from, &((win_T *)from)->w_p_fcs);
5212+
set_chars_option((win_T *)from, &((win_T *)from)->w_p_fcs, TRUE);
52135213
redraw_later(NOT_VALID);
52145214
break;
52155215
case PV_VE:
@@ -5607,8 +5607,8 @@ after_copy_winopt(win_T *wp)
56075607
fill_culopt_flags(NULL, wp);
56085608
check_colorcolumn(wp);
56095609
#endif
5610-
set_chars_option(wp, &wp->w_p_lcs);
5611-
set_chars_option(wp, &wp->w_p_fcs);
5610+
set_chars_option(wp, &wp->w_p_lcs, TRUE);
5611+
set_chars_option(wp, &wp->w_p_fcs, TRUE);
56125612
}
56135613

56145614
static char_u *

src/optionstr.c

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ did_set_string_option(
866866
{
867867
if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
868868
errmsg = e_invalid_argument;
869-
else if (set_chars_option(curwin, &p_fcs) != NULL)
869+
else if (set_chars_option(curwin, &p_fcs, FALSE) != NULL)
870870
errmsg = e_conflicts_with_value_of_fillchars;
871871
else
872872
{
@@ -875,7 +875,7 @@ did_set_string_option(
875875

876876
FOR_ALL_TAB_WINDOWS(tp, wp)
877877
{
878-
if (set_chars_option(wp, &wp->w_p_lcs) != NULL)
878+
if (set_chars_option(wp, &wp->w_p_lcs, FALSE) != NULL)
879879
{
880880
errmsg = e_conflicts_with_value_of_listchars;
881881
goto ambw_end;
@@ -1304,60 +1304,47 @@ did_set_string_option(
13041304
}
13051305
}
13061306

1307-
// global 'listchars'
1308-
else if (varp == &p_lcs)
1307+
// global 'listchars' or 'fillchars'
1308+
else if (varp == &p_lcs || varp == &p_fcs)
13091309
{
1310-
errmsg = set_chars_option(curwin, varp);
1310+
char_u **local_ptr = varp == &p_lcs
1311+
? &curwin->w_p_lcs : &curwin->w_p_fcs;
1312+
1313+
// only apply the global value to "curwin" when it does not have a
1314+
// local value
1315+
errmsg = set_chars_option(curwin, varp,
1316+
**local_ptr == NUL || !(opt_flags & OPT_GLOBAL));
13111317
if (errmsg == NULL)
13121318
{
13131319
tabpage_T *tp;
13141320
win_T *wp;
13151321

1316-
// If the current window is set to use the global 'listchars'
1317-
// value, clear the window-local value.
1322+
// If the current window is set to use the global
1323+
// 'listchars'/'fillchars' value, clear the window-local value.
13181324
if (!(opt_flags & OPT_GLOBAL))
1319-
clear_string_option(&curwin->w_p_lcs);
1325+
clear_string_option(local_ptr);
13201326
FOR_ALL_TAB_WINDOWS(tp, wp)
1327+
{
13211328
// If the current window has a local value need to apply it
13221329
// again, it was changed when setting the global value.
13231330
// If no error was returned above, we don't expect an error
13241331
// here, so ignore the return value.
1325-
(void)set_chars_option(wp, &wp->w_p_lcs);
1332+
local_ptr = varp == &p_lcs ? &wp->w_p_lcs : &wp->w_p_fcs;
1333+
if (**local_ptr == NUL)
1334+
(void)set_chars_option(wp, local_ptr, TRUE);
1335+
}
13261336

13271337
redraw_all_later(NOT_VALID);
13281338
}
13291339
}
13301340
// local 'listchars'
13311341
else if (varp == &curwin->w_p_lcs)
1332-
errmsg = set_chars_option(curwin, varp);
1333-
1334-
// 'fillchars'
1335-
else if (varp == &p_fcs)
1336-
{
1337-
errmsg = set_chars_option(curwin, varp);
1338-
if (errmsg == NULL)
1339-
{
1340-
tabpage_T *tp;
1341-
win_T *wp;
1342+
errmsg = set_chars_option(curwin, varp, TRUE);
13421343

1343-
// If the current window is set to use the global 'fillchars'
1344-
// value clear the window-local value.
1345-
if (!(opt_flags & OPT_GLOBAL))
1346-
clear_string_option(&curwin->w_p_fcs);
1347-
FOR_ALL_TAB_WINDOWS(tp, wp)
1348-
// If the current window has a local value need to apply it
1349-
// again, it was changed when setting the global value.
1350-
// If no error was returned above, we don't expect an error
1351-
// here, so ignore the return value.
1352-
(void)set_chars_option(wp, &wp->w_p_fcs);
1353-
1354-
redraw_all_later(NOT_VALID);
1355-
}
1356-
}
13571344
// local 'fillchars'
13581345
else if (varp == &curwin->w_p_fcs)
13591346
{
1360-
errmsg = set_chars_option(curwin, varp);
1347+
errmsg = set_chars_option(curwin, varp, TRUE);
13611348
}
13621349

13631350
#ifdef FEAT_CMDWIN

src/proto/screen.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ void comp_col(void);
5555
int number_width(win_T *wp);
5656
int screen_screencol(void);
5757
int screen_screenrow(void);
58-
char *set_chars_option(win_T *wp, char_u **varp);
58+
char *set_chars_option(win_T *wp, char_u **varp, int apply);
5959
/* vim: set ft=c : */

src/screen.c

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ static char *(features[]) =
735735

736736
static int included_patches[] =
737737
{ /* Add new patch number below this line */
738+
/**/
739+
40,
738740
/**/
739741
39,
740742
/**/

0 commit comments

Comments
 (0)