Skip to content

Commit a441a3e

Browse files
Millychrisbra
authored andcommitted
patch 9.1.0804: tests: no error check when setting global 'cc'
Problem: tests: no error check when setting global 'cc' Solution: also parse and check global 'cc' value (Milly) closes: #15914 Signed-off-by: Milly <milly.ca@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 5e7a6a4 commit a441a3e

7 files changed

Lines changed: 36 additions & 15 deletions

File tree

src/buffer.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ open_buffer(
214214
enter_buffer(curbuf);
215215
#ifdef FEAT_SYN_HL
216216
if (old_tw != curbuf->b_p_tw)
217-
check_colorcolumn(curwin);
217+
check_colorcolumn(NULL, curwin);
218218
#endif
219219
return FAIL;
220220
}
@@ -1213,7 +1213,7 @@ handle_swap_exists(bufref_T *old_curbuf)
12131213

12141214
#ifdef FEAT_SYN_HL
12151215
if (old_tw != curbuf->b_p_tw)
1216-
check_colorcolumn(curwin);
1216+
check_colorcolumn(NULL, curwin);
12171217
#endif
12181218
}
12191219
// If "old_curbuf" is NULL we are in big trouble here...
@@ -1911,7 +1911,7 @@ set_curbuf(buf_T *buf, int action)
19111911
enter_buffer(buf);
19121912
#ifdef FEAT_SYN_HL
19131913
if (old_tw != curbuf->b_p_tw)
1914-
check_colorcolumn(curwin);
1914+
check_colorcolumn(NULL, curwin);
19151915
#endif
19161916
}
19171917
}

src/option.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4328,7 +4328,7 @@ did_set_textwidth(optset_T *args UNUSED)
43284328
tabpage_T *tp;
43294329

43304330
FOR_ALL_TAB_WINDOWS(tp, wp)
4331-
check_colorcolumn(wp);
4331+
check_colorcolumn(NULL, wp);
43324332
}
43334333
#endif
43344334

@@ -6755,7 +6755,7 @@ after_copy_winopt(win_T *wp)
67556755
#endif
67566756
#ifdef FEAT_SYN_HL
67576757
fill_culopt_flags(NULL, wp);
6758-
check_colorcolumn(wp);
6758+
check_colorcolumn(NULL, wp);
67596759
#endif
67606760
set_listchars_option(wp, wp->w_p_lcs, TRUE, NULL, 0);
67616761
set_fillchars_option(wp, wp->w_p_fcs, TRUE, NULL, 0);

src/optionstr.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,9 +1478,11 @@ did_set_cinoptions(optset_T *args UNUSED)
14781478
* The 'colorcolumn' option is changed.
14791479
*/
14801480
char *
1481-
did_set_colorcolumn(optset_T *args UNUSED)
1481+
did_set_colorcolumn(optset_T *args)
14821482
{
1483-
return check_colorcolumn(curwin);
1483+
char_u **varp = (char_u **)args->os_varp;
1484+
1485+
return check_colorcolumn(*varp, varp == &curwin->w_p_cc ? curwin : NULL);
14841486
}
14851487
#endif
14861488

src/proto/window.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void restore_snapshot(int idx, int close_curwin);
9898
int win_hasvertsplit(void);
9999
int get_win_number(win_T *wp, win_T *first_win);
100100
int get_tab_number(tabpage_T *tp);
101-
char *check_colorcolumn(win_T *wp);
101+
char *check_colorcolumn(char_u *cc, win_T *wp);
102102
int get_last_winid(void);
103103
int win_locked(win_T *wp);
104104
/* vim: set ft=c : */

src/testdir/gen_opt_test.vim

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ let skip_setglobal_reasons = #{
4646
\ iminsert: 'The global value is always overwritten by the local value',
4747
\ imsearch: 'The global value is always overwritten by the local value',
4848
\ breakindentopt: 'TODO: fix missing error handling for setglobal',
49-
\ colorcolumn: 'TODO: fix missing error handling for setglobal',
5049
\ conceallevel: 'TODO: fix missing error handling for setglobal',
5150
\ foldcolumn: 'TODO: fix missing error handling for setglobal',
5251
\ numberwidth: 'TODO: fix missing error handling for setglobal',

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
804,
707709
/**/
708710
803,
709711
/**/

src/window.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7925,23 +7925,38 @@ int_cmp(const void *pa, const void *pb)
79257925
}
79267926

79277927
/*
7928-
* Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7928+
* Check "cc" as 'colorcolumn' and update the members of "wp".
7929+
* This is called when 'colorcolumn' or 'textwidth' is changed.
79297930
* Returns error message, NULL if it's OK.
79307931
*/
79317932
char *
7932-
check_colorcolumn(win_T *wp)
7933+
check_colorcolumn(
7934+
char_u *cc, // when NULL: use "wp->w_p_cc"
7935+
win_T *wp) // when NULL: only parse "cc"
79337936
{
79347937
char_u *s;
7938+
int tw;
79357939
int col;
79367940
int count = 0;
79377941
int color_cols[256];
79387942
int i;
79397943
int j = 0;
79407944

7941-
if (wp->w_buffer == NULL)
7945+
if (wp != NULL && wp->w_buffer == NULL)
79427946
return NULL; // buffer was closed
79437947

7944-
for (s = wp->w_p_cc; *s != NUL && count < 255;)
7948+
if (cc != NULL)
7949+
s = cc;
7950+
else
7951+
s = wp->w_p_cc;
7952+
7953+
if (wp != NULL)
7954+
tw = wp->w_buffer->b_p_tw;
7955+
else
7956+
// buffer-local value not set, assume zero
7957+
tw = 0;
7958+
7959+
while (*s != NUL && count < 255)
79457960
{
79467961
if (*s == '-' || *s == '+')
79477962
{
@@ -7951,9 +7966,9 @@ check_colorcolumn(win_T *wp)
79517966
if (!VIM_ISDIGIT(*s))
79527967
return e_invalid_argument;
79537968
col = col * getdigits(&s);
7954-
if (wp->w_buffer->b_p_tw == 0)
7969+
if (tw == 0)
79557970
goto skip; // 'textwidth' not set, skip this item
7956-
col += wp->w_buffer->b_p_tw;
7971+
col += tw;
79577972
if (col < 0)
79587973
goto skip;
79597974
}
@@ -7971,6 +7986,9 @@ check_colorcolumn(win_T *wp)
79717986
return e_invalid_argument; // illegal trailing comma as in "set cc=80,"
79727987
}
79737988

7989+
if (wp == NULL)
7990+
return NULL; // only parse "cc"
7991+
79747992
vim_free(wp->w_p_cc_cols);
79757993
if (count == 0)
79767994
wp->w_p_cc_cols = NULL;

0 commit comments

Comments
 (0)