aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-10-24 06:23:00 +0800
committerzeertzjq <zeertzjq@outlook.com>2024-10-24 06:56:12 +0800
commit5436d9b3c6c537b243ea6af4f1acc143bf94de1c (patch)
treef24f7e4da14be6d40ec609b1e6c1b909a831f18e
parent3d2aca83de7f57ad0ba1c67acb87e55876569d0a (diff)
downloadrneovim-5436d9b3c6c537b243ea6af4f1acc143bf94de1c.tar.gz
rneovim-5436d9b3c6c537b243ea6af4f1acc143bf94de1c.tar.bz2
rneovim-5436d9b3c6c537b243ea6af4f1acc143bf94de1c.zip
vim-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: vim/vim#15914 https://github.com/vim/vim/commit/a441a3eaabbfc14b4772e07ecbecaaff3bd06a58 Co-authored-by: Milly <milly.ca@gmail.com>
-rw-r--r--src/nvim/buffer.c6
-rw-r--r--src/nvim/option.c4
-rw-r--r--src/nvim/optionstr.c3
-rw-r--r--src/nvim/window.c43
-rw-r--r--test/old/testdir/gen_opt_test.vim1
5 files changed, 38 insertions, 19 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index ce47705aa6..2142b5b298 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -255,7 +255,7 @@ int open_buffer(bool read_stdin, exarg_T *eap, int flags_arg)
emsg(_("E83: Cannot allocate buffer, using other one..."));
enter_buffer(curbuf);
if (old_tw != curbuf->b_p_tw) {
- check_colorcolumn(curwin);
+ check_colorcolumn(NULL, curwin);
}
return FAIL;
}
@@ -1029,7 +1029,7 @@ void handle_swap_exists(bufref_T *old_curbuf)
enter_buffer(buf);
if (old_tw != curbuf->b_p_tw) {
- check_colorcolumn(curwin);
+ check_colorcolumn(NULL, curwin);
}
}
// If "old_curbuf" is NULL we are in big trouble here...
@@ -1669,7 +1669,7 @@ void set_curbuf(buf_T *buf, int action, bool update_jumplist)
// enter some buffer. Using the last one is hopefully OK.
enter_buffer(valid ? buf : lastbuf);
if (old_tw != curbuf->b_p_tw) {
- check_colorcolumn(curwin);
+ check_colorcolumn(NULL, curwin);
}
}
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 89753f7cf8..8e6e068e96 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -2592,7 +2592,7 @@ static const char *did_set_swapfile(optset_T *args)
static const char *did_set_textwidth(optset_T *args FUNC_ATTR_UNUSED)
{
FOR_ALL_TAB_WINDOWS(tp, wp) {
- check_colorcolumn(wp);
+ check_colorcolumn(NULL, wp);
}
return NULL;
@@ -5111,7 +5111,7 @@ void didset_window_options(win_T *wp, bool valid_cursor)
} else {
wp->w_skipcol = 0;
}
- check_colorcolumn(wp);
+ check_colorcolumn(NULL, wp);
briopt_check(wp);
fill_culopt_flags(NULL, wp);
set_chars_option(wp, wp->w_p_fcs, kFillchars, true, NULL, 0);
diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c
index f9be1be3d2..0e63a8089d 100644
--- a/src/nvim/optionstr.c
+++ b/src/nvim/optionstr.c
@@ -898,7 +898,8 @@ int expand_set_clipboard(optexpand_T *args, int *numMatches, char ***matches)
const char *did_set_colorcolumn(optset_T *args)
{
win_T *win = (win_T *)args->os_win;
- return check_colorcolumn(win);
+ char **varp = (char **)args->os_varp;
+ return check_colorcolumn(*varp, varp == &win->w_p_cc ? win : NULL);
}
/// The 'comments' option is changed.
diff --git a/src/nvim/window.c b/src/nvim/window.c
index 91a69c3ec4..73d31d3048 100644
--- a/src/nvim/window.c
+++ b/src/nvim/window.c
@@ -7371,18 +7371,37 @@ static int int_cmp(const void *pa, const void *pb)
return a == b ? 0 : a < b ? -1 : 1;
}
-/// 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.
+///
+/// @param cc when NULL: use "wp->w_p_cc"
+/// @param wp when NULL: only parse "cc"
///
/// @return error message, NULL if it's OK.
-const char *check_colorcolumn(win_T *wp)
+const char *check_colorcolumn(char *cc, win_T *wp)
{
- if (wp->w_buffer == NULL) {
+ if (wp != NULL && wp->w_buffer == NULL) {
return NULL; // buffer was closed
}
+ char *s;
+ if (cc != NULL) {
+ s = cc;
+ } else {
+ s = wp->w_p_cc;
+ }
+
+ OptInt tw;
+ if (wp != NULL) {
+ tw = wp->w_buffer->b_p_tw;
+ } else {
+ // buffer-local value not set, assume zero
+ tw = 0;
+ }
+
unsigned count = 0;
int color_cols[256];
- for (char *s = wp->w_p_cc; *s != NUL && count < 255;) {
+ while (*s != NUL && count < 255) {
int col;
if (*s == '-' || *s == '+') {
// -N and +N: add to 'textwidth'
@@ -7392,16 +7411,12 @@ const char *check_colorcolumn(win_T *wp)
return e_invarg;
}
col = col * getdigits_int(&s, true, 0);
- if (wp->w_buffer->b_p_tw == 0) {
+ if (tw == 0) {
goto skip; // 'textwidth' not set, skip this item
}
- assert((col >= 0
- && wp->w_buffer->b_p_tw <= INT_MAX - col
- && wp->w_buffer->b_p_tw + col >= INT_MIN)
- || (col < 0
- && wp->w_buffer->b_p_tw >= INT_MIN - col
- && wp->w_buffer->b_p_tw + col <= INT_MAX));
- col += (int)wp->w_buffer->b_p_tw;
+ assert((col >= 0 && tw <= INT_MAX - col && tw + col >= INT_MIN)
+ || (col < 0 && tw >= INT_MIN - col && tw + col <= INT_MAX));
+ col += (int)tw;
if (col < 0) {
goto skip;
}
@@ -7423,6 +7438,10 @@ skip:
}
}
+ if (wp == NULL) {
+ return NULL; // only parse "cc"
+ }
+
xfree(wp->w_p_cc_cols);
if (count == 0) {
wp->w_p_cc_cols = NULL;
diff --git a/test/old/testdir/gen_opt_test.vim b/test/old/testdir/gen_opt_test.vim
index 8a6d534c62..c28284afdf 100644
--- a/test/old/testdir/gen_opt_test.vim
+++ b/test/old/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',