mirror of
https://github.com/neovim/neovim.git
synced 2025-09-18 01:08:20 +00:00
vim-patch:8.1.1966: some code in options.c fits better elsewhere (#19840)
Problem: Some code in options.c fits better elsewhere.
Solution: Move functions from options.c to other files. (Yegappan
Lakshmanan, closes vim/vim#4889)
e677df8d93
This commit is contained in:
@@ -7269,6 +7269,88 @@ static bool frame_check_width(const frame_T *topfrp, int width)
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Simple int comparison function for use with qsort()
|
||||
static int int_cmp(const void *a, const void *b)
|
||||
{
|
||||
return *(const int *)a - *(const int *)b;
|
||||
}
|
||||
|
||||
/// Handle setting 'colorcolumn' or 'textwidth' in window "wp".
|
||||
///
|
||||
/// @return error message, NULL if it's OK.
|
||||
char *check_colorcolumn(win_T *wp)
|
||||
{
|
||||
char *s;
|
||||
int col;
|
||||
unsigned int count = 0;
|
||||
int color_cols[256];
|
||||
int j = 0;
|
||||
|
||||
if (wp->w_buffer == NULL) {
|
||||
return NULL; // buffer was closed
|
||||
}
|
||||
|
||||
for (s = (char *)wp->w_p_cc; *s != NUL && count < 255;) {
|
||||
if (*s == '-' || *s == '+') {
|
||||
// -N and +N: add to 'textwidth'
|
||||
col = (*s == '-') ? -1 : 1;
|
||||
s++;
|
||||
if (!ascii_isdigit(*s)) {
|
||||
return e_invarg;
|
||||
}
|
||||
col = col * getdigits_int(&s, true, 0);
|
||||
if (wp->w_buffer->b_p_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;
|
||||
if (col < 0) {
|
||||
goto skip;
|
||||
}
|
||||
} else if (ascii_isdigit(*s)) {
|
||||
col = getdigits_int(&s, true, 0);
|
||||
} else {
|
||||
return e_invarg;
|
||||
}
|
||||
color_cols[count++] = col - 1; // 1-based to 0-based
|
||||
skip:
|
||||
if (*s == NUL) {
|
||||
break;
|
||||
}
|
||||
if (*s != ',') {
|
||||
return e_invarg;
|
||||
}
|
||||
if (*++s == NUL) {
|
||||
return e_invarg; // illegal trailing comma as in "set cc=80,"
|
||||
}
|
||||
}
|
||||
|
||||
xfree(wp->w_p_cc_cols);
|
||||
if (count == 0) {
|
||||
wp->w_p_cc_cols = NULL;
|
||||
} else {
|
||||
wp->w_p_cc_cols = xmalloc(sizeof(int) * (count + 1));
|
||||
// sort the columns for faster usage on screen redraw inside
|
||||
// win_line()
|
||||
qsort(color_cols, count, sizeof(int), int_cmp);
|
||||
|
||||
for (unsigned int i = 0; i < count; i++) {
|
||||
// skip duplicates
|
||||
if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i]) {
|
||||
wp->w_p_cc_cols[j++] = color_cols[i];
|
||||
}
|
||||
}
|
||||
wp->w_p_cc_cols[j] = -1; // end marker
|
||||
}
|
||||
|
||||
return NULL; // no error
|
||||
}
|
||||
|
||||
int win_getid(typval_T *argvars)
|
||||
{
|
||||
if (argvars[0].v_type == VAR_UNKNOWN) {
|
||||
|
Reference in New Issue
Block a user