From e47622f26b40d88bb8582c391df30474a64a082c Mon Sep 17 00:00:00 2001 From: Jakob Schnitzer Date: Sun, 26 Mar 2017 13:20:44 +0200 Subject: options: setlocal should only set local value For 'iminsert' and 'imsearch' the global value was always changed. --- src/nvim/option.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 0bf81b4d3a..f622efeb0b 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4120,7 +4120,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, errmsg = e_invarg; curbuf->b_p_iminsert = B_IMODE_NONE; } - p_iminsert = curbuf->b_p_iminsert; showmode(); /* Show/unshow value of 'keymap' in status lines. */ status_redraw_curbuf(); @@ -4134,7 +4133,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, errmsg = e_invarg; curbuf->b_p_imsearch = B_IMODE_NONE; } - p_imsearch = curbuf->b_p_imsearch; } /* if 'titlelen' has changed, redraw the title */ else if (pp == &p_titlelen) { -- cgit From 79d3e9494299ae91f297c5a06dc3fd4f2f71f13e Mon Sep 17 00:00:00 2001 From: Jakob Schnitzer Date: Mon, 27 Mar 2017 18:52:16 +0200 Subject: options: move code around in set_num_option handle side-effects after validation --- src/nvim/option.c | 175 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 101 insertions(+), 74 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index f622efeb0b..248b5205ec 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4004,9 +4004,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, curbuf->b_p_sw = curbuf->b_p_ts; } - /* - * Number options that need some action when changed - */ + // Number options that need some validation when changed. if (pp == &p_wh || pp == &p_hh) { if (p_wh < 1) { errmsg = e_positive; @@ -4020,14 +4018,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, errmsg = e_positive; p_hh = 0; } - - /* Change window height NOW */ - if (lastwin != firstwin) { - if (pp == &p_wh && curwin->w_height < p_wh) - win_setheight((int)p_wh); - if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh) - win_setheight((int)p_hh); - } } /* 'winminheight' */ else if (pp == &p_wmh) { @@ -4039,7 +4029,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, errmsg = e_winheight; p_wmh = p_wh; } - win_setminheight(); } else if (pp == &p_wiw) { if (p_wiw < 1) { errmsg = e_positive; @@ -4049,10 +4038,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, errmsg = e_winwidth; p_wiw = p_wmw; } - - /* Change window width NOW */ - if (lastwin != firstwin && curwin->w_width < p_wiw) - win_setwidth((int)p_wiw); } /* 'winminwidth' */ else if (pp == &p_wmw) { @@ -4064,29 +4049,11 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, errmsg = e_winwidth; p_wmw = p_wiw; } - win_setminheight(); - } else if (pp == &p_ls) { - /* (re)set last window status line */ - last_status(false); - } - /* (re)set tab page line */ - else if (pp == &p_stal) { - shell_new_rows(); /* recompute window positions and heights */ } /* 'foldlevel' */ else if (pp == &curwin->w_p_fdl) { if (curwin->w_p_fdl < 0) curwin->w_p_fdl = 0; - newFoldLevel(); - } - /* 'foldminlines' */ - else if (pp == &curwin->w_p_fml) { - foldUpdateAll(curwin); - } - /* 'foldnestmax' */ - else if (pp == &curwin->w_p_fdn) { - if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) - foldUpdateAll(curwin); } /* 'foldcolumn' */ else if (pp == &curwin->w_p_fdc) { @@ -4097,16 +4064,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, errmsg = e_invarg; curwin->w_p_fdc = 12; } - // 'shiftwidth' or 'tabstop' - } else if (pp == &curbuf->b_p_sw || pp == (long *)&curbuf->b_p_ts) { - if (foldmethodIsIndent(curwin)) { - foldUpdateAll(curwin); - } - // When 'shiftwidth' changes, or it's zero and 'tabstop' changes: - // parse 'cinoptions'. - if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0) { - parse_cino(curbuf); - } } /* 'maxcombine' */ else if (pp == &p_mco) { @@ -4114,15 +4071,11 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, p_mco = MAX_MCO; else if (p_mco < 0) p_mco = 0; - screenclear(); /* will re-allocate the screen */ } else if (pp == &curbuf->b_p_iminsert) { if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST) { errmsg = e_invarg; curbuf->b_p_iminsert = B_IMODE_NONE; } - showmode(); - /* Show/unshow value of 'keymap' in status lines. */ - status_redraw_curbuf(); } else if (pp == &p_window) { if (p_window < 1) p_window = 1; @@ -4140,8 +4093,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, errmsg = e_positive; p_titlelen = 85; } - if (starting != NO_SCREEN && old_value != p_titlelen) - need_maketitle = TRUE; } /* if p_ch changed value, change the command line height */ else if (pp == &p_ch) { @@ -4151,12 +4102,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, } if (p_ch > Rows - min_rows() + 1) p_ch = Rows - min_rows() + 1; - - /* Only compute the new window layout when startup has been - * completed. Otherwise the frame sizes may be wrong. */ - if (p_ch != old_value && full_screen - ) - command_height(); } /* when 'updatecount' changes from zero to non-zero, open swap files */ else if (pp == &p_uc) { @@ -4164,8 +4109,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, errmsg = e_positive; p_uc = 100; } - if (p_uc && !old_value) - ml_open_files(); } else if (pp == &curwin->w_p_cole) { if (curwin->w_p_cole < 0) { errmsg = e_positive; @@ -4175,18 +4118,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, curwin->w_p_cole = 3; } } - /* sync undo before 'undolevels' changes */ - else if (pp == &p_ul) { - /* use the old value, otherwise u_sync() may not work properly */ - p_ul = old_value; - u_sync(TRUE); - p_ul = value; - } else if (pp == &curbuf->b_p_ul) { - /* use the old value, otherwise u_sync() may not work properly */ - curbuf->b_p_ul = old_value; - u_sync(TRUE); - curbuf->b_p_ul = value; - } /* 'numberwidth' must be positive */ else if (pp == &curwin->w_p_nuw) { if (curwin->w_p_nuw < 1) { @@ -4203,10 +4134,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, errmsg = e_positive; curbuf->b_p_tw = 0; } - - FOR_ALL_TAB_WINDOWS(tp, wp) { - check_colorcolumn(wp); - } } else if (pp == &curbuf->b_p_scbk || pp == &p_scbk) { // 'scrollback' if (*pp < -1 || *pp > SB_MAX @@ -4219,6 +4146,106 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, } } + // Number options that need some action when changed + if (pp == &p_wh || pp == &p_hh) { + /* Change window height NOW */ + if (lastwin != firstwin) { + if (pp == &p_wh && curwin->w_height < p_wh) + win_setheight((int)p_wh); + if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh) + win_setheight((int)p_hh); + } + } + else if (pp == &p_wmh) { + win_setminheight(); + } else if (pp == &p_wiw) { + /* Change window width NOW */ + if (lastwin != firstwin && curwin->w_width < p_wiw) + win_setwidth((int)p_wiw); + } + else if (pp == &p_wmw) { + win_setminheight(); + } else if (pp == &p_ls) { + /* (re)set last window status line */ + last_status(false); + } + /* (re)set tab page line */ + else if (pp == &p_stal) { + shell_new_rows(); /* recompute window positions and heights */ + } + else if (pp == &curwin->w_p_fdl) { + newFoldLevel(); + } + /* 'foldminlines' */ + else if (pp == &curwin->w_p_fml) { + foldUpdateAll(curwin); + } + /* 'foldnestmax' */ + else if (pp == &curwin->w_p_fdn) { + if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) + foldUpdateAll(curwin); + // 'shiftwidth' or 'tabstop' + } else if (pp == &curbuf->b_p_sw || pp == (long *)&curbuf->b_p_ts) { + if (foldmethodIsIndent(curwin)) { + foldUpdateAll(curwin); + } + // When 'shiftwidth' changes, or it's zero and 'tabstop' changes: + // parse 'cinoptions'. + if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0) { + parse_cino(curbuf); + } + } + /* 'maxcombine' */ + else if (pp == &p_mco) { + screenclear(); /* will re-allocate the screen */ + } else if (pp == &curbuf->b_p_iminsert) { + showmode(); + /* Show/unshow value of 'keymap' in status lines. */ + status_redraw_curbuf(); + } + /* if 'titlelen' has changed, redraw the title */ + else if (pp == &p_titlelen) { + if (starting != NO_SCREEN && old_value != p_titlelen) + need_maketitle = TRUE; + } + /* if p_ch changed value, change the command line height */ + else if (pp == &p_ch) { + + /* Only compute the new window layout when startup has been + * completed. Otherwise the frame sizes may be wrong. */ + if (p_ch != old_value && full_screen + ) + command_height(); + } + /* when 'updatecount' changes from zero to non-zero, open swap files */ + else if (pp == &p_uc) { + if (p_uc && !old_value) + ml_open_files(); + } + /* sync undo before 'undolevels' changes */ + else if (pp == &p_ul) { + /* use the old value, otherwise u_sync() may not work properly */ + p_ul = old_value; + u_sync(TRUE); + p_ul = value; + } else if (pp == &curbuf->b_p_ul) { + /* use the old value, otherwise u_sync() may not work properly */ + curbuf->b_p_ul = old_value; + u_sync(TRUE); + curbuf->b_p_ul = value; + } else if (pp == &curbuf->b_p_tw) { + FOR_ALL_TAB_WINDOWS(tp, wp) { + check_colorcolumn(wp); + } + } + 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); + } + } + + /* * Check the bounds for numeric options here */ -- cgit From f4920fb485da92d546c1e01f5f10766d00c3791d Mon Sep 17 00:00:00 2001 From: Jakob Schnitzer Date: Mon, 27 Mar 2017 19:03:46 +0200 Subject: options: if invalid value is given, reset to old value --- src/nvim/option.c | 112 ++++++++++++++++++++---------------------------------- 1 file changed, 42 insertions(+), 70 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 248b5205ec..d069cceb39 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4005,144 +4005,114 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, } // Number options that need some validation when changed. - if (pp == &p_wh || pp == &p_hh) { + if (pp == &p_wh) { if (p_wh < 1) { errmsg = e_positive; - p_wh = 1; } if (p_wmh > p_wh) { errmsg = e_winheight; - p_wh = p_wmh; } + } else if (pp == &p_hh) { if (p_hh < 0) { errmsg = e_positive; - p_hh = 0; } - } - /* 'winminheight' */ - else if (pp == &p_wmh) { + } else if (pp == &p_wmh) { if (p_wmh < 0) { errmsg = e_positive; - p_wmh = 0; } if (p_wmh > p_wh) { errmsg = e_winheight; - p_wmh = p_wh; } } else if (pp == &p_wiw) { if (p_wiw < 1) { errmsg = e_positive; - p_wiw = 1; } if (p_wmw > p_wiw) { errmsg = e_winwidth; - p_wiw = p_wmw; } - } - /* 'winminwidth' */ - else if (pp == &p_wmw) { + } else if (pp == &p_wmw) { if (p_wmw < 0) { errmsg = e_positive; - p_wmw = 0; } if (p_wmw > p_wiw) { errmsg = e_winwidth; - p_wmw = p_wiw; } - } - /* 'foldlevel' */ - else if (pp == &curwin->w_p_fdl) { - if (curwin->w_p_fdl < 0) - curwin->w_p_fdl = 0; - } - /* 'foldcolumn' */ - else if (pp == &curwin->w_p_fdc) { + } else if (pp == &curwin->w_p_fdl) { + if (curwin->w_p_fdl < 0) { + errmsg = e_positive; + } + } else if (pp == &curwin->w_p_fdc) { if (curwin->w_p_fdc < 0) { errmsg = e_positive; - curwin->w_p_fdc = 0; } else if (curwin->w_p_fdc > 12) { errmsg = e_invarg; - curwin->w_p_fdc = 12; } - } - /* 'maxcombine' */ - else if (pp == &p_mco) { - if (p_mco > MAX_MCO) - p_mco = MAX_MCO; - else if (p_mco < 0) - p_mco = 0; + } else if (pp == &p_mco) { + if (p_mco > MAX_MCO) { + errmsg = e_invarg; + } else if (p_mco < 0) { + errmsg = e_positive; + } } else if (pp == &curbuf->b_p_iminsert) { if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST) { errmsg = e_invarg; - curbuf->b_p_iminsert = B_IMODE_NONE; } - } else if (pp == &p_window) { - if (p_window < 1) - p_window = 1; - else if (p_window >= Rows) - p_window = Rows - 1; } else if (pp == &curbuf->b_p_imsearch) { if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST) { errmsg = e_invarg; - curbuf->b_p_imsearch = B_IMODE_NONE; } - } - /* if 'titlelen' has changed, redraw the title */ - else if (pp == &p_titlelen) { + } else if (pp == &p_titlelen) { if (p_titlelen < 0) { errmsg = e_positive; - p_titlelen = 85; - } - } - /* if p_ch changed value, change the command line height */ - else if (pp == &p_ch) { - if (p_ch < 1) { - errmsg = e_positive; - p_ch = 1; } - if (p_ch > Rows - min_rows() + 1) - p_ch = Rows - min_rows() + 1; - } - /* when 'updatecount' changes from zero to non-zero, open swap files */ - else if (pp == &p_uc) { + } else if (pp == &p_uc) { if (p_uc < 0) { errmsg = e_positive; - p_uc = 100; } } else if (pp == &curwin->w_p_cole) { if (curwin->w_p_cole < 0) { errmsg = e_positive; - curwin->w_p_cole = 0; } else if (curwin->w_p_cole > 3) { errmsg = e_invarg; - curwin->w_p_cole = 3; } - } - /* 'numberwidth' must be positive */ - else if (pp == &curwin->w_p_nuw) { + } else if (pp == &curwin->w_p_nuw) { if (curwin->w_p_nuw < 1) { errmsg = e_positive; - curwin->w_p_nuw = 1; } if (curwin->w_p_nuw > 10) { errmsg = e_invarg; - curwin->w_p_nuw = 10; } curwin->w_nrwidth_line_count = 0; } else if (pp == &curbuf->b_p_tw) { if (curbuf->b_p_tw < 0) { errmsg = e_positive; - curbuf->b_p_tw = 0; } } else if (pp == &curbuf->b_p_scbk || pp == &p_scbk) { - // 'scrollback' if (*pp < -1 || *pp > SB_MAX || (opt_flags == OPT_LOCAL && !curbuf->terminal)) { errmsg = e_invarg; - *pp = old_value; - } else if (curbuf->terminal) { - // Force the scrollback to take effect. - terminal_resize(curbuf->terminal, UINT16_MAX, UINT16_MAX); + } + } else if (pp == &p_ch) { + if (p_ch < 1) { + errmsg = e_positive; + } + } + + if (errmsg != NULL) { + *pp = old_value; + return errmsg; + } + + // For these options we want to fix some invalid values. + if (pp == &p_window) { + if (p_window < 1) { + p_window = 1; + } else if (p_window >= Rows) { + p_window = Rows - 1; + } + } else if (pp == &p_ch) { + if (p_ch > Rows - min_rows() + 1) { + p_ch = Rows - min_rows() + 1; } } @@ -4243,6 +4213,8 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, // Force the scrollback to take effect. terminal_resize(curbuf->terminal, UINT16_MAX, UINT16_MAX); } + } else if (pp == &curwin->w_p_nuw) { + curwin->w_nrwidth_line_count = 0; } -- cgit From 1a56a032fe6060c3b4c8532c209ccfaa90fdf74e Mon Sep 17 00:00:00 2001 From: Jakob Schnitzer Date: Mon, 27 Mar 2017 19:17:58 +0200 Subject: options: clean up num_options side-effects --- src/nvim/option.c | 118 +++++++++++++++++++++++------------------------------- 1 file changed, 50 insertions(+), 68 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index d069cceb39..f6639d4f6a 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3999,11 +3999,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, /* Remember where the option was set. */ set_option_scriptID_idx(opt_idx, opt_flags, current_SID); - if (curbuf->b_p_sw < 0) { - errmsg = e_positive; - curbuf->b_p_sw = curbuf->b_p_ts; - } - // Number options that need some validation when changed. if (pp == &p_wh) { if (p_wh < 1) { @@ -4091,13 +4086,18 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, if (*pp < -1 || *pp > SB_MAX || (opt_flags == OPT_LOCAL && !curbuf->terminal)) { errmsg = e_invarg; - } + } + } else if (pp == &curbuf->b_p_sw) { + if (curbuf->b_p_sw < 0) { + errmsg = e_positive; + } } else if (pp == &p_ch) { if (p_ch < 1) { errmsg = e_positive; } } + // If validation failed, reset to old value and return. if (errmsg != NULL) { *pp = old_value; return errmsg; @@ -4117,45 +4117,38 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, } // Number options that need some action when changed - if (pp == &p_wh || pp == &p_hh) { - /* Change window height NOW */ - if (lastwin != firstwin) { - if (pp == &p_wh && curwin->w_height < p_wh) - win_setheight((int)p_wh); - if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh) - win_setheight((int)p_hh); + if (pp == &p_wh) { + if (lastwin != firstwin && curwin->w_height < p_wh) { + win_setheight((int)p_wh); } - } - else if (pp == &p_wmh) { + } else if (pp == &p_hh) { + if (lastwin != firstwin && curbuf->b_help && curwin->w_height < p_hh) { + win_setheight((int)p_hh); + } + } else if (pp == &p_wmh) { win_setminheight(); } else if (pp == &p_wiw) { - /* Change window width NOW */ - if (lastwin != firstwin && curwin->w_width < p_wiw) + if (lastwin != firstwin && curwin->w_width < p_wiw) { win_setwidth((int)p_wiw); - } - else if (pp == &p_wmw) { + } + } else if (pp == &p_wmw) { win_setminheight(); } else if (pp == &p_ls) { - /* (re)set last window status line */ + // (re)set last window status line. last_status(false); - } - /* (re)set tab page line */ - else if (pp == &p_stal) { - shell_new_rows(); /* recompute window positions and heights */ - } - else if (pp == &curwin->w_p_fdl) { + } else if (pp == &p_stal) { + // (re)set tab page line + shell_new_rows(); // recompute window positions and heights + } else if (pp == &curwin->w_p_fdl) { newFoldLevel(); - } - /* 'foldminlines' */ - else if (pp == &curwin->w_p_fml) { + } else if (pp == &curwin->w_p_fml) { foldUpdateAll(curwin); - } - /* 'foldnestmax' */ - else if (pp == &curwin->w_p_fdn) { - if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) + } else if (pp == &curwin->w_p_fdn) { + if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) { foldUpdateAll(curwin); - // 'shiftwidth' or 'tabstop' + } } else if (pp == &curbuf->b_p_sw || pp == (long *)&curbuf->b_p_ts) { + // 'shiftwidth' or 'tabstop' if (foldmethodIsIndent(curwin)) { foldUpdateAll(curwin); } @@ -4164,51 +4157,40 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0) { parse_cino(curbuf); } - } - /* 'maxcombine' */ - else if (pp == &p_mco) { - screenclear(); /* will re-allocate the screen */ + } else if (pp == &p_mco) { + screenclear(); // will re-allocate the screen } else if (pp == &curbuf->b_p_iminsert) { showmode(); - /* Show/unshow value of 'keymap' in status lines. */ + // Show/unshow value of 'keymap' in status lines. status_redraw_curbuf(); - } - /* if 'titlelen' has changed, redraw the title */ - else if (pp == &p_titlelen) { - if (starting != NO_SCREEN && old_value != p_titlelen) + } else if (pp == &p_titlelen) { + // if 'titlelen' has changed, redraw the title + if (starting != NO_SCREEN && old_value != p_titlelen) { need_maketitle = TRUE; - } - /* if p_ch changed value, change the command line height */ - else if (pp == &p_ch) { - - /* Only compute the new window layout when startup has been - * completed. Otherwise the frame sizes may be wrong. */ - if (p_ch != old_value && full_screen - ) + } + } else if (pp == &p_ch) { + // if p_ch changed value, change the command line height + // Only compute the new window layout when startup has been + // completed. Otherwise the frame sizes may be wrong. + if (p_ch != old_value && full_screen) { command_height(); - } - /* when 'updatecount' changes from zero to non-zero, open swap files */ - else if (pp == &p_uc) { - if (p_uc && !old_value) + } + } else if (pp == &p_uc) { + // when 'updatecount' changes from zero to non-zero, open swap files + if (p_uc && !old_value) { ml_open_files(); - } - /* sync undo before 'undolevels' changes */ - else if (pp == &p_ul) { - /* use the old value, otherwise u_sync() may not work properly */ - p_ul = old_value; - u_sync(TRUE); - p_ul = value; - } else if (pp == &curbuf->b_p_ul) { - /* use the old value, otherwise u_sync() may not work properly */ - curbuf->b_p_ul = old_value; + } + } else if (pp == &p_ul || pp == &curbuf->b_p_ul) { + // sync undo before 'undolevels' changes + // use the old value, otherwise u_sync() may not work properly + *pp = old_value; u_sync(TRUE); - curbuf->b_p_ul = value; + *pp = value; } else if (pp == &curbuf->b_p_tw) { FOR_ALL_TAB_WINDOWS(tp, wp) { check_colorcolumn(wp); } - } - else if (pp == &curbuf->b_p_scbk || pp == &p_scbk) { + } 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); -- cgit From 0273f96ef69d2a70a9c2e77b7f5da3a811bca460 Mon Sep 17 00:00:00 2001 From: Jakob Schnitzer Date: Mon, 27 Mar 2017 19:26:41 +0200 Subject: options: move more validation together --- src/nvim/option.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index f6639d4f6a..65457dec9f 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4095,6 +4095,14 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, if (p_ch < 1) { errmsg = e_positive; } + } else if (pp == &curbuf->b_p_ts) { + if (curbuf->b_p_ts <= 0) { + errmsg = e_positive; + } + } else if (pp == &p_tm) { + if (p_tm < 0) { + errmsg = e_positive; + } } // If validation failed, reset to old value and return. @@ -4246,14 +4254,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, } } - if (curbuf->b_p_ts <= 0) { - errmsg = e_positive; - curbuf->b_p_ts = 8; - } - if (p_tm < 0) { - errmsg = e_positive; - p_tm = 0; - } if ((curwin->w_p_scr <= 0 || (curwin->w_p_scr > curwin->w_height && curwin->w_height > 0)) -- cgit From 2b0abdbd9adcdaee5fb4f8d056c6385749c45579 Mon Sep 17 00:00:00 2001 From: Jakob Schnitzer Date: Mon, 27 Mar 2017 19:29:51 +0200 Subject: options: more of the same --- src/nvim/option.c | 69 +++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 35 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 65457dec9f..24c9b9b72e 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4103,6 +4103,40 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, if (p_tm < 0) { errmsg = e_positive; } + } else if (pp == &p_hi) { + if (p_hi < 0) { + errmsg = e_positive; + } else if (p_hi > 10000) { + errmsg = e_invarg; + } + } else if (pp == &p_re) { + if (p_re < 0 || p_re > 2) { + errmsg = e_invarg; + } + } else if (pp == &p_report) { + if (p_report < 0) { + errmsg = e_positive; + } + } else if (pp == &p_so) { + if (p_so < 0 && full_screen) { + errmsg = e_scroll; + } + } else if (pp == &p_siso) { + if (p_siso < 0 && full_screen) { + errmsg = e_positive; + } + } else if (pp == &p_cwh) { + if (p_cwh < 1) { + errmsg = e_positive; + } + } else if (pp == &p_ut) { + if (p_ut < 0) { + errmsg = e_positive; + } + } else if (pp == &p_ss) { + if (p_ss < 0) { + errmsg = e_positive; + } } // If validation failed, reset to old value and return. @@ -4270,21 +4304,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, else /* curwin->w_p_scr > curwin->w_height */ curwin->w_p_scr = curwin->w_height; } - if (p_hi < 0) { - errmsg = e_positive; - p_hi = 0; - } else if (p_hi > 10000) { - errmsg = e_invarg; - p_hi = 10000; - } - if (p_re < 0 || p_re > 2) { - errmsg = e_invarg; - p_re = 0; - } - if (p_report < 0) { - errmsg = e_positive; - p_report = 1; - } if ((p_sj < -100 || p_sj >= Rows) && full_screen) { if (Rows != old_Rows) /* Rows changed, just adjust p_sj */ p_sj = Rows / 2; @@ -4293,26 +4312,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, p_sj = 1; } } - if (p_so < 0 && full_screen) { - errmsg = e_scroll; - p_so = 0; - } - if (p_siso < 0 && full_screen) { - errmsg = e_positive; - p_siso = 0; - } - if (p_cwh < 1) { - errmsg = e_positive; - p_cwh = 1; - } - if (p_ut < 0) { - errmsg = e_positive; - p_ut = 2000; - } - if (p_ss < 0) { - errmsg = e_positive; - p_ss = 0; - } /* May set global value for local option. */ if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) -- cgit From 2290a7a1b1f8ea3c04365667b751fdfff62b43f5 Mon Sep 17 00:00:00 2001 From: Jakob Schnitzer Date: Mon, 27 Mar 2017 19:37:39 +0200 Subject: options: group num_option validation by type --- src/nvim/option.c | 96 +++++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 49 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 24c9b9b72e..976aadbc9c 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4032,30 +4032,12 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, if (p_wmw > p_wiw) { errmsg = e_winwidth; } - } else if (pp == &curwin->w_p_fdl) { - if (curwin->w_p_fdl < 0) { - errmsg = e_positive; - } - } else if (pp == &curwin->w_p_fdc) { - if (curwin->w_p_fdc < 0) { - errmsg = e_positive; - } else if (curwin->w_p_fdc > 12) { - errmsg = e_invarg; - } } else if (pp == &p_mco) { if (p_mco > MAX_MCO) { errmsg = e_invarg; } else if (p_mco < 0) { errmsg = e_positive; } - } else if (pp == &curbuf->b_p_iminsert) { - if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST) { - errmsg = e_invarg; - } - } else if (pp == &curbuf->b_p_imsearch) { - if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST) { - errmsg = e_invarg; - } } else if (pp == &p_titlelen) { if (p_titlelen < 0) { errmsg = e_positive; @@ -4064,41 +4046,10 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, if (p_uc < 0) { errmsg = e_positive; } - } else if (pp == &curwin->w_p_cole) { - if (curwin->w_p_cole < 0) { - errmsg = e_positive; - } else if (curwin->w_p_cole > 3) { - errmsg = e_invarg; - } - } else if (pp == &curwin->w_p_nuw) { - if (curwin->w_p_nuw < 1) { - errmsg = e_positive; - } - if (curwin->w_p_nuw > 10) { - errmsg = e_invarg; - } - curwin->w_nrwidth_line_count = 0; - } else if (pp == &curbuf->b_p_tw) { - if (curbuf->b_p_tw < 0) { - errmsg = e_positive; - } - } else if (pp == &curbuf->b_p_scbk || pp == &p_scbk) { - if (*pp < -1 || *pp > SB_MAX - || (opt_flags == OPT_LOCAL && !curbuf->terminal)) { - errmsg = e_invarg; - } - } else if (pp == &curbuf->b_p_sw) { - if (curbuf->b_p_sw < 0) { - errmsg = e_positive; - } } else if (pp == &p_ch) { if (p_ch < 1) { errmsg = e_positive; } - } else if (pp == &curbuf->b_p_ts) { - if (curbuf->b_p_ts <= 0) { - errmsg = e_positive; - } } else if (pp == &p_tm) { if (p_tm < 0) { errmsg = e_positive; @@ -4137,6 +4088,53 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, if (p_ss < 0) { errmsg = e_positive; } + } else if (pp == &curwin->w_p_fdl) { + if (curwin->w_p_fdl < 0) { + errmsg = e_positive; + } + } else if (pp == &curwin->w_p_fdc) { + if (curwin->w_p_fdc < 0) { + errmsg = e_positive; + } else if (curwin->w_p_fdc > 12) { + errmsg = e_invarg; + } + } else if (pp == &curwin->w_p_cole) { + if (curwin->w_p_cole < 0) { + errmsg = e_positive; + } else if (curwin->w_p_cole > 3) { + errmsg = e_invarg; + } + } else if (pp == &curwin->w_p_nuw) { + if (curwin->w_p_nuw < 1) { + errmsg = e_positive; + } else if (curwin->w_p_nuw > 10) { + errmsg = e_invarg; + } + } else if (pp == &curbuf->b_p_iminsert) { + if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST) { + errmsg = e_invarg; + } + } else if (pp == &curbuf->b_p_imsearch) { + if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST) { + errmsg = e_invarg; + } + } else if (pp == &curbuf->b_p_tw) { + if (curbuf->b_p_tw < 0) { + errmsg = e_positive; + } + } else if (pp == &curbuf->b_p_scbk || pp == &p_scbk) { + if (*pp < -1 || *pp > SB_MAX + || (opt_flags == OPT_LOCAL && !curbuf->terminal)) { + errmsg = e_invarg; + } + } else if (pp == &curbuf->b_p_sw) { + if (curbuf->b_p_sw < 0) { + errmsg = e_positive; + } + } else if (pp == &curbuf->b_p_ts) { + if (curbuf->b_p_ts <= 0) { + errmsg = e_positive; + } } // If validation failed, reset to old value and return. -- cgit From 44f039a1c8bf1a3111825f2d3385730e31536d9a Mon Sep 17 00:00:00 2001 From: Jakob Schnitzer Date: Mon, 27 Mar 2017 19:50:04 +0200 Subject: options: fix setglobal for buf-local number options --- src/nvim/option.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 976aadbc9c..637591d7ca 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4014,22 +4014,19 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, } else if (pp == &p_wmh) { if (p_wmh < 0) { errmsg = e_positive; - } - if (p_wmh > p_wh) { + } else if (p_wmh > p_wh) { errmsg = e_winheight; } } else if (pp == &p_wiw) { if (p_wiw < 1) { errmsg = e_positive; - } - if (p_wmw > p_wiw) { + } else if (p_wmw > p_wiw) { errmsg = e_winwidth; } } else if (pp == &p_wmw) { if (p_wmw < 0) { errmsg = e_positive; - } - if (p_wmw > p_wiw) { + } else if (p_wmw > p_wiw) { errmsg = e_winwidth; } } else if (pp == &p_mco) { @@ -4110,16 +4107,16 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, } else if (curwin->w_p_nuw > 10) { errmsg = e_invarg; } - } else if (pp == &curbuf->b_p_iminsert) { - if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST) { + } else if (pp == &curbuf->b_p_iminsert || pp == &p_iminsert) { + if (*pp < 0 || *pp > B_IMODE_LAST) { errmsg = e_invarg; } - } else if (pp == &curbuf->b_p_imsearch) { - if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST) { + } else if (pp == &curbuf->b_p_imsearch || pp == &p_imsearch) { + if (*pp < -1 || *pp > B_IMODE_LAST) { errmsg = e_invarg; } - } else if (pp == &curbuf->b_p_tw) { - if (curbuf->b_p_tw < 0) { + } else if (pp == &curbuf->b_p_tw || pp == &p_tw) { + if (*pp < 0) { errmsg = e_positive; } } else if (pp == &curbuf->b_p_scbk || pp == &p_scbk) { @@ -4127,12 +4124,12 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, || (opt_flags == OPT_LOCAL && !curbuf->terminal)) { errmsg = e_invarg; } - } else if (pp == &curbuf->b_p_sw) { - if (curbuf->b_p_sw < 0) { + } else if (pp == &curbuf->b_p_sw || pp == &p_sw) { + if (*pp < 0) { errmsg = e_positive; } - } else if (pp == &curbuf->b_p_ts) { - if (curbuf->b_p_ts <= 0) { + } else if (pp == &curbuf->b_p_ts || pp == &p_ts) { + if (*pp <= 0) { errmsg = e_positive; } } @@ -4206,7 +4203,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, } else if (pp == &p_titlelen) { // if 'titlelen' has changed, redraw the title if (starting != NO_SCREEN && old_value != p_titlelen) { - need_maketitle = TRUE; + need_maketitle = true; } } else if (pp == &p_ch) { // if p_ch changed value, change the command line height @@ -4224,7 +4221,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, // sync undo before 'undolevels' changes // use the old value, otherwise u_sync() may not work properly *pp = old_value; - u_sync(TRUE); + u_sync(true); *pp = value; } else if (pp == &curbuf->b_p_tw) { FOR_ALL_TAB_WINDOWS(tp, wp) { -- cgit From db095f65636664afb4b09a3920571bf0565c7763 Mon Sep 17 00:00:00 2001 From: Jakob Schnitzer Date: Tue, 28 Mar 2017 16:17:53 +0200 Subject: options: more tests; check first set later; stricter validation --- src/nvim/option.c | 141 +++++++++++++++++++++++++++--------------------------- 1 file changed, 71 insertions(+), 70 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 637591d7ca..d5bc3c1765 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -7,7 +7,8 @@ // - For a window option, add some code to copy_winopt(). // - For a buffer option, add some code to buf_copy_options(). // - For a buffer string option, add code to check_buf_options(). -// - If it's a numeric option, add any necessary bounds checks to do_set(). +// - If it's a numeric option, add any necessary bounds checks to +// set_num_option(). // - If it's a list of flags, add some code in do_set(), search for WW_ALL. // - When adding an option with expansion (P_EXPAND), but with a different // default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP. @@ -1445,8 +1446,7 @@ do_set ( goto skip; } } else if (*arg == '-' || ascii_isdigit(*arg)) { - // Allow negative (for 'undolevels'), octal and - // hex numbers. + // Allow negative, octal and hex numbers. vim_str2nr(arg, NULL, &i, STR2NR_ALL, &value, NULL, 0); if (arg[i] != NUL && !ascii_iswhite(arg[i])) { errmsg = e_invarg; @@ -3995,151 +3995,158 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, return (char *)e_secure; } - *pp = value; - /* Remember where the option was set. */ - set_option_scriptID_idx(opt_idx, opt_flags, current_SID); + // Many number options assume their value is in the signed int range. + if (value < INT_MIN || value > INT_MAX) { + return e_invarg; + } - // Number options that need some validation when changed. + // Options that need some validation. if (pp == &p_wh) { - if (p_wh < 1) { + if (value < 1) { errmsg = e_positive; - } - if (p_wmh > p_wh) { + } else if (p_wmh > value) { errmsg = e_winheight; } } else if (pp == &p_hh) { - if (p_hh < 0) { + if (value < 0) { errmsg = e_positive; } } else if (pp == &p_wmh) { - if (p_wmh < 0) { + if (value < 0) { errmsg = e_positive; - } else if (p_wmh > p_wh) { + } else if (value > p_wh) { errmsg = e_winheight; } } else if (pp == &p_wiw) { - if (p_wiw < 1) { + if (value < 1) { errmsg = e_positive; - } else if (p_wmw > p_wiw) { + } else if (p_wmw > value) { errmsg = e_winwidth; } } else if (pp == &p_wmw) { - if (p_wmw < 0) { + if (value < 0) { errmsg = e_positive; - } else if (p_wmw > p_wiw) { + } else if (value > p_wiw) { errmsg = e_winwidth; } } else if (pp == &p_mco) { - if (p_mco > MAX_MCO) { + if (value > MAX_MCO) { errmsg = e_invarg; - } else if (p_mco < 0) { + } else if (value < 0) { errmsg = e_positive; } } else if (pp == &p_titlelen) { - if (p_titlelen < 0) { + if (value < 0) { errmsg = e_positive; } } else if (pp == &p_uc) { - if (p_uc < 0) { + if (value < 0) { errmsg = e_positive; } } else if (pp == &p_ch) { - if (p_ch < 1) { + if (value < 1) { errmsg = e_positive; } } else if (pp == &p_tm) { - if (p_tm < 0) { + if (value < 0) { errmsg = e_positive; } } else if (pp == &p_hi) { - if (p_hi < 0) { + if (value < 0) { errmsg = e_positive; - } else if (p_hi > 10000) { + } else if (value > 10000) { errmsg = e_invarg; } } else if (pp == &p_re) { - if (p_re < 0 || p_re > 2) { + if (value < 0 || value > 2) { errmsg = e_invarg; } } else if (pp == &p_report) { - if (p_report < 0) { + if (value < 0) { errmsg = e_positive; } } else if (pp == &p_so) { - if (p_so < 0 && full_screen) { + if (value < 0 && full_screen) { errmsg = e_scroll; } } else if (pp == &p_siso) { - if (p_siso < 0 && full_screen) { + if (value < 0 && full_screen) { errmsg = e_positive; } } else if (pp == &p_cwh) { - if (p_cwh < 1) { + if (value < 1) { errmsg = e_positive; } } else if (pp == &p_ut) { - if (p_ut < 0) { + if (value < 0) { errmsg = e_positive; } } else if (pp == &p_ss) { - if (p_ss < 0) { + if (value < 0) { errmsg = e_positive; } - } else if (pp == &curwin->w_p_fdl) { - if (curwin->w_p_fdl < 0) { + } else if (pp == &curwin->w_p_fdl + || pp == (long *)GLOBAL_WO(&curwin->w_p_fdl)) { + if (value < 0) { errmsg = e_positive; } - } else if (pp == &curwin->w_p_fdc) { - if (curwin->w_p_fdc < 0) { + } else if (pp == &curwin->w_p_fdc + || pp == (long *)GLOBAL_WO(&curwin->w_p_fdc)) { + if (value < 0) { errmsg = e_positive; - } else if (curwin->w_p_fdc > 12) { + } else if (value > 12) { errmsg = e_invarg; } - } else if (pp == &curwin->w_p_cole) { - if (curwin->w_p_cole < 0) { + } else if (pp == &curwin->w_p_cole + || pp == (long *)GLOBAL_WO(&curwin->w_p_cole)) { + if (value < 0) { errmsg = e_positive; - } else if (curwin->w_p_cole > 3) { + } else if (value > 3) { errmsg = e_invarg; } - } else if (pp == &curwin->w_p_nuw) { - if (curwin->w_p_nuw < 1) { + } else if (pp == &curwin->w_p_nuw + || pp == (long *)GLOBAL_WO(&curwin->w_p_nuw)) { + if (value < 1) { errmsg = e_positive; - } else if (curwin->w_p_nuw > 10) { + } else if (value > 10) { errmsg = e_invarg; } } else if (pp == &curbuf->b_p_iminsert || pp == &p_iminsert) { - if (*pp < 0 || *pp > B_IMODE_LAST) { + if (value < 0 || value > B_IMODE_LAST) { errmsg = e_invarg; } } else if (pp == &curbuf->b_p_imsearch || pp == &p_imsearch) { - if (*pp < -1 || *pp > B_IMODE_LAST) { + if (value < -1 || value > B_IMODE_LAST) { errmsg = e_invarg; } - } else if (pp == &curbuf->b_p_tw || pp == &p_tw) { - if (*pp < 0) { - errmsg = e_positive; - } } else if (pp == &curbuf->b_p_scbk || pp == &p_scbk) { - if (*pp < -1 || *pp > SB_MAX + if (value < -1 || value > SB_MAX || (opt_flags == OPT_LOCAL && !curbuf->terminal)) { errmsg = e_invarg; } } else if (pp == &curbuf->b_p_sw || pp == &p_sw) { - if (*pp < 0) { + if (value < 0) { errmsg = e_positive; } } else if (pp == &curbuf->b_p_ts || pp == &p_ts) { - if (*pp <= 0) { + if (value <= 0) { + errmsg = e_positive; + } + } else if (pp == &curbuf->b_p_tw || pp == &p_tw) { + if (value < 0) { errmsg = e_positive; } } - // If validation failed, reset to old value and return. + // Don't change the value and return early if validation failed. if (errmsg != NULL) { - *pp = old_value; return errmsg; } + *pp = value; + // Remember where the option was set. + set_option_scriptID_idx(opt_idx, opt_flags, current_SID); + // For these options we want to fix some invalid values. if (pp == &p_window) { if (p_window < 1) { @@ -4168,11 +4175,8 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, if (lastwin != firstwin && curwin->w_width < p_wiw) { win_setwidth((int)p_wiw); } - } else if (pp == &p_wmw) { - win_setminheight(); } else if (pp == &p_ls) { - // (re)set last window status line. - last_status(false); + last_status(false); // (re)set last window status line. } else if (pp == &p_stal) { // (re)set tab page line shell_new_rows(); // recompute window positions and heights @@ -4237,9 +4241,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, } - /* - * Check the bounds for numeric options here - */ + // Check the (new) bounds for Rows and Columns here. if (Rows < min_rows() && full_screen) { if (errbuf != NULL) { vim_snprintf((char *)errbuf, errbuflen, @@ -4259,19 +4261,17 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, limit_screen_size(); - /* - * If the screen (shell) height has been changed, assume it is the - * physical screenheight. - */ + // If the screen (shell) height has been changed, assume it is the + // physical screenheight. if (old_Rows != Rows || old_Columns != Columns) { - /* Changing the screen size is not allowed while updating the screen. */ + // Changing the screen size is not allowed while updating the screen. if (updating_screen) { *pp = old_value; } else if (full_screen) { screen_resize((int)Columns, (int)Rows); } else { - /* Postpone the resizing; check the size and cmdline position for - * messages. */ + // Postpone the resizing; check the size and cmdline position for + // messages. check_shellsize(); if (cmdline_row > Rows - p_ch && Rows > p_ch) { assert(p_ch >= 0 && Rows - p_ch <= INT_MAX); @@ -4308,9 +4308,10 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, } } - /* May set global value for local option. */ - if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) + // May set global value for local option. + if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) { *(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. -- cgit From 8a55f9b1c8bab2cf22e266d7e1eecde85119d75d Mon Sep 17 00:00:00 2001 From: Jakob Schnitzer Date: Fri, 31 Mar 2017 18:30:06 +0200 Subject: update for changes in master; fix 'window'; tests --- src/nvim/option.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index d5bc3c1765..eddfdd6218 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3997,7 +3997,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, // Many number options assume their value is in the signed int range. if (value < INT_MIN || value > INT_MAX) { - return e_invarg; + return (char *)e_invarg; } // Options that need some validation. @@ -4129,7 +4129,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, errmsg = e_positive; } } else if (pp == &curbuf->b_p_ts || pp == &p_ts) { - if (value <= 0) { + if (value < 1) { errmsg = e_positive; } } else if (pp == &curbuf->b_p_tw || pp == &p_tw) { @@ -4140,7 +4140,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, // Don't change the value and return early if validation failed. if (errmsg != NULL) { - return errmsg; + return (char *)errmsg; } *pp = value; @@ -4150,7 +4150,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, // For these options we want to fix some invalid values. if (pp == &p_window) { if (p_window < 1) { - p_window = 1; + p_window = Rows - 1; } else if (p_window >= Rows) { p_window = Rows - 1; } @@ -4188,7 +4188,7 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) { foldUpdateAll(curwin); } - } else if (pp == &curbuf->b_p_sw || pp == (long *)&curbuf->b_p_ts) { + } else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts) { // 'shiftwidth' or 'tabstop' if (foldmethodIsIndent(curwin)) { foldUpdateAll(curwin); -- cgit From 3aa24042a8f7d591b8091b437fc9cdb03497bc7a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 27 Nov 2017 00:35:09 +0100 Subject: tui: dump termcap info if -V3 ('verbose' >= 3) Get terminal debugging info by starting Nvim with 'verbose' level 3: nvim -V3log This is like Vim's `:set termcap`, which was removed in Nvim (and would be very awkward to restore because of the decoupled UI). --- src/nvim/option.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 913d27d508..37c4233142 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -4906,15 +4906,14 @@ showoptions ( vimoption_T **items = xmalloc(sizeof(vimoption_T *) * PARAM_COUNT); - /* Highlight title */ - if (all == 2) - MSG_PUTS_TITLE(_("\n--- Terminal codes ---")); - else if (opt_flags & OPT_GLOBAL) + // Highlight title + if (opt_flags & OPT_GLOBAL) { MSG_PUTS_TITLE(_("\n--- Global option values ---")); - else if (opt_flags & OPT_LOCAL) + } else if (opt_flags & OPT_LOCAL) { MSG_PUTS_TITLE(_("\n--- Local option values ---")); - else + } else { MSG_PUTS_TITLE(_("\n--- Options ---")); + } /* * do the loop two times: -- cgit From 1f2b35860f755513a58c1d010f082d946c889b47 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Thu, 7 Dec 2017 20:53:02 -0500 Subject: mac: Set $LANG based on the system locale Unix's typical locale-related environment variables aren't always set appropriately on a Mac. Instead of relying on them, query the locale information using Mac specific APIs and then set $LANG appropriately for the rest of nvim. Closes #5873 --- src/nvim/option.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 37c4233142..f8a05f133d 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -75,6 +75,7 @@ #include "nvim/window.h" #include "nvim/os/os.h" #include "nvim/os/input.h" +#include "nvim/os/lang.h" /* * The options that are local to a window or buffer have "indir" set to one of @@ -784,6 +785,8 @@ void set_init_1(void) didset_options2(); + lang_init(); + // enc_locale() will try to find the encoding of the current locale. // This will be used when 'default' is used as encoding specifier // in 'fileencodings' -- cgit From 34057045beca40406673ff421a4ef1e8e8c08853 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 12 Dec 2017 18:23:19 +0100 Subject: ui: forward relevant option updates to UIs (#7520) also make termguicolors mutable after startup --- src/nvim/option.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index f8a05f133d..499cf79836 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -74,6 +74,7 @@ #include "nvim/undo.h" #include "nvim/window.h" #include "nvim/os/os.h" +#include "nvim/api/private/helpers.h" #include "nvim/os/input.h" #include "nvim/os/lang.h" @@ -248,6 +249,7 @@ typedef struct vimoption { #define P_RWINONLY 0x10000000U ///< only redraw current window #define P_NDNAME 0x20000000U ///< only normal dir name chars allowed +#define P_UI_OPTION 0x40000000U ///< send option to remote ui #define HIGHLIGHT_INIT \ "8:SpecialKey,~:EndOfBuffer,z:TermCursor,Z:TermCursorNC,@:NonText," \ @@ -1188,6 +1190,7 @@ do_set ( set_options_default(OPT_FREE | opt_flags); didset_options(); didset_options2(); + ui_refresh_options(); redraw_all_later(CLEAR); } else { showoptions(1, opt_flags); @@ -1815,6 +1818,10 @@ do_set ( NULL, false, NULL); reset_v_option_vars(); xfree(saved_origval); + if (options[opt_idx].flags & P_UI_OPTION) { + ui_call_option_set(cstr_as_string(options[opt_idx].fullname), + STRING_OBJ(cstr_as_string(*(char **)varp))); + } } } else { // key code option(FIXME(tarruda): Show a warning or something @@ -2417,6 +2424,10 @@ static char *set_string_option(const int opt_idx, const char *const value, NULL, false, NULL); reset_v_option_vars(); xfree(saved_oldval); + if (options[opt_idx].flags & P_UI_OPTION) { + ui_call_option_set(cstr_as_string(options[opt_idx].fullname), + STRING_OBJ(cstr_as_string((char *)(*varp)))); + } } return r; @@ -4024,6 +4035,10 @@ static char *set_bool_option(const int opt_idx, char_u *const varp, (char_u *) options[opt_idx].fullname, NULL, false, NULL); reset_v_option_vars(); + if (options[opt_idx].flags & P_UI_OPTION) { + ui_call_option_set(cstr_as_string(options[opt_idx].fullname), + BOOLEAN_OBJ(value)); + } } comp_col(); /* in case 'ruler' or 'showcmd' changed */ @@ -4429,6 +4444,10 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, (char_u *) options[opt_idx].fullname, NULL, false, NULL); reset_v_option_vars(); + if (options[opt_idx].flags & P_UI_OPTION) { + ui_call_option_set(cstr_as_string(options[opt_idx].fullname), + INTEGER_OBJ(value)); + } } comp_col(); /* in case 'columns' or 'ls' changed */ @@ -4999,6 +5018,29 @@ static int optval_default(vimoption_T *p, char_u *varp) return STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0; } +/// Send update to UIs with values of UI relevant options +void ui_refresh_options(void) +{ + for (int opt_idx = 0; options[opt_idx].fullname; opt_idx++) { + uint32_t flags = options[opt_idx].flags; + if (!(flags & P_UI_OPTION)) { + continue; + } + String name = cstr_as_string(options[opt_idx].fullname); + void *varp = options[opt_idx].var; + Object value = OBJECT_INIT; + if (flags & P_BOOL) { + value = BOOLEAN_OBJ(*(int *)varp); + } else if (flags & P_NUM) { + value = INTEGER_OBJ(*(long *)varp); + } else if (flags & P_STRING) { + // cstr_as_string handles NULL string + value = STRING_OBJ(cstr_as_string(*(char **)varp)); + } + ui_call_option_set(name, value); + } +} + /* * showoneopt: show the value of one option * must not be called with a hidden option! -- cgit From d5bce42b524708a54243658e87b1e3bd9c7acdf3 Mon Sep 17 00:00:00 2001 From: Michael Schupikov Date: Sat, 23 Sep 2017 09:56:44 +0200 Subject: vim-patch:8.0.0074 Problem: Cannot make Vim fail on an internal error. Solution: Add IEMSG() and IEMSG2(). (Domenique Pelle) Avoid reporting an internal error without mentioning where. https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f Signed-off-by: Michael Schupikov --- src/nvim/option.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 499cf79836..a345906200 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2258,7 +2258,7 @@ int was_set_insecurely(char_u *opt, int opt_flags) uint32_t *flagp = insecure_flag(idx, opt_flags); return (*flagp & P_INSECURE) != 0; } - EMSG2(_(e_intern2), "was_set_insecurely()"); + internal_error("was_set_insecurely()"); return -1; } @@ -2317,8 +2317,8 @@ set_string_option_direct ( if (idx == -1) { // Use name. idx = findoption((const char *)name); if (idx < 0) { // Not found (should not happen). - EMSG2(_(e_intern2), "set_string_option_direct()"); - EMSG2(_("For option %s"), name); + internal_error("set_string_option_direct()"); + IEMSG2(_("For option %s"), name); return; } } @@ -5584,7 +5584,7 @@ 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); - default: EMSG(_("E356: get_varp ERROR")); + default: IEMSG(_("E356: get_varp ERROR")); } /* always return a valid pointer to avoid a crash! */ return (char_u *)&(curbuf->b_p_wm); -- cgit From c162bc629440afaf8910f1a29f1dfdb03f898101 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sat, 16 Dec 2017 21:50:20 -0500 Subject: vim-patch:8.0.0420: text garbled when the system encoding differs from 'encoding' Problem: When running :make the output may be in the system encoding, different from 'encoding'. Solution: Add the 'makeencoding' option. (Ken Takata) https://github.com/vim/vim/commit/2c7292dc5bbf155fe2192d417363b8c085759cad --- src/nvim/option.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index a345906200..192d2b0f78 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2217,6 +2217,7 @@ void check_buf_options(buf_T *buf) check_string_option(&buf->b_p_tsr); check_string_option(&buf->b_p_lw); check_string_option(&buf->b_p_bkc); + check_string_option(&buf->b_p_menc); } /* @@ -2635,8 +2636,8 @@ did_set_string_option ( else if (varp == &p_ei) { if (check_ei() == FAIL) errmsg = e_invarg; - /* 'encoding' and 'fileencoding' */ - } else if (varp == &p_enc || gvarp == &p_fenc) { + // 'encoding', 'fileencoding' and 'makeencoding' + } else if (varp == &p_enc || gvarp == &p_fenc || gvarp == &p_menc) { if (gvarp == &p_fenc) { if (!MODIFIABLE(curbuf) && opt_flags != OPT_GLOBAL) { errmsg = e_modifiable; @@ -5400,6 +5401,9 @@ void unset_global_local_option(char *name, void *from) case PV_LW: clear_string_option(&buf->b_p_lw); break; + case PV_MENC: + clear_string_option(&buf->b_p_menc); + break; } } @@ -5433,6 +5437,7 @@ static char_u *get_varp_scope(vimoption_T *p, int opt_flags) case PV_UL: return (char_u *)&(curbuf->b_p_ul); case PV_LW: return (char_u *)&(curbuf->b_p_lw); case PV_BKC: return (char_u *)&(curbuf->b_p_bkc); + case PV_MENC: return (char_u *)&(curbuf->b_p_menc); } return NULL; /* "cannot happen" */ } @@ -5488,6 +5493,8 @@ static char_u *get_varp(vimoption_T *p) ? (char_u *)&(curbuf->b_p_ul) : p->var; case PV_LW: return *curbuf->b_p_lw != NUL ? (char_u *)&(curbuf->b_p_lw) : p->var; + case PV_MENC: return *curbuf->b_p_menc != NUL + ? (char_u *)&(curbuf->b_p_menc) : p->var; case PV_ARAB: return (char_u *)&(curwin->w_p_arab); case PV_LIST: return (char_u *)&(curwin->w_p_list); @@ -5885,6 +5892,7 @@ void buf_copy_options(buf_T *buf, int flags) buf->b_p_qe = vim_strsave(p_qe); buf->b_p_udf = p_udf; buf->b_p_lw = empty_option; + buf->b_p_menc = empty_option; /* * Don't copy the options set by ex_help(), use the saved values, -- cgit From 06994e0e21eb5545aef7c2234f5d1a271865366e Mon Sep 17 00:00:00 2001 From: George Zhao Date: Wed, 17 Jan 2018 19:35:57 +0800 Subject: Fix warning about conversion on mingw64 --- src/nvim/option.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 192d2b0f78..d9ee8f8b94 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -844,7 +844,7 @@ set_option_default ( if (options[opt_idx].indir == PV_SCROLL) win_comp_scroll(curwin); else { - *(long *)varp = (long)options[opt_idx].def_val[dvi]; + *(long *)varp = (long)(intptr_t)options[opt_idx].def_val[dvi]; /* May also set global value for local option. */ if (both) *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = @@ -926,7 +926,7 @@ void set_number_default(char *name, long val) opt_idx = findoption(name); if (opt_idx >= 0) { - options[opt_idx].def_val[VI_DEFAULT] = (char_u *)val; + options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(intptr_t)val; } } @@ -1442,7 +1442,7 @@ do_set ( */ ++arg; if (nextchar == '&') - value = (long)options[opt_idx].def_val[ + value = (long)(intptr_t)options[opt_idx].def_val[ ((flags & P_VI_DEF) || cp_val) ? VI_DEFAULT : VIM_DEFAULT]; else if (nextchar == '<') { @@ -5012,7 +5012,7 @@ static int optval_default(vimoption_T *p, char_u *varp) return TRUE; /* hidden option is always at default */ dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT; if (p->flags & P_NUM) - return *(long *)varp == (long)p->def_val[dvi]; + return *(long *)varp == (long)(intptr_t)p->def_val[dvi]; if (p->flags & P_BOOL) return *(int *)varp == (int)(intptr_t)p->def_val[dvi]; /* P_STRING */ -- cgit From 10b1738f590fe08675173071b35fface324f4048 Mon Sep 17 00:00:00 2001 From: George Zhao Date: Wed, 17 Jan 2018 22:29:23 +0800 Subject: Fix lint error in option.c --- src/nvim/option.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index d9ee8f8b94..fa2e6b169b 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -831,24 +831,26 @@ set_option_default ( if (flags & P_STRING) { /* Use set_string_option_direct() for local options to handle * freeing and allocating the value. */ - if (options[opt_idx].indir != PV_NONE) + if (options[opt_idx].indir != PV_NONE) { set_string_option_direct(NULL, opt_idx, - options[opt_idx].def_val[dvi], opt_flags, 0); - else { - if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED)) + options[opt_idx].def_val[dvi], opt_flags, 0); + } else { + if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED)) { free_string_option(*(char_u **)(varp)); + } *(char_u **)varp = options[opt_idx].def_val[dvi]; options[opt_idx].flags &= ~P_ALLOCED; } } else if (flags & P_NUM) { - if (options[opt_idx].indir == PV_SCROLL) + if (options[opt_idx].indir == PV_SCROLL) { win_comp_scroll(curwin); - else { + } else { *(long *)varp = (long)(intptr_t)options[opt_idx].def_val[dvi]; - /* May also set global value for local option. */ - if (both) + // May also set global value for local option. + if (both) { *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *(long *)varp; + } } } else { /* P_BOOL */ *(int *)varp = (int)(intptr_t)options[opt_idx].def_val[dvi]; @@ -1440,20 +1442,19 @@ do_set ( * [-]0-9 set number * other error */ - ++arg; - if (nextchar == '&') + arg++; + if (nextchar == '&') { value = (long)(intptr_t)options[opt_idx].def_val[ - ((flags & P_VI_DEF) || cp_val) - ? VI_DEFAULT : VIM_DEFAULT]; - else if (nextchar == '<') { - /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to - * use the global value. */ - if ((long *)varp == &curbuf->b_p_ul - && opt_flags == OPT_LOCAL) + ((flags & P_VI_DEF) || cp_val) ? VI_DEFAULT : VIM_DEFAULT]; + } else if (nextchar == '<') { + // For 'undolevels' NO_LOCAL_UNDOLEVEL means to + // use the global value. + if ((long *)varp == &curbuf->b_p_ul && opt_flags == OPT_LOCAL) { value = NO_LOCAL_UNDOLEVEL; - else + } else { value = *(long *)get_varp_scope( &(options[opt_idx]), OPT_GLOBAL); + } } else if (((long *)varp == &p_wc || (long *)varp == &p_wcm) && (*arg == '<' @@ -5011,11 +5012,13 @@ static int optval_default(vimoption_T *p, char_u *varp) if (varp == NULL) return TRUE; /* hidden option is always at default */ dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT; - if (p->flags & P_NUM) + if (p->flags & P_NUM) { return *(long *)varp == (long)(intptr_t)p->def_val[dvi]; - if (p->flags & P_BOOL) + } + if (p->flags & P_BOOL) { return *(int *)varp == (int)(intptr_t)p->def_val[dvi]; - /* P_STRING */ + } + // P_STRING return STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0; } -- cgit From 8728a5d50bc3339db81c7f29d59c55f9f817f06c Mon Sep 17 00:00:00 2001 From: KunMing Xie Date: Wed, 31 Jan 2018 03:29:15 +0800 Subject: vim-patch:8.0.0448: some macros are lower case (#7936) Problem: Some macros are in lower case, which can be confusing. Solution: Make a few lower case macros upper case. https://github.com/vim/vim/commit/b5aedf3e228d35821591da9ae8501b61cf2e264c ref #6297 --- src/nvim/option.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index fa2e6b169b..aa1f5f3fe7 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1059,7 +1059,7 @@ void set_init_3(void) xfree(p); } - if (bufempty()) { + if (BUFEMPTY()) { int idx_ffs = findoption_len(S_LEN("ffs")); // Apply the first entry of 'fileformats' to the initial buffer. -- cgit From 2d151f7739a072ee7239cc44efec2b43c1b72679 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 2 Feb 2018 02:04:36 +0100 Subject: vim-patch:8.0.0676: crash when closing quickfix window in autocmd Problem: Crash when closing the quickfix window in a FileType autocommand that triggers when the quickfix window is opened. Solution: Save the new value before triggering the OptionSet autocommand. Add the "starting" flag to test_override() to make the text work. https://github.com/vim/vim/commit/182a17b1e80b92826204d967808df0d30eb2ef27 --- src/nvim/option.c | 74 +++++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index aa1f5f3fe7..0858637a9d 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1790,40 +1790,31 @@ do_set ( /* Set the new value. */ *(char_u **)(varp) = newval; - if (!starting && origval != NULL) { + if (!starting && origval != NULL && newval != NULL) { // origval may be freed by // did_set_string_option(), make a copy. saved_origval = xstrdup((char *) origval); + // newval (and varp) may become invalid if the + // buffer is closed by autocommands. + saved_newval = vim_strsave(newval); } - /* Handle side effects, and set the global value for - * ":set" on local options. */ + // Handle side effects, and set the global value for + // ":set" on local options. Note: when setting 'syntax' + // or 'filetype' autocommands may be triggered that can + // cause havoc. errmsg = did_set_string_option(opt_idx, (char_u **)varp, new_value_alloced, oldval, errbuf, opt_flags); // If error detected, print the error message. if (errmsg != NULL) { xfree(saved_origval); + xfree(saved_newval); goto skip; } - if (saved_origval != NULL) { - char buf_type[7]; - vim_snprintf(buf_type, ARRAY_SIZE(buf_type), "%s", - (opt_flags & OPT_LOCAL) ? "local" : "global"); - set_vim_var_string(VV_OPTION_NEW, *(char **) varp, -1); - set_vim_var_string(VV_OPTION_OLD, saved_origval, -1); - set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); - apply_autocmds(EVENT_OPTIONSET, - (char_u *)options[opt_idx].fullname, - NULL, false, NULL); - reset_v_option_vars(); - xfree(saved_origval); - if (options[opt_idx].flags & P_UI_OPTION) { - ui_call_option_set(cstr_as_string(options[opt_idx].fullname), - STRING_OBJ(cstr_as_string(*(char **)varp))); - } - } + trigger_optionsset_string(opt_idx, opt_flags, saved_origval, + saved_newval); } else { // key code option(FIXME(tarruda): Show a warning or something // similar) @@ -2406,6 +2397,7 @@ static char *set_string_option(const int opt_idx, const char *const value, *varp = s; char *const saved_oldval = (starting ? NULL : xstrdup(oldval)); + char *const *saved_newval = (starting ? NULL : xstrdup(s)); char *const r = (char *)did_set_string_option( opt_idx, (char_u **)varp, (int)true, (char_u *)oldval, NULL, opt_flags); @@ -2414,23 +2406,8 @@ static char *set_string_option(const int opt_idx, const char *const value, } // call autocommand after handling side effects - if (saved_oldval != NULL) { - char buf_type[7]; - vim_snprintf(buf_type, ARRAY_SIZE(buf_type), "%s", - (opt_flags & OPT_LOCAL) ? "local" : "global"); - set_vim_var_string(VV_OPTION_NEW, (char *)(*varp), -1); - set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1); - set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); - apply_autocmds(EVENT_OPTIONSET, - (char_u *)options[opt_idx].fullname, - NULL, false, NULL); - reset_v_option_vars(); - xfree(saved_oldval); - if (options[opt_idx].flags & P_UI_OPTION) { - ui_call_option_set(cstr_as_string(options[opt_idx].fullname), - STRING_OBJ(cstr_as_string((char *)(*varp)))); - } - } + trigger_optionsset_string(opt_idx, opt_flags, + saved_oldval, saved_newval); return r; } @@ -4461,6 +4438,29 @@ static char *set_num_option(int opt_idx, char_u *varp, long value, return (char *)errmsg; } +static void trigger_optionsset_string(int opt_idx, int opt_flags, + char *oldval, char *newval) +{ + if (oldval != NULL && newval != NULL) { + char buf_type[7]; + + vim_snprintf(buf_type, ARRAY_SIZE(buf_type), "%s", + (opt_flags & OPT_LOCAL) ? "local" : "global"); + set_vim_var_string(VV_OPTION_OLD, oldval, -1); + set_vim_var_string(VV_OPTION_NEW, newval, -1); + set_vim_var_string(VV_OPTION_TYPE, buf_type, -1); + apply_autocmds(EVENT_OPTIONSET, + (char_u *)options[opt_idx].fullname, NULL, false, NULL); + reset_v_option_vars(); + if (options[opt_idx].flags & P_UI_OPTION) { + ui_call_option_set(cstr_as_string(options[opt_idx].fullname), + STRING_OBJ(cstr_as_string(newval))); + } + } + xfree(oldval); + xfree(newval); +} + /* * Called after an option changed: check if something needs to be redrawn. */ -- cgit From fd58863eb62edddf688a71d73448934efa188241 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 2 Feb 2018 02:30:21 +0100 Subject: vim-patch:8.0.0703: illegal memory access with empty :doau command Problem: Illegal memory access with empty :doau command. Solution: Check the event for being out of range. (James McCoy) https://github.com/vim/vim/commit/faf29d7f91477c25c85d9d7165d90e8d8f1c512e --- src/nvim/option.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 0858637a9d..6b1bb2b8a3 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1498,6 +1498,7 @@ do_set ( char_u *newval; char_u *origval = NULL; char *saved_origval = NULL; + char *saved_newval = NULL; unsigned newlen; int comma; int bs; @@ -1793,10 +1794,10 @@ do_set ( if (!starting && origval != NULL && newval != NULL) { // origval may be freed by // did_set_string_option(), make a copy. - saved_origval = xstrdup((char *) origval); + saved_origval = xstrdup((char *)origval); // newval (and varp) may become invalid if the // buffer is closed by autocommands. - saved_newval = vim_strsave(newval); + saved_newval = xstrdup((char *)newval); } // Handle side effects, and set the global value for @@ -2397,7 +2398,7 @@ static char *set_string_option(const int opt_idx, const char *const value, *varp = s; char *const saved_oldval = (starting ? NULL : xstrdup(oldval)); - char *const *saved_newval = (starting ? NULL : xstrdup(s)); + char *const saved_newval = (starting ? NULL : xstrdup(s)); char *const r = (char *)did_set_string_option( opt_idx, (char_u **)varp, (int)true, (char_u *)oldval, NULL, opt_flags); -- cgit From e578d586f28160d684087bae99482ab3912d3770 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 2 Feb 2018 02:38:10 +0100 Subject: vim-patch:8.0.0974: resetting a string option does not trigger OptionSet Problem: Resetting a string option does not trigger OptionSet. (Rick Howe) Solution: Set the origval. https://github.com/vim/vim/commit/8efa026a25b95de5598535ef62505282a8584a4b --- src/nvim/option.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 6b1bb2b8a3..7195ef58ac 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1515,6 +1515,16 @@ do_set ( /* The old value is kept until we are sure that the * new value is valid. */ oldval = *(char_u **)varp; + + // When setting the local value of a global + // option, the old value may be the global value. + if (((int)options[opt_idx].indir & PV_BOTH) && (opt_flags + & OPT_LOCAL)) { + origval = *(char_u **)get_varp(&options[opt_idx]); + } else { + origval = oldval; + } + if (nextchar == '&') { /* set to default val */ newval = options[opt_idx].def_val[ ((flags & P_VI_DEF) || cp_val) @@ -1610,15 +1620,6 @@ do_set ( ++arg; } - /* When setting the local value of a global - * option, the old value may be the global value. */ - if (((int)options[opt_idx].indir & PV_BOTH) - && (opt_flags & OPT_LOCAL)) - origval = *(char_u **)get_varp( - &options[opt_idx]); - else - origval = oldval; - /* * Copy the new string into allocated memory. * Can't use set_string_option_direct(), because @@ -1788,7 +1789,7 @@ do_set ( new_value_alloced = TRUE; } - /* Set the new value. */ + // Set the new value. *(char_u **)(varp) = newval; if (!starting && origval != NULL && newval != NULL) { @@ -1807,15 +1808,18 @@ do_set ( errmsg = did_set_string_option(opt_idx, (char_u **)varp, new_value_alloced, oldval, errbuf, opt_flags); + if (errmsg == NULL) { + trigger_optionsset_string(opt_idx, opt_flags, saved_origval, + saved_newval); + } + xfree(saved_origval); + xfree(saved_newval); + // If error detected, print the error message. if (errmsg != NULL) { - xfree(saved_origval); - xfree(saved_newval); goto skip; } - trigger_optionsset_string(opt_idx, opt_flags, saved_origval, - saved_newval); } else { // key code option(FIXME(tarruda): Show a warning or something // similar) @@ -2407,8 +2411,12 @@ static char *set_string_option(const int opt_idx, const char *const value, } // call autocommand after handling side effects - trigger_optionsset_string(opt_idx, opt_flags, - saved_oldval, saved_newval); + if (r == NULL) { + trigger_optionsset_string(opt_idx, opt_flags, + saved_oldval, saved_newval); + } + xfree(saved_oldval); + xfree(saved_newval); return r; } @@ -4458,8 +4466,6 @@ static void trigger_optionsset_string(int opt_idx, int opt_flags, STRING_OBJ(cstr_as_string(newval))); } } - xfree(oldval); - xfree(newval); } /* -- cgit From f69e0d314fe2ab3e2456441b593f4f154dba1026 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 11 Feb 2018 16:44:00 +0100 Subject: vim-patch:8.0.0975: using freed memory when setting 'backspace' Problem: Using freed memory when setting 'backspace'. Solution: When changing oldval also change origval. https://github.com/vim/vim/commit/edbc0d46cffe1766d0b330dc2842212cff644f8e --- src/nvim/option.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 7195ef58ac..b0e0d01504 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1584,6 +1584,9 @@ do_set ( break; } xfree(oldval); + if (origval == oldval) { + origval = *(char_u **)varp; + } oldval = *(char_u **)varp; } /* -- cgit From f26a4d484b486019c90fc55af5e74e33de374bc4 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 11 Feb 2018 19:02:57 +0100 Subject: lint --- src/nvim/option.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index b0e0d01504..c805e41ec5 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1525,7 +1525,7 @@ do_set ( origval = oldval; } - if (nextchar == '&') { /* set to default val */ + if (nextchar == '&') { // set to default val newval = options[opt_idx].def_val[ ((flags & P_VI_DEF) || cp_val) ? VI_DEFAULT : VIM_DEFAULT]; -- cgit From e9134421ab8f72393d469d9d7793d4a75984cb93 Mon Sep 17 00:00:00 2001 From: Nimit Bhardwaj Date: Wed, 14 Feb 2018 19:48:01 +0530 Subject: vim-patch-8.0.0649 and vim-patch-8.0.0650: autocmd open help 2 times --- src/nvim/option.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index c805e41ec5..2341371f65 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2455,6 +2455,7 @@ did_set_string_option ( int did_chartab = FALSE; char_u **gvarp; bool free_oldval = (options[opt_idx].flags & P_ALLOCED); + int ft_changed = false; /* Get the global option to compare with, otherwise we would have to check * two values for all local options. */ @@ -3174,6 +3175,8 @@ did_set_string_option ( } else if (gvarp == &p_ft) { if (!valid_filetype(*varp)) { errmsg = e_invarg; + } else { + ft_changed = STRCMP(oldval, *varp) != 0; } } else if (gvarp == &p_syn) { if (!valid_filetype(*varp)) { @@ -3256,10 +3259,12 @@ did_set_string_option ( apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname, TRUE, curbuf); } else if (varp == &(curbuf->b_p_ft)) { - /* 'filetype' is set, trigger the FileType autocommand */ - did_filetype = TRUE; - apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, - curbuf->b_fname, TRUE, curbuf); + // 'filetype' is set, trigger the FileType autocommand + if (!(opt_flags & OPT_MODELINE) || ft_changed) { + did_filetype = true; + apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, + curbuf->b_fname, true, curbuf); + } } if (varp == &(curwin->w_s->b_p_spl)) { char_u fname[200]; -- cgit From 384a39479a0b70abf9cd6ced0b5f1d53cd817c11 Mon Sep 17 00:00:00 2001 From: Matthieu Coudron Date: Fri, 9 Feb 2018 08:44:24 +0900 Subject: 'fillchars': fix defaults logic; handle ambiwidth=double #7986 Update tests. --- src/nvim/option.c | 76 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 33 deletions(-) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 2341371f65..eff436eb4d 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3381,37 +3381,38 @@ skip: return NULL; /* no error */ } -/* - * Handle setting 'listchars' or 'fillchars'. - * Returns error message, NULL if it's OK. - */ + +/// Handle setting 'listchars' or 'fillchars'. +/// Assume monocell characters +/// +/// @param varp either &p_lcs ('listchars') or &p_fcs ('fillchar') +/// @return error message, NULL if it's OK. static char_u *set_chars_option(char_u **varp) { int round, i, len, entries; char_u *p, *s; int c1, c2 = 0; struct charstab { - int *cp; - char *name; + 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"}, - {&fill_fold, "fold"}, - {&fill_diff, "diff"}, + static struct charstab filltab[] = { + { &fill_stl, "stl" , ' ' }, + { &fill_stlnc, "stlnc", ' ' }, + { &fill_vert, "vert" , 9474 }, // │ + { &fill_fold, "fold" , 183 }, // · + { &fill_diff, "diff" , '-' }, }; - static struct charstab lcstab[] = - { - {&lcs_eol, "eol"}, - {&lcs_ext, "extends"}, - {&lcs_nbsp, "nbsp"}, - {&lcs_prec, "precedes"}, - {&lcs_space, "space"}, - {&lcs_tab2, "tab"}, - {&lcs_trail, "trail"}, - {&lcs_conceal, "conceal"}, + 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 charstab *tab; @@ -3421,20 +3422,29 @@ static char_u *set_chars_option(char_u **varp) } else { tab = filltab; entries = ARRAY_SIZE(filltab); + 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 = '-'; + } else { + filltab[2].def = 9474; // │ + filltab[3].def = 183; // · + } } - /* first round: check for valid value, second round: assign values */ - for (round = 0; round <= 1; ++round) { + // first round: check for valid value, second round: assign values + for (round = 0; round <= 1; round++) { if (round > 0) { - /* After checking that the value is valid: set defaults: space for - * 'fillchars', NUL for 'listchars' */ - for (i = 0; i < entries; ++i) - if (tab[i].cp != NULL) - *(tab[i].cp) = (varp == &p_lcs ? NUL : ' '); - if (varp == &p_lcs) + // After checking that the value is valid: set defaults + for (i = 0; i < entries; i++) { + if (tab[i].cp != NULL) { + *(tab[i].cp) = tab[i].def; + } + } + if (varp == &p_lcs) { lcs_tab1 = NUL; - else - fill_diff = '-'; + } } p = *varp; while (*p) { -- cgit From 353ca83f73dba0c7661a061215cc8508051a1be9 Mon Sep 17 00:00:00 2001 From: b-r-o-c-k Date: Sun, 4 Mar 2018 17:44:23 -0600 Subject: build/msvc: Workaround for compiler optimization bug --- src/nvim/option.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index eff436eb4d..d6903c8db7 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -2436,6 +2436,11 @@ static bool valid_filetype(char_u *val) return true; } +#ifdef _MSC_VER +// MSVC optimizations are disabled for this function because it +// incorrectly generates an empty string for SHM_ALL. +#pragma optimize("", off) +#endif /* * Handle string options that need some action to perform when changed. * Returns NULL for success, or an error message for an error. @@ -3305,6 +3310,9 @@ did_set_string_option ( return errmsg; } +#ifdef _MSC_VER +#pragma optimize("", on) +#endif /* * Simple int comparison function for use with qsort() -- cgit From 98e71123900fbdf26a16a43297a1f58118cde41b Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 31 Mar 2018 11:12:27 +0200 Subject: msg: do not scroll entire screen (#8088) --- src/nvim/option.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/option.c') diff --git a/src/nvim/option.c b/src/nvim/option.c index 41cfdf9856..c43ba2fc4f 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -3411,6 +3411,7 @@ static char_u *set_chars_option(char_u **varp) { &fill_vert, "vert" , 9474 }, // │ { &fill_fold, "fold" , 183 }, // · { &fill_diff, "diff" , '-' }, + { &fill_msgsep, "msgsep", ' ' }, }; static struct charstab lcstab[] = { { &lcs_eol, "eol", NUL }, -- cgit