options: clean up num_options side-effects

This commit is contained in:
Jakob Schnitzer
2017-03-27 19:17:58 +02:00
parent f4920fb485
commit 1a56a032fe

View File

@@ -3999,11 +3999,6 @@ static char *set_num_option(int opt_idx, char_u *varp, long value,
/* Remember where the option was set. */ /* Remember where the option was set. */
set_option_scriptID_idx(opt_idx, opt_flags, current_SID); 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. // Number options that need some validation when changed.
if (pp == &p_wh) { if (pp == &p_wh) {
if (p_wh < 1) { 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 if (*pp < -1 || *pp > SB_MAX
|| (opt_flags == OPT_LOCAL && !curbuf->terminal)) { || (opt_flags == OPT_LOCAL && !curbuf->terminal)) {
errmsg = e_invarg; errmsg = e_invarg;
} }
} else if (pp == &curbuf->b_p_sw) {
if (curbuf->b_p_sw < 0) {
errmsg = e_positive;
}
} else if (pp == &p_ch) { } else if (pp == &p_ch) {
if (p_ch < 1) { if (p_ch < 1) {
errmsg = e_positive; errmsg = e_positive;
} }
} }
// If validation failed, reset to old value and return.
if (errmsg != NULL) { if (errmsg != NULL) {
*pp = old_value; *pp = old_value;
return errmsg; 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 // Number options that need some action when changed
if (pp == &p_wh || pp == &p_hh) { if (pp == &p_wh) {
/* Change window height NOW */ if (lastwin != firstwin && curwin->w_height < p_wh) {
if (lastwin != firstwin) { win_setheight((int)p_wh);
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_hh) {
else if (pp == &p_wmh) { if (lastwin != firstwin && curbuf->b_help && curwin->w_height < p_hh) {
win_setheight((int)p_hh);
}
} else if (pp == &p_wmh) {
win_setminheight(); win_setminheight();
} else if (pp == &p_wiw) { } 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); win_setwidth((int)p_wiw);
} }
else if (pp == &p_wmw) { } else if (pp == &p_wmw) {
win_setminheight(); win_setminheight();
} else if (pp == &p_ls) { } else if (pp == &p_ls) {
/* (re)set last window status line */ // (re)set last window status line.
last_status(false); last_status(false);
} } else if (pp == &p_stal) {
/* (re)set tab page line */ // (re)set tab page line
else if (pp == &p_stal) { shell_new_rows(); // recompute window positions and heights
shell_new_rows(); /* recompute window positions and heights */ } else if (pp == &curwin->w_p_fdl) {
}
else if (pp == &curwin->w_p_fdl) {
newFoldLevel(); newFoldLevel();
} } else if (pp == &curwin->w_p_fml) {
/* 'foldminlines' */
else if (pp == &curwin->w_p_fml) {
foldUpdateAll(curwin); foldUpdateAll(curwin);
} } else if (pp == &curwin->w_p_fdn) {
/* 'foldnestmax' */ if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin)) {
else if (pp == &curwin->w_p_fdn) {
if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
foldUpdateAll(curwin); foldUpdateAll(curwin);
// 'shiftwidth' or 'tabstop' }
} else if (pp == &curbuf->b_p_sw || pp == (long *)&curbuf->b_p_ts) { } else if (pp == &curbuf->b_p_sw || pp == (long *)&curbuf->b_p_ts) {
// 'shiftwidth' or 'tabstop'
if (foldmethodIsIndent(curwin)) { if (foldmethodIsIndent(curwin)) {
foldUpdateAll(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) { if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0) {
parse_cino(curbuf); parse_cino(curbuf);
} }
} } else if (pp == &p_mco) {
/* 'maxcombine' */ screenclear(); // will re-allocate the screen
else if (pp == &p_mco) {
screenclear(); /* will re-allocate the screen */
} else if (pp == &curbuf->b_p_iminsert) { } else if (pp == &curbuf->b_p_iminsert) {
showmode(); showmode();
/* Show/unshow value of 'keymap' in status lines. */ // Show/unshow value of 'keymap' in status lines.
status_redraw_curbuf(); status_redraw_curbuf();
} } else if (pp == &p_titlelen) {
/* if 'titlelen' has changed, redraw the title */ // if 'titlelen' has changed, redraw the title
else if (pp == &p_titlelen) { if (starting != NO_SCREEN && old_value != p_titlelen) {
if (starting != NO_SCREEN && old_value != p_titlelen)
need_maketitle = TRUE; need_maketitle = TRUE;
} }
/* if p_ch changed value, change the command line height */ } else if (pp == &p_ch) {
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
/* Only compute the new window layout when startup has been // completed. Otherwise the frame sizes may be wrong.
* completed. Otherwise the frame sizes may be wrong. */ if (p_ch != old_value && full_screen) {
if (p_ch != old_value && full_screen
)
command_height(); command_height();
} }
/* when 'updatecount' changes from zero to non-zero, open swap files */ } else if (pp == &p_uc) {
else if (pp == &p_uc) { // when 'updatecount' changes from zero to non-zero, open swap files
if (p_uc && !old_value) if (p_uc && !old_value) {
ml_open_files(); ml_open_files();
} }
/* sync undo before 'undolevels' changes */ } else if (pp == &p_ul || pp == &curbuf->b_p_ul) {
else if (pp == &p_ul) { // sync undo before 'undolevels' changes
/* use the old value, otherwise u_sync() may not work properly */ // use the old value, otherwise u_sync() may not work properly
p_ul = old_value; *pp = old_value;
u_sync(TRUE); u_sync(TRUE);
p_ul = value; *pp = 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) { } else if (pp == &curbuf->b_p_tw) {
FOR_ALL_TAB_WINDOWS(tp, wp) { FOR_ALL_TAB_WINDOWS(tp, wp) {
check_colorcolumn(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) { if (curbuf->terminal) {
// Force the scrollback to take effect. // Force the scrollback to take effect.
terminal_resize(curbuf->terminal, UINT16_MAX, UINT16_MAX); terminal_resize(curbuf->terminal, UINT16_MAX, UINT16_MAX);