diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-09-02 22:31:11 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-09-02 22:31:11 +0200 |
commit | e677df8d93772a705f40a94f3c871aee78fe4d99 (patch) | |
tree | 918556233748a58fbdcaf94d0416d6dcd0449b39 /src/window.c | |
parent | 359ad1a6f92d0d3b4b942ea003fb02dc57bbfc9e (diff) | |
download | vim-git-e677df8d93772a705f40a94f3c871aee78fe4d99.tar.gz |
patch 8.1.1966: some code in options.c fits better elsewherev8.1.1966
Problem: Some code in options.c fits better elsewhere.
Solution: Move functions from options.c to other files. (Yegappan
Lakshmanan, closes #4889)
Diffstat (limited to 'src/window.c')
-rw-r--r-- | src/window.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/src/window.c b/src/window.c index 4abceb4d9..edeffcac2 100644 --- a/src/window.c +++ b/src/window.c @@ -6816,6 +6816,87 @@ frame_check_width(frame_T *topfrp, int width) 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) |