Mercurial > vim
diff src/window.c @ 17940:079e10a49ea1 v8.1.1966
patch 8.1.1966: some code in options.c fits better elsewhere
Commit: https://github.com/vim/vim/commit/e677df8d93772a705f40a94f3c871aee78fe4d99
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Sep 2 22:31:11 2019 +0200
patch 8.1.1966: some code in options.c fits better elsewhere
Problem: Some code in options.c fits better elsewhere.
Solution: Move functions from options.c to other files. (Yegappan
Lakshmanan, closes #4889)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 02 Sep 2019 22:45:05 +0200 |
parents | 70ed823bdbb6 |
children | cf8e0c7e0cb9 |
line wrap: on
line diff
--- a/src/window.c +++ b/src/window.c @@ -6816,6 +6816,87 @@ frame_check_width(frame_T *topfrp, int w return TRUE; } +#if defined(FEAT_SYN_HL) || defined(PROTO) +/* + * 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". + * Returns error message, NULL if it's OK. + */ + char * +check_colorcolumn(win_T *wp) +{ + char_u *s; + int col; + int count = 0; + int color_cols[256]; + int i; + int j = 0; + + if (wp->w_buffer == NULL) + return NULL; // buffer was closed + + for (s = wp->w_p_cc; *s != NUL && count < 255;) + { + if (*s == '-' || *s == '+') + { + // -N and +N: add to 'textwidth' + col = (*s == '-') ? -1 : 1; + ++s; + if (!VIM_ISDIGIT(*s)) + return e_invarg; + col = col * getdigits(&s); + if (wp->w_buffer->b_p_tw == 0) + goto skip; // 'textwidth' not set, skip this item + col += wp->w_buffer->b_p_tw; + if (col < 0) + goto skip; + } + else if (VIM_ISDIGIT(*s)) + col = getdigits(&s); + 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," + } + + vim_free(wp->w_p_cc_cols); + if (count == 0) + wp->w_p_cc_cols = NULL; + else + { + wp->w_p_cc_cols = ALLOC_MULT(int, count + 1); + if (wp->w_p_cc_cols != NULL) + { + // sort the columns for faster usage on screen redraw inside + // win_line() + qsort(color_cols, count, sizeof(int), int_cmp); + + for (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 +} +#endif + #if defined(FEAT_EVAL) || defined(PROTO) int win_getid(typval_T *argvars)