patch 9.1.0804: tests: no error check when setting global 'cc'

Commit: 
https://github.com/vim/vim/commit/a441a3eaabbfc14b4772e07ecbecaaff3bd06a58
Author: Milly <milly...@gmail.com>
Date:   Tue Oct 22 22:43:01 2024 +0200

    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...@gmail.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/buffer.c b/src/buffer.c
index 90be301e8..5359527c2 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -214,7 +214,7 @@ open_buffer(
        enter_buffer(curbuf);
 #ifdef FEAT_SYN_HL
        if (old_tw != curbuf->b_p_tw)
-           check_colorcolumn(curwin);
+           check_colorcolumn(NULL, curwin);
 #endif
        return FAIL;
     }
@@ -1213,7 +1213,7 @@ handle_swap_exists(bufref_T *old_curbuf)
 
 #ifdef FEAT_SYN_HL
            if (old_tw != curbuf->b_p_tw)
-               check_colorcolumn(curwin);
+               check_colorcolumn(NULL, curwin);
 #endif
        }
        // If "old_curbuf" is NULL we are in big trouble here...
@@ -1911,7 +1911,7 @@ set_curbuf(buf_T *buf, int action)
            enter_buffer(buf);
 #ifdef FEAT_SYN_HL
        if (old_tw != curbuf->b_p_tw)
-           check_colorcolumn(curwin);
+           check_colorcolumn(NULL, curwin);
 #endif
     }
 }
diff --git a/src/option.c b/src/option.c
index a108c521a..a55288a9e 100644
--- a/src/option.c
+++ b/src/option.c
@@ -4328,7 +4328,7 @@ did_set_textwidth(optset_T *args UNUSED)
        tabpage_T       *tp;
 
        FOR_ALL_TAB_WINDOWS(tp, wp)
-           check_colorcolumn(wp);
+           check_colorcolumn(NULL, wp);
     }
 #endif
 
@@ -6755,7 +6755,7 @@ after_copy_winopt(win_T *wp)
 #endif
 #ifdef FEAT_SYN_HL
     fill_culopt_flags(NULL, wp);
-    check_colorcolumn(wp);
+    check_colorcolumn(NULL, wp);
 #endif
     set_listchars_option(wp, wp->w_p_lcs, TRUE, NULL, 0);
     set_fillchars_option(wp, wp->w_p_fcs, TRUE, NULL, 0);
diff --git a/src/optionstr.c b/src/optionstr.c
index 2049633f8..17947460b 100644
--- a/src/optionstr.c
+++ b/src/optionstr.c
@@ -1478,9 +1478,11 @@ did_set_cinoptions(optset_T *args UNUSED)
  * The 'colorcolumn' option is changed.
  */
     char *
-did_set_colorcolumn(optset_T *args UNUSED)
+did_set_colorcolumn(optset_T *args)
 {
-    return check_colorcolumn(curwin);
+    char_u     **varp = (char_u **)args->os_varp;
+
+    return check_colorcolumn(*varp, varp == &curwin->w_p_cc ? curwin : NULL);
 }
 #endif
 
diff --git a/src/proto/window.pro b/src/proto/window.pro
index 441070ebf..4ab710310 100644
--- a/src/proto/window.pro
+++ b/src/proto/window.pro
@@ -98,7 +98,7 @@ void restore_snapshot(int idx, int close_curwin);
 int win_hasvertsplit(void);
 int get_win_number(win_T *wp, win_T *first_win);
 int get_tab_number(tabpage_T *tp);
-char *check_colorcolumn(win_T *wp);
+char *check_colorcolumn(char_u *cc, win_T *wp);
 int get_last_winid(void);
 int win_locked(win_T *wp);
 /* vim: set ft=c : */
diff --git a/src/testdir/gen_opt_test.vim b/src/testdir/gen_opt_test.vim
index 120ea9b18..7e89e7342 100644
--- a/src/testdir/gen_opt_test.vim
+++ b/src/testdir/gen_opt_test.vim
@@ -46,7 +46,6 @@ let skip_setglobal_reasons = #{
       \ iminsert: 'The global value is always overwritten by the local value',
       \ imsearch: 'The global value is always overwritten by the local value',
       \ breakindentopt:        'TODO: fix missing error handling for 
setglobal',
-      \ colorcolumn:   'TODO: fix missing error handling for setglobal',
       \ conceallevel:  'TODO: fix missing error handling for setglobal',
       \ foldcolumn:    'TODO: fix missing error handling for setglobal',
       \ numberwidth:   'TODO: fix missing error handling for setglobal',
diff --git a/src/version.c b/src/version.c
index b26e848c0..59260d1e3 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    804,
 /**/
     803,
 /**/
diff --git a/src/window.c b/src/window.c
index db907f8a4..5a8dc2e9e 100644
--- a/src/window.c
+++ b/src/window.c
@@ -7925,23 +7925,38 @@ int_cmp(const void *pa, const void *pb)
 }
 
 /*
- * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
+ * Check "cc" as 'colorcolumn' and update the members of "wp".
+ * This is called when 'colorcolumn' or 'textwidth' is changed.
  * Returns error message, NULL if it's OK.
  */
     char *
-check_colorcolumn(win_T *wp)
+check_colorcolumn(
+    char_u *cc,                // when NULL: use "wp->w_p_cc"
+    win_T *wp)         // when NULL: only parse "cc"
 {
     char_u     *s;
+    int                tw;
     int                col;
     int                count = 0;
     int                color_cols[256];
     int                i;
     int                j = 0;
 
-    if (wp->w_buffer == NULL)
+    if (wp != NULL && wp->w_buffer == NULL)
        return NULL;  // buffer was closed
 
-    for (s = wp->w_p_cc; *s != NUL && count < 255;)
+    if (cc != NULL)
+       s = cc;
+    else
+       s = wp->w_p_cc;
+
+    if (wp != NULL)
+       tw = wp->w_buffer->b_p_tw;
+    else
+       // buffer-local value not set, assume zero
+       tw = 0;
+
+    while (*s != NUL && count < 255)
     {
        if (*s == '-' || *s == '+')
        {
@@ -7951,9 +7966,9 @@ check_colorcolumn(win_T *wp)
            if (!VIM_ISDIGIT(*s))
                return e_invalid_argument;
            col = col * getdigits(&s);
-           if (wp->w_buffer->b_p_tw == 0)
+           if (tw == 0)
                goto skip;  // 'textwidth' not set, skip this item
-           col += wp->w_buffer->b_p_tw;
+           col += tw;
            if (col < 0)
                goto skip;
        }
@@ -7971,6 +7986,9 @@ skip:
            return e_invalid_argument;  // illegal trailing comma as in "set 
cc=80,"
     }
 
+    if (wp == NULL)
+       return NULL;  // only parse "cc"
+
     vim_free(wp->w_p_cc_cols);
     if (count == 0)
        wp->w_p_cc_cols = NULL;

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1t3Lz2-000R1P-3Q%40256bit.org.

Raspunde prin e-mail lui