mirror of
https://github.com/vim/vim.git
synced 2025-10-01 04:54:07 -04:00
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.
This commit is contained in:
@@ -5647,9 +5647,9 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
|
|
||||||
// Check that the new value does not conflict with 'fillchars' or
|
// Check that the new value does not conflict with 'fillchars' or
|
||||||
// 'listchars'.
|
// 'listchars'.
|
||||||
if (set_chars_option(curwin, &p_fcs) != NULL)
|
if (set_chars_option(curwin, &p_fcs, FALSE) != NULL)
|
||||||
error = e_conflicts_with_value_of_fillchars;
|
error = e_conflicts_with_value_of_fillchars;
|
||||||
else if (set_chars_option(curwin, &p_lcs) != NULL)
|
else if (set_chars_option(curwin, &p_lcs, FALSE) != NULL)
|
||||||
error = e_conflicts_with_value_of_listchars;
|
error = e_conflicts_with_value_of_listchars;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -5658,12 +5658,12 @@ f_setcellwidths(typval_T *argvars, typval_T *rettv UNUSED)
|
|||||||
|
|
||||||
FOR_ALL_TAB_WINDOWS(tp, wp)
|
FOR_ALL_TAB_WINDOWS(tp, wp)
|
||||||
{
|
{
|
||||||
if (set_chars_option(wp, &wp->w_p_lcs) != NULL)
|
if (set_chars_option(wp, &wp->w_p_lcs, FALSE) != NULL)
|
||||||
{
|
{
|
||||||
error = e_conflicts_with_value_of_listchars;
|
error = e_conflicts_with_value_of_listchars;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (set_chars_option(wp, &wp->w_p_fcs) != NULL)
|
if (set_chars_option(wp, &wp->w_p_fcs, FALSE) != NULL)
|
||||||
{
|
{
|
||||||
error = e_conflicts_with_value_of_fillchars;
|
error = e_conflicts_with_value_of_fillchars;
|
||||||
break;
|
break;
|
||||||
|
12
src/option.c
12
src/option.c
@@ -2433,10 +2433,10 @@ didset_options2(void)
|
|||||||
check_opt_wim();
|
check_opt_wim();
|
||||||
|
|
||||||
// Parse default for 'listchars'.
|
// Parse default for 'listchars'.
|
||||||
(void)set_chars_option(curwin, &curwin->w_p_lcs);
|
(void)set_chars_option(curwin, &curwin->w_p_lcs, TRUE);
|
||||||
|
|
||||||
// Parse default for 'fillchars'.
|
// Parse default for 'fillchars'.
|
||||||
(void)set_chars_option(curwin, &curwin->w_p_fcs);
|
(void)set_chars_option(curwin, &curwin->w_p_fcs, TRUE);
|
||||||
|
|
||||||
#ifdef FEAT_CLIPBOARD
|
#ifdef FEAT_CLIPBOARD
|
||||||
// Parse default for 'clipboard'
|
// Parse default for 'clipboard'
|
||||||
@@ -5204,12 +5204,12 @@ unset_global_local_option(char_u *name, void *from)
|
|||||||
break;
|
break;
|
||||||
case PV_LCS:
|
case PV_LCS:
|
||||||
clear_string_option(&((win_T *)from)->w_p_lcs);
|
clear_string_option(&((win_T *)from)->w_p_lcs);
|
||||||
set_chars_option((win_T *)from, &((win_T *)from)->w_p_lcs);
|
set_chars_option((win_T *)from, &((win_T *)from)->w_p_lcs, TRUE);
|
||||||
redraw_later(NOT_VALID);
|
redraw_later(NOT_VALID);
|
||||||
break;
|
break;
|
||||||
case PV_FCS:
|
case PV_FCS:
|
||||||
clear_string_option(&((win_T *)from)->w_p_fcs);
|
clear_string_option(&((win_T *)from)->w_p_fcs);
|
||||||
set_chars_option((win_T *)from, &((win_T *)from)->w_p_fcs);
|
set_chars_option((win_T *)from, &((win_T *)from)->w_p_fcs, TRUE);
|
||||||
redraw_later(NOT_VALID);
|
redraw_later(NOT_VALID);
|
||||||
break;
|
break;
|
||||||
case PV_VE:
|
case PV_VE:
|
||||||
@@ -5607,8 +5607,8 @@ after_copy_winopt(win_T *wp)
|
|||||||
fill_culopt_flags(NULL, wp);
|
fill_culopt_flags(NULL, wp);
|
||||||
check_colorcolumn(wp);
|
check_colorcolumn(wp);
|
||||||
#endif
|
#endif
|
||||||
set_chars_option(wp, &wp->w_p_lcs);
|
set_chars_option(wp, &wp->w_p_lcs, TRUE);
|
||||||
set_chars_option(wp, &wp->w_p_fcs);
|
set_chars_option(wp, &wp->w_p_fcs, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char_u *
|
static char_u *
|
||||||
|
@@ -866,7 +866,7 @@ did_set_string_option(
|
|||||||
{
|
{
|
||||||
if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
|
if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
|
||||||
errmsg = e_invalid_argument;
|
errmsg = e_invalid_argument;
|
||||||
else if (set_chars_option(curwin, &p_fcs) != NULL)
|
else if (set_chars_option(curwin, &p_fcs, FALSE) != NULL)
|
||||||
errmsg = e_conflicts_with_value_of_fillchars;
|
errmsg = e_conflicts_with_value_of_fillchars;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -875,7 +875,7 @@ did_set_string_option(
|
|||||||
|
|
||||||
FOR_ALL_TAB_WINDOWS(tp, wp)
|
FOR_ALL_TAB_WINDOWS(tp, wp)
|
||||||
{
|
{
|
||||||
if (set_chars_option(wp, &wp->w_p_lcs) != NULL)
|
if (set_chars_option(wp, &wp->w_p_lcs, FALSE) != NULL)
|
||||||
{
|
{
|
||||||
errmsg = e_conflicts_with_value_of_listchars;
|
errmsg = e_conflicts_with_value_of_listchars;
|
||||||
goto ambw_end;
|
goto ambw_end;
|
||||||
@@ -1304,60 +1304,47 @@ ambw_end:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// global 'listchars'
|
// global 'listchars' or 'fillchars'
|
||||||
else if (varp == &p_lcs)
|
else if (varp == &p_lcs || varp == &p_fcs)
|
||||||
{
|
{
|
||||||
errmsg = set_chars_option(curwin, varp);
|
char_u **local_ptr = varp == &p_lcs
|
||||||
|
? &curwin->w_p_lcs : &curwin->w_p_fcs;
|
||||||
|
|
||||||
|
// only apply the global value to "curwin" when it does not have a
|
||||||
|
// local value
|
||||||
|
errmsg = set_chars_option(curwin, varp,
|
||||||
|
**local_ptr == NUL || !(opt_flags & OPT_GLOBAL));
|
||||||
if (errmsg == NULL)
|
if (errmsg == NULL)
|
||||||
{
|
{
|
||||||
tabpage_T *tp;
|
tabpage_T *tp;
|
||||||
win_T *wp;
|
win_T *wp;
|
||||||
|
|
||||||
// If the current window is set to use the global 'listchars'
|
// If the current window is set to use the global
|
||||||
// value, clear the window-local value.
|
// 'listchars'/'fillchars' value, clear the window-local value.
|
||||||
if (!(opt_flags & OPT_GLOBAL))
|
if (!(opt_flags & OPT_GLOBAL))
|
||||||
clear_string_option(&curwin->w_p_lcs);
|
clear_string_option(local_ptr);
|
||||||
FOR_ALL_TAB_WINDOWS(tp, wp)
|
FOR_ALL_TAB_WINDOWS(tp, wp)
|
||||||
|
{
|
||||||
// If the current window has a local value need to apply it
|
// If the current window has a local value need to apply it
|
||||||
// again, it was changed when setting the global value.
|
// again, it was changed when setting the global value.
|
||||||
// If no error was returned above, we don't expect an error
|
// If no error was returned above, we don't expect an error
|
||||||
// here, so ignore the return value.
|
// here, so ignore the return value.
|
||||||
(void)set_chars_option(wp, &wp->w_p_lcs);
|
local_ptr = varp == &p_lcs ? &wp->w_p_lcs : &wp->w_p_fcs;
|
||||||
|
if (**local_ptr == NUL)
|
||||||
|
(void)set_chars_option(wp, local_ptr, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
redraw_all_later(NOT_VALID);
|
redraw_all_later(NOT_VALID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// local 'listchars'
|
// local 'listchars'
|
||||||
else if (varp == &curwin->w_p_lcs)
|
else if (varp == &curwin->w_p_lcs)
|
||||||
errmsg = set_chars_option(curwin, varp);
|
errmsg = set_chars_option(curwin, varp, TRUE);
|
||||||
|
|
||||||
// 'fillchars'
|
|
||||||
else if (varp == &p_fcs)
|
|
||||||
{
|
|
||||||
errmsg = set_chars_option(curwin, varp);
|
|
||||||
if (errmsg == NULL)
|
|
||||||
{
|
|
||||||
tabpage_T *tp;
|
|
||||||
win_T *wp;
|
|
||||||
|
|
||||||
// If the current window is set to use the global 'fillchars'
|
|
||||||
// value clear the window-local value.
|
|
||||||
if (!(opt_flags & OPT_GLOBAL))
|
|
||||||
clear_string_option(&curwin->w_p_fcs);
|
|
||||||
FOR_ALL_TAB_WINDOWS(tp, wp)
|
|
||||||
// If the current window has a local value need to apply it
|
|
||||||
// again, it was changed when setting the global value.
|
|
||||||
// If no error was returned above, we don't expect an error
|
|
||||||
// here, so ignore the return value.
|
|
||||||
(void)set_chars_option(wp, &wp->w_p_fcs);
|
|
||||||
|
|
||||||
redraw_all_later(NOT_VALID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// local 'fillchars'
|
// local 'fillchars'
|
||||||
else if (varp == &curwin->w_p_fcs)
|
else if (varp == &curwin->w_p_fcs)
|
||||||
{
|
{
|
||||||
errmsg = set_chars_option(curwin, varp);
|
errmsg = set_chars_option(curwin, varp, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FEAT_CMDWIN
|
#ifdef FEAT_CMDWIN
|
||||||
|
@@ -55,5 +55,5 @@ void comp_col(void);
|
|||||||
int number_width(win_T *wp);
|
int number_width(win_T *wp);
|
||||||
int screen_screencol(void);
|
int screen_screencol(void);
|
||||||
int screen_screenrow(void);
|
int screen_screenrow(void);
|
||||||
char *set_chars_option(win_T *wp, char_u **varp);
|
char *set_chars_option(win_T *wp, char_u **varp, int apply);
|
||||||
/* vim: set ft=c : */
|
/* vim: set ft=c : */
|
||||||
|
36
src/screen.c
36
src/screen.c
@@ -4843,11 +4843,13 @@ get_encoded_char_adv(char_u **p)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle setting 'listchars' or 'fillchars'.
|
* Handle setting 'listchars' or 'fillchars'.
|
||||||
|
* "varp" points to either the global or the window-local value.
|
||||||
|
* When "apply" is FALSE do not store the flags, only check for errors.
|
||||||
* Assume monocell characters.
|
* Assume monocell characters.
|
||||||
* Returns error message, NULL if it's OK.
|
* Returns error message, NULL if it's OK.
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
set_chars_option(win_T *wp, char_u **varp)
|
set_chars_option(win_T *wp, char_u **varp, int apply)
|
||||||
{
|
{
|
||||||
int round, i, len, len2, entries;
|
int round, i, len, len2, entries;
|
||||||
char_u *p, *s;
|
char_u *p, *s;
|
||||||
@@ -4856,11 +4858,16 @@ set_chars_option(win_T *wp, char_u **varp)
|
|||||||
char_u *last_lmultispace = NULL; // Last occurrence of "leadmultispace:"
|
char_u *last_lmultispace = NULL; // Last occurrence of "leadmultispace:"
|
||||||
int multispace_len = 0; // Length of lcs-multispace string
|
int multispace_len = 0; // Length of lcs-multispace string
|
||||||
int lead_multispace_len = 0; // Length of lcs-leadmultispace string
|
int lead_multispace_len = 0; // Length of lcs-leadmultispace string
|
||||||
|
int is_listchars = (varp == &p_lcs || varp == &wp->w_p_lcs);
|
||||||
|
char_u *value = *varp;
|
||||||
|
|
||||||
struct charstab
|
struct charstab
|
||||||
{
|
{
|
||||||
int *cp;
|
int *cp;
|
||||||
char *name;
|
char *name;
|
||||||
};
|
};
|
||||||
|
struct charstab *tab;
|
||||||
|
|
||||||
static fill_chars_T fill_chars;
|
static fill_chars_T fill_chars;
|
||||||
static struct charstab filltab[] =
|
static struct charstab filltab[] =
|
||||||
{
|
{
|
||||||
@@ -4874,6 +4881,7 @@ set_chars_option(win_T *wp, char_u **varp)
|
|||||||
{&fill_chars.diff, "diff"},
|
{&fill_chars.diff, "diff"},
|
||||||
{&fill_chars.eob, "eob"},
|
{&fill_chars.eob, "eob"},
|
||||||
};
|
};
|
||||||
|
|
||||||
static lcs_chars_T lcs_chars;
|
static lcs_chars_T lcs_chars;
|
||||||
struct charstab lcstab[] =
|
struct charstab lcstab[] =
|
||||||
{
|
{
|
||||||
@@ -4891,22 +4899,21 @@ set_chars_option(win_T *wp, char_u **varp)
|
|||||||
{NULL, "conceal"},
|
{NULL, "conceal"},
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
struct charstab *tab;
|
|
||||||
|
|
||||||
if (varp == &p_lcs || varp == &wp->w_p_lcs)
|
if (is_listchars)
|
||||||
{
|
{
|
||||||
tab = lcstab;
|
tab = lcstab;
|
||||||
CLEAR_FIELD(lcs_chars);
|
CLEAR_FIELD(lcs_chars);
|
||||||
entries = ARRAY_LENGTH(lcstab);
|
entries = ARRAY_LENGTH(lcstab);
|
||||||
if (varp == &wp->w_p_lcs && wp->w_p_lcs[0] == NUL)
|
if (varp == &wp->w_p_lcs && wp->w_p_lcs[0] == NUL)
|
||||||
varp = &p_lcs;
|
value = p_lcs; // local value is empty, us the global value
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tab = filltab;
|
tab = filltab;
|
||||||
entries = ARRAY_LENGTH(filltab);
|
entries = ARRAY_LENGTH(filltab);
|
||||||
if (varp == &wp->w_p_fcs && wp->w_p_fcs[0] == NUL)
|
if (varp == &wp->w_p_fcs && wp->w_p_fcs[0] == NUL)
|
||||||
varp = &p_fcs;
|
value = p_fcs; // local value is empty, us the global value
|
||||||
}
|
}
|
||||||
|
|
||||||
// first round: check for valid value, second round: assign values
|
// first round: check for valid value, second round: assign values
|
||||||
@@ -4915,7 +4922,7 @@ set_chars_option(win_T *wp, char_u **varp)
|
|||||||
if (round > 0)
|
if (round > 0)
|
||||||
{
|
{
|
||||||
// After checking that the value is valid: set defaults.
|
// After checking that the value is valid: set defaults.
|
||||||
if (varp == &p_lcs || varp == &wp->w_p_lcs)
|
if (is_listchars)
|
||||||
{
|
{
|
||||||
for (i = 0; i < entries; ++i)
|
for (i = 0; i < entries; ++i)
|
||||||
if (tab[i].cp != NULL)
|
if (tab[i].cp != NULL)
|
||||||
@@ -4926,6 +4933,7 @@ set_chars_option(win_T *wp, char_u **varp)
|
|||||||
if (multispace_len > 0)
|
if (multispace_len > 0)
|
||||||
{
|
{
|
||||||
lcs_chars.multispace = ALLOC_MULT(int, multispace_len + 1);
|
lcs_chars.multispace = ALLOC_MULT(int, multispace_len + 1);
|
||||||
|
if (lcs_chars.multispace != NULL)
|
||||||
lcs_chars.multispace[multispace_len] = NUL;
|
lcs_chars.multispace[multispace_len] = NUL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -4953,7 +4961,7 @@ set_chars_option(win_T *wp, char_u **varp)
|
|||||||
fill_chars.eob = '~';
|
fill_chars.eob = '~';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p = *varp;
|
p = value;
|
||||||
while (*p)
|
while (*p)
|
||||||
{
|
{
|
||||||
for (i = 0; i < entries; ++i)
|
for (i = 0; i < entries; ++i)
|
||||||
@@ -5007,7 +5015,7 @@ set_chars_option(win_T *wp, char_u **varp)
|
|||||||
{
|
{
|
||||||
len = (int)STRLEN("multispace");
|
len = (int)STRLEN("multispace");
|
||||||
len2 = (int)STRLEN("leadmultispace");
|
len2 = (int)STRLEN("leadmultispace");
|
||||||
if ((varp == &p_lcs || varp == &wp->w_p_lcs)
|
if (is_listchars
|
||||||
&& STRNCMP(p, "multispace", len) == 0
|
&& STRNCMP(p, "multispace", len) == 0
|
||||||
&& p[len] == ':'
|
&& p[len] == ':'
|
||||||
&& p[len + 1] != NUL)
|
&& p[len + 1] != NUL)
|
||||||
@@ -5044,7 +5052,7 @@ set_chars_option(win_T *wp, char_u **varp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if ((varp == &p_lcs || varp == &wp->w_p_lcs)
|
else if (is_listchars
|
||||||
&& STRNCMP(p, "leadmultispace", len2) == 0
|
&& STRNCMP(p, "leadmultispace", len2) == 0
|
||||||
&& p[len2] == ':'
|
&& p[len2] == ':'
|
||||||
&& p[len2 + 1] != NUL)
|
&& p[len2 + 1] != NUL)
|
||||||
@@ -5090,7 +5098,9 @@ set_chars_option(win_T *wp, char_u **varp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tab == lcstab)
|
if (apply)
|
||||||
|
{
|
||||||
|
if (is_listchars)
|
||||||
{
|
{
|
||||||
vim_free(wp->w_lcs_chars.multispace);
|
vim_free(wp->w_lcs_chars.multispace);
|
||||||
vim_free(wp->w_lcs_chars.leadmultispace);
|
vim_free(wp->w_lcs_chars.leadmultispace);
|
||||||
@@ -5100,6 +5110,12 @@ set_chars_option(win_T *wp, char_u **varp)
|
|||||||
{
|
{
|
||||||
wp->w_fill_chars = fill_chars;
|
wp->w_fill_chars = fill_chars;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (is_listchars)
|
||||||
|
{
|
||||||
|
vim_free(lcs_chars.multispace);
|
||||||
|
vim_free(lcs_chars.leadmultispace);
|
||||||
|
}
|
||||||
|
|
||||||
return NULL; // no error
|
return NULL; // no error
|
||||||
}
|
}
|
||||||
|
@@ -735,6 +735,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
40,
|
||||||
/**/
|
/**/
|
||||||
39,
|
39,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user