diff options
Diffstat (limited to 'src/nvim/option.c')
| -rw-r--r-- | src/nvim/option.c | 163 |
1 files changed, 99 insertions, 64 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index b8f5957c09..b85ec6dbcc 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -50,6 +50,7 @@ #include "nvim/fold.h" #include "nvim/getchar.h" #include "nvim/hardcopy.h" +#include "nvim/highlight.h" #include "nvim/indent_c.h" #include "nvim/mbyte.h" #include "nvim/memfile.h" @@ -65,6 +66,7 @@ #include "nvim/normal.h" #include "nvim/os_unix.h" #include "nvim/path.h" +#include "nvim/popupmnu.h" #include "nvim/regexp.h" #include "nvim/screen.h" #include "nvim/spell.h" @@ -2121,10 +2123,10 @@ static void didset_options2(void) (void)opt_strings_flags(p_cb, p_cb_values, &cb_flags, true); // Parse default for 'fillchars'. - (void)set_chars_option(&p_fcs); + (void)set_chars_option(curwin, &curwin->w_p_fcs); // Parse default for 'listchars'. - (void)set_chars_option(&p_lcs); + (void)set_chars_option(curwin, &curwin->w_p_lcs); // Parse default for 'wildmode'. check_opt_wim(); @@ -2567,10 +2569,19 @@ did_set_string_option ( // 'ambiwidth' if (check_opt_strings(p_ambw, p_ambw_values, false) != OK) { errmsg = e_invarg; - } else if (set_chars_option(&p_lcs) != NULL) { - errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'"); - } else if (set_chars_option(&p_fcs) != NULL) { - errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'"); + } else { + FOR_ALL_TAB_WINDOWS(tp, wp) { + if (set_chars_option(wp, &wp->w_p_lcs) != NULL) { + errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'"); + goto ambw_end; + } + if (set_chars_option(wp, &wp->w_p_fcs) != NULL) { + errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'"); + goto ambw_end; + } + } +ambw_end: + {} // clint prefers {} over ; as an empty statement } } /* 'background' */ @@ -2756,14 +2767,10 @@ did_set_string_option ( } s = skip_to_option_part(s); } - } - /* 'listchars' */ - else if (varp == &p_lcs) { - errmsg = set_chars_option(varp); - } - /* 'fillchars' */ - else if (varp == &p_fcs) { - errmsg = set_chars_option(varp); + } else if (varp == &curwin->w_p_lcs) { // 'listchars' + errmsg = set_chars_option(curwin, varp); + } else if (varp == &curwin->w_p_fcs) { // 'fillchars' + errmsg = set_chars_option(curwin, varp); } /* 'cedit' */ else if (varp == &p_cedit) { @@ -3394,53 +3401,55 @@ skip: /// Handle setting 'listchars' or 'fillchars'. /// Assume monocell characters /// -/// @param varp either &p_lcs ('listchars') or &p_fcs ('fillchar') +/// @param varp either &curwin->w_p_lcs or &curwin->w_p_fcs /// @return error message, NULL if it's OK. -static char_u *set_chars_option(char_u **varp) +static char_u *set_chars_option(win_T *wp, char_u **varp) { int round, i, len, entries; - char_u *p, *s; - int c1, c2 = 0; - struct charstab { + char_u *p, *s; + int c1 = 0, c2 = 0, c3 = 0; + + struct chars_tab { int *cp; ///< char value char *name; ///< char id int def; ///< default value }; - static struct charstab filltab[] = { - { &fill_stl, "stl" , ' ' }, - { &fill_stlnc, "stlnc", ' ' }, - { &fill_vert, "vert" , 9474 }, // │ - { &fill_fold, "fold" , 183 }, // · - { &fill_diff, "diff" , '-' }, - { &fill_msgsep, "msgsep", ' ' }, - { &fill_eob, "eob", '~' }, + struct chars_tab *tab; + + struct chars_tab fcs_tab[] = { + { &wp->w_p_fcs_chars.stl, "stl", ' ' }, + { &wp->w_p_fcs_chars.stlnc, "stlnc", ' ' }, + { &wp->w_p_fcs_chars.vert, "vert", 9474 }, // │ + { &wp->w_p_fcs_chars.fold, "fold", 183 }, // · + { &wp->w_p_fcs_chars.diff, "diff", '-' }, + { &wp->w_p_fcs_chars.msgsep, "msgsep", ' ' }, + { &wp->w_p_fcs_chars.eob, "eob", '~' }, }; - static struct charstab lcstab[] = { - { &lcs_eol, "eol", NUL }, - { &lcs_ext, "extends", NUL }, - { &lcs_nbsp, "nbsp", NUL }, - { &lcs_prec, "precedes", NUL }, - { &lcs_space, "space", NUL }, - { &lcs_tab2, "tab", NUL }, - { &lcs_trail, "trail", NUL }, - { &lcs_conceal, "conceal", NUL }, + struct chars_tab lcs_tab[] = { + { &wp->w_p_lcs_chars.eol, "eol", NUL }, + { &wp->w_p_lcs_chars.ext, "extends", NUL }, + { &wp->w_p_lcs_chars.nbsp, "nbsp", NUL }, + { &wp->w_p_lcs_chars.prec, "precedes", NUL }, + { &wp->w_p_lcs_chars.space, "space", NUL }, + { &wp->w_p_lcs_chars.tab2, "tab", NUL }, + { &wp->w_p_lcs_chars.trail, "trail", NUL }, + { &wp->w_p_lcs_chars.conceal, "conceal", NUL }, }; - struct charstab *tab; - if (varp == &p_lcs) { - tab = lcstab; - entries = ARRAY_SIZE(lcstab); + if (varp == &wp->w_p_lcs) { + tab = lcs_tab; + entries = ARRAY_SIZE(lcs_tab); } else { - tab = filltab; - entries = ARRAY_SIZE(filltab); + tab = fcs_tab; + entries = ARRAY_SIZE(fcs_tab); if (*p_ambw == 'd') { // XXX: If ambiwidth=double then "|" and "·" take 2 columns, which is // forbidden (TUI limitation?). Set old defaults. - filltab[2].def = '|'; - filltab[3].def = '-'; + fcs_tab[2].def = '|'; + fcs_tab[3].def = '-'; } else { - filltab[2].def = 9474; // │ - filltab[3].def = 183; // · + fcs_tab[2].def = 9474; // │ + fcs_tab[3].def = 183; // · } } @@ -3453,8 +3462,9 @@ static char_u *set_chars_option(char_u **varp) *(tab[i].cp) = tab[i].def; } } - if (varp == &p_lcs) { - lcs_tab1 = NUL; + if (varp == &wp->w_p_lcs) { + wp->w_p_lcs_chars.tab1 = NUL; + wp->w_p_lcs_chars.tab3 = NUL; } } p = *varp; @@ -3464,6 +3474,7 @@ static char_u *set_chars_option(char_u **varp) if (STRNCMP(p, tab[i].name, len) == 0 && p[len] == ':' && p[len + 1] != NUL) { + c1 = c2 = c3 = 0; s = p + len + 1; // TODO(bfredl): use schar_T representation and utfc_ptr2len @@ -3472,7 +3483,7 @@ static char_u *set_chars_option(char_u **varp) if (mb_char2cells(c1) > 1 || (c1len == 1 && c1 > 127)) { continue; } - if (tab[i].cp == &lcs_tab2) { + if (tab[i].cp == &wp->w_p_lcs_chars.tab2) { if (*s == NUL) { continue; } @@ -3481,15 +3492,23 @@ static char_u *set_chars_option(char_u **varp) if (mb_char2cells(c2) > 1 || (c2len == 1 && c2 > 127)) { continue; } + if (!(*s == ',' || *s == NUL)) { + int c3len = utf_ptr2len(s); + c3 = mb_cptr2char_adv((const char_u **)&s); + if (mb_char2cells(c3) > 1 || (c3len == 1 && c3 > 127)) { + continue; + } + } } if (*s == ',' || *s == NUL) { if (round) { - if (tab[i].cp == &lcs_tab2) { - lcs_tab1 = c1; - lcs_tab2 = c2; - } else if (tab[i].cp != NULL) + if (tab[i].cp == &wp->w_p_lcs_chars.tab2) { + wp->w_p_lcs_chars.tab1 = c1; + wp->w_p_lcs_chars.tab2 = c2; + wp->w_p_lcs_chars.tab3 = c3; + } else if (tab[i].cp != NULL) { *(tab[i].cp) = c1; - + } } p = s; break; @@ -4149,7 +4168,8 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, errmsg = e_positive; } } else if (pp == &p_ch) { - if (value < 1) { + int minval = ui_has(kUIMessages) ? 0 : 1; + if (value < minval) { errmsg = e_positive; } } else if (pp == &p_tm) { @@ -4223,8 +4243,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, } else if (pp == &curbuf->b_p_channel || pp == &p_channel) { errmsg = e_invarg; } else if (pp == &curbuf->b_p_scbk || pp == &p_scbk) { - if (value < -1 || value > SB_MAX - || (value != -1 && opt_flags == OPT_LOCAL && !curbuf->terminal)) { + if (value < -1 || value > SB_MAX) { errmsg = e_invarg; } } else if (pp == &curbuf->b_p_sw || pp == &p_sw) { @@ -4258,6 +4277,9 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, p_window = Rows - 1; } } else if (pp == &p_ch) { + if (ui_has(kUIMessages)) { + p_ch = 0; + } if (p_ch > Rows - min_rows() + 1) { p_ch = Rows - min_rows() + 1; } @@ -4322,6 +4344,14 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, if (p_uc && !old_value) { ml_open_files(); } + } else if (pp == &p_pb) { + p_pb = MAX(MIN(p_pb, 100), 0); + if (old_value != 0) { + hl_invalidate_blends(); + } + if (pum_drawn()) { + pum_recompose(); + } } else if (pp == &p_pyx) { if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3) { errmsg = e_invarg; @@ -4339,7 +4369,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, } else if (pp == &curbuf->b_p_scbk || pp == &p_scbk) { if (curbuf->terminal) { // Force the scrollback to take effect. - terminal_resize(curbuf->terminal, UINT16_MAX, UINT16_MAX); + terminal_check_size(curbuf->terminal); } } else if (pp == &curwin->w_p_nuw) { curwin->w_nrwidth_line_count = 0; @@ -4418,11 +4448,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp; } - if (pp == &curbuf->b_p_scbk && !curbuf->terminal) { - // Normal buffer: reset local 'scrollback' after updating the global value. - curbuf->b_p_scbk = -1; - } - options[opt_idx].flags |= P_WAS_SET; // Don't do this while starting up, failure or recursively. @@ -5613,6 +5638,8 @@ static char_u *get_varp(vimoption_T *p) case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap); case PV_SCL: return (char_u *)&(curwin->w_p_scl); case PV_WINHL: return (char_u *)&(curwin->w_p_winhl); + case PV_FCS: return (char_u *)&(curwin->w_p_fcs); + case PV_LCS: return (char_u *)&(curwin->w_p_lcs); default: IEMSG(_("E356: get_varp ERROR")); } /* always return a valid pointer to avoid a crash! */ @@ -5691,6 +5718,8 @@ void copy_winopt(winopt_T *from, winopt_T *to) to->wo_fmr = vim_strsave(from->wo_fmr); to->wo_scl = vim_strsave(from->wo_scl); to->wo_winhl = vim_strsave(from->wo_winhl); + to->wo_fcs = vim_strsave(from->wo_fcs); + to->wo_lcs = vim_strsave(from->wo_lcs); check_winopt(to); // don't want NULL pointers } @@ -5721,6 +5750,8 @@ static void check_winopt(winopt_T *wop) check_string_option(&wop->wo_cocu); check_string_option(&wop->wo_briopt); check_string_option(&wop->wo_winhl); + check_string_option(&wop->wo_fcs); + check_string_option(&wop->wo_lcs); } /* @@ -5741,12 +5772,16 @@ void clear_winopt(winopt_T *wop) clear_string_option(&wop->wo_cocu); clear_string_option(&wop->wo_briopt); clear_string_option(&wop->wo_winhl); + clear_string_option(&wop->wo_fcs); + clear_string_option(&wop->wo_lcs); } void didset_window_options(win_T *wp) { check_colorcolumn(wp); briopt_check(wp); + set_chars_option(wp, &wp->w_p_fcs); + set_chars_option(wp, &wp->w_p_lcs); parse_winhl_opt(wp); } @@ -5835,7 +5870,7 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_ai = p_ai; buf->b_p_ai_nopaste = p_ai_nopaste; buf->b_p_sw = p_sw; - buf->b_p_scbk = -1; + buf->b_p_scbk = p_scbk; buf->b_p_tw = p_tw; buf->b_p_tw_nopaste = p_tw_nopaste; buf->b_p_tw_nobin = p_tw_nobin; |
