comparison src/option.c @ 2314:233eb4412f5d vim73

Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
author Bram Moolenaar <bram@vim.org>
date Wed, 14 Jul 2010 19:53:30 +0200
parents ccda151dde4e
children 2b2cd34569eb
comparison
equal deleted inserted replaced
2313:e382b66b936d 2314:233eb4412f5d
230 # define PV_SPELL OPT_WIN(WV_SPELL) 230 # define PV_SPELL OPT_WIN(WV_SPELL)
231 #endif 231 #endif
232 #ifdef FEAT_SYN_HL 232 #ifdef FEAT_SYN_HL
233 # define PV_CUC OPT_WIN(WV_CUC) 233 # define PV_CUC OPT_WIN(WV_CUC)
234 # define PV_CUL OPT_WIN(WV_CUL) 234 # define PV_CUL OPT_WIN(WV_CUL)
235 # define PV_CC OPT_WIN(WV_CC)
235 #endif 236 #endif
236 #ifdef FEAT_STL_OPT 237 #ifdef FEAT_STL_OPT
237 # define PV_STL OPT_BOTH(OPT_WIN(WV_STL)) 238 # define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
238 #endif 239 #endif
239 #ifdef FEAT_WINDOWS 240 #ifdef FEAT_WINDOWS
464 /* The 16 bit MS-DOS version is low on space, make the string as short as 465 /* The 16 bit MS-DOS version is low on space, make the string as short as
465 * possible when compiling with few features. */ 466 * possible when compiling with few features. */
466 #if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \ 467 #if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
467 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \ 468 || defined(FEAT_VERTSPLIT) || defined(FEAT_CLIPBOARD) \
468 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL) 469 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
469 # define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine" 470 # define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn"
470 #else 471 #else
471 # define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill" 472 # define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
472 #endif 473 #endif
473 474
474 /* 475 /*
772 (char_u *)&p_cwh, PV_NONE, 773 (char_u *)&p_cwh, PV_NONE,
773 #else 774 #else
774 (char_u *)NULL, PV_NONE, 775 (char_u *)NULL, PV_NONE,
775 #endif 776 #endif
776 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT}, 777 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
778 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_COMMA|P_NODUP|P_RWIN,
779 #ifdef FEAT_SYN_HL
780 (char_u *)VAR_WIN, PV_CC,
781 #else
782 (char_u *)NULL, PV_NONE,
783 #endif
784 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
777 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR, 785 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
778 (char_u *)&Columns, PV_NONE, 786 (char_u *)&Columns, PV_NONE,
779 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT}, 787 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
780 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP, 788 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_COMMA|P_NODUP,
781 #ifdef FEAT_COMMENTS 789 #ifdef FEAT_COMMENTS
2524 (char_u *)TRUE, 2532 (char_u *)TRUE,
2525 #else 2533 #else
2526 (char_u *)FALSE, 2534 (char_u *)FALSE,
2527 #endif 2535 #endif
2528 (char_u *)0L} SCRIPTID_INIT}, 2536 (char_u *)0L} SCRIPTID_INIT},
2529 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM, 2537 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2530 (char_u *)&p_tw, PV_TW, 2538 (char_u *)&p_tw, PV_TW,
2531 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT}, 2539 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
2532 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP, 2540 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
2533 #ifdef FEAT_INS_EXPAND 2541 #ifdef FEAT_INS_EXPAND
2534 (char_u *)&p_tsr, PV_TSR, 2542 (char_u *)&p_tsr, PV_TSR,
2973 #endif 2981 #endif
2974 static void set_string_option_global __ARGS((int opt_idx, char_u **varp)); 2982 static void set_string_option_global __ARGS((int opt_idx, char_u **varp));
2975 static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags)); 2983 static void set_string_option __ARGS((int opt_idx, char_u *value, int opt_flags));
2976 static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags)); 2984 static char_u *did_set_string_option __ARGS((int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags));
2977 static char_u *set_chars_option __ARGS((char_u **varp)); 2985 static char_u *set_chars_option __ARGS((char_u **varp));
2986 #ifdef FEAT_SYN_HL
2987 static int int_cmp __ARGS((const void *a, const void *b));
2988 #endif
2978 #ifdef FEAT_CLIPBOARD 2989 #ifdef FEAT_CLIPBOARD
2979 static char_u *check_clipboard_option __ARGS((void)); 2990 static char_u *check_clipboard_option __ARGS((void));
2980 #endif 2991 #endif
2981 #ifdef FEAT_SPELL 2992 #ifdef FEAT_SPELL
2982 static char_u *compile_cap_prog __ARGS((synblock_T *synblock)); 2993 static char_u *compile_cap_prog __ARGS((synblock_T *synblock));
5636 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)""); 5647 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5637 didset_vimruntime = FALSE; 5648 didset_vimruntime = FALSE;
5638 } 5649 }
5639 } 5650 }
5640 5651
5652 #ifdef FEAT_SYN_HL
5653 /* 'colorcolumn' */
5654 else if (varp == &curwin->w_p_cc)
5655 errmsg = check_colorcolumn(curwin);
5656 #endif
5657
5641 #ifdef FEAT_MULTI_LANG 5658 #ifdef FEAT_MULTI_LANG
5642 /* 'helplang' */ 5659 /* 'helplang' */
5643 else if (varp == &p_hlg) 5660 else if (varp == &p_hlg)
5644 { 5661 {
5645 /* Check for "", "ab", "ab,cd", etc. */ 5662 /* Check for "", "ab", "ab,cd", etc. */
6909 check_redraw(options[opt_idx].flags); 6926 check_redraw(options[opt_idx].flags);
6910 6927
6911 return errmsg; 6928 return errmsg;
6912 } 6929 }
6913 6930
6931 #ifdef FEAT_SYN_HL
6932 /*
6933 * Simple int comparison function for use with qsort()
6934 */
6935 static int
6936 int_cmp(a, b)
6937 const void *a;
6938 const void *b;
6939 {
6940 return *(const int *)a - *(const int *)b;
6941 }
6942
6943 /*
6944 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
6945 * Returns error message, NULL if it's OK.
6946 */
6947 char_u *
6948 check_colorcolumn(wp)
6949 win_T *wp;
6950 {
6951 char_u *s;
6952 int col;
6953 int count = 0;
6954 int color_cols[256];
6955 int i;
6956 int j = 0;
6957
6958 for (s = wp->w_p_cc; *s != NUL && count < 255; ++s)
6959 {
6960 if (*s == '-' || *s == '+')
6961 {
6962 /* -N and +N: add to 'textwidth' */
6963 col = (*s == '-') ? -1 : 1;
6964 ++s;
6965 if (!VIM_ISDIGIT(*s))
6966 return e_invarg;
6967 col = col * getdigits(&s);
6968 if (wp->w_buffer->b_p_tw == 0)
6969 continue; /* 'textwidth' not set, skip this item */
6970 col += wp->w_buffer->b_p_tw;
6971 if (col < 0)
6972 continue;
6973 }
6974 else if (VIM_ISDIGIT(*s))
6975 col = getdigits(&s);
6976 else
6977 return e_invarg;
6978 color_cols[count++] = col - 1; /* 1-based to 0-based */
6979
6980 if (*s == NUL)
6981 break;
6982 if (*s != ',')
6983 return e_invarg;
6984 }
6985
6986 vim_free(wp->w_p_cc_cols);
6987 if (count == 0)
6988 wp->w_p_cc_cols = NULL;
6989 else
6990 {
6991 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
6992 if (wp->w_p_cc_cols != NULL)
6993 {
6994 /* sort the columns for faster usage on screen redraw inside
6995 * win_line() */
6996 qsort(color_cols, count, sizeof(int), int_cmp);
6997
6998 for (i = 0; i < count; ++i)
6999 /* skip duplicates */
7000 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7001 wp->w_p_cc_cols[j++] = color_cols[i];
7002 wp->w_p_cc_cols[j] = -1; /* end marker */
7003 }
7004 }
7005
7006 return NULL; /* no error */
7007 }
7008 #endif
7009
6914 /* 7010 /*
6915 * Handle setting 'listchars' or 'fillchars'. 7011 * Handle setting 'listchars' or 'fillchars'.
6916 * Returns error message, NULL if it's OK. 7012 * Returns error message, NULL if it's OK.
6917 */ 7013 */
6918 static char_u * 7014 static char_u *
8177 } 8273 }
8178 curwin->w_nrwidth_line_count = 0; 8274 curwin->w_nrwidth_line_count = 0;
8179 } 8275 }
8180 #endif 8276 #endif
8181 8277
8278 else if (pp == &curbuf->b_p_tw)
8279 {
8280 if (curbuf->b_p_tw < 0)
8281 {
8282 errmsg = e_positive;
8283 curbuf->b_p_tw = 0;
8284 }
8285 #ifdef FEAT_SYN_HL
8286 # ifdef FEAT_WINDOWS
8287 {
8288 win_T *wp;
8289 tabpage_T *tp;
8290
8291 FOR_ALL_TAB_WINDOWS(tp, wp)
8292 check_colorcolumn(wp);
8293 }
8294 # else
8295 check_colorcolumn(curwin);
8296 # endif
8297 #endif
8298 }
8299
8182 /* 8300 /*
8183 * Check the bounds for numeric options here 8301 * Check the bounds for numeric options here
8184 */ 8302 */
8185 if (Rows < min_rows() && full_screen) 8303 if (Rows < min_rows() && full_screen)
8186 { 8304 {
8248 } 8366 }
8249 if (curbuf->b_p_ts <= 0) 8367 if (curbuf->b_p_ts <= 0)
8250 { 8368 {
8251 errmsg = e_positive; 8369 errmsg = e_positive;
8252 curbuf->b_p_ts = 8; 8370 curbuf->b_p_ts = 8;
8253 }
8254 if (curbuf->b_p_tw < 0)
8255 {
8256 errmsg = e_positive;
8257 curbuf->b_p_tw = 0;
8258 } 8371 }
8259 if (p_tm < 0) 8372 if (p_tm < 0)
8260 { 8373 {
8261 errmsg = e_positive; 8374 errmsg = e_positive;
8262 p_tm = 0; 8375 p_tm = 0;
9339 case PV_SPELL: return (char_u *)&(curwin->w_p_spell); 9452 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
9340 #endif 9453 #endif
9341 #ifdef FEAT_SYN_HL 9454 #ifdef FEAT_SYN_HL
9342 case PV_CUC: return (char_u *)&(curwin->w_p_cuc); 9455 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
9343 case PV_CUL: return (char_u *)&(curwin->w_p_cul); 9456 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
9457 case PV_CC: return (char_u *)&(curwin->w_p_cc);
9344 #endif 9458 #endif
9345 #ifdef FEAT_DIFF 9459 #ifdef FEAT_DIFF
9346 case PV_DIFF: return (char_u *)&(curwin->w_p_diff); 9460 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
9347 #endif 9461 #endif
9348 #ifdef FEAT_FOLDING 9462 #ifdef FEAT_FOLDING
9580 to->wo_spell = from->wo_spell; 9694 to->wo_spell = from->wo_spell;
9581 #endif 9695 #endif
9582 #ifdef FEAT_SYN_HL 9696 #ifdef FEAT_SYN_HL
9583 to->wo_cuc = from->wo_cuc; 9697 to->wo_cuc = from->wo_cuc;
9584 to->wo_cul = from->wo_cul; 9698 to->wo_cul = from->wo_cul;
9699 to->wo_cc = vim_strsave(from->wo_cc);
9585 #endif 9700 #endif
9586 #ifdef FEAT_DIFF 9701 #ifdef FEAT_DIFF
9587 to->wo_diff = from->wo_diff; 9702 to->wo_diff = from->wo_diff;
9588 #endif 9703 #endif
9589 #ifdef FEAT_FOLDING 9704 #ifdef FEAT_FOLDING
9634 check_string_option(&wop->wo_rlc); 9749 check_string_option(&wop->wo_rlc);
9635 #endif 9750 #endif
9636 #ifdef FEAT_STL_OPT 9751 #ifdef FEAT_STL_OPT
9637 check_string_option(&wop->wo_stl); 9752 check_string_option(&wop->wo_stl);
9638 #endif 9753 #endif
9754 #ifdef FEAT_SYN_HL
9755 check_string_option(&wop->wo_cc);
9756 #endif
9639 } 9757 }
9640 9758
9641 /* 9759 /*
9642 * Free the allocated memory inside a winopt_T. 9760 * Free the allocated memory inside a winopt_T.
9643 */ 9761 */
9657 #ifdef FEAT_RIGHTLEFT 9775 #ifdef FEAT_RIGHTLEFT
9658 clear_string_option(&wop->wo_rlc); 9776 clear_string_option(&wop->wo_rlc);
9659 #endif 9777 #endif
9660 #ifdef FEAT_STL_OPT 9778 #ifdef FEAT_STL_OPT
9661 clear_string_option(&wop->wo_stl); 9779 clear_string_option(&wop->wo_stl);
9780 #endif
9781 #ifdef FEAT_SYN_HL
9782 clear_string_option(&wop->wo_cc);
9662 #endif 9783 #endif
9663 } 9784 }
9664 9785
9665 /* 9786 /*
9666 * Copy global option values to local options for one buffer. 9787 * Copy global option values to local options for one buffer.
9680 char_u *save_p_isk = NULL; /* init for GCC */ 9801 char_u *save_p_isk = NULL; /* init for GCC */
9681 int dont_do_help; 9802 int dont_do_help;
9682 int did_isk = FALSE; 9803 int did_isk = FALSE;
9683 9804
9684 /* 9805 /*
9685 * Don't do anything of the buffer is invalid. 9806 * Don't do anything if the buffer is invalid.
9686 */ 9807 */
9687 if (buf == NULL || !buf_valid(buf)) 9808 if (buf == NULL || !buf_valid(buf))
9688 return; 9809 return;
9689 9810
9690 /* 9811 /*