mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 22:48:34 +00:00
vim-patch:9.0.1294: the set_bool_option() function is too long
Problem: The set_bool_option() function is too long.
Solution: Move code to separate functions. (Yegappan Lakshmanan,
closes vim/vim#11964)
80b817b749
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
This commit is contained in:
@@ -1996,59 +1996,45 @@ static void apply_optionset_autocmd(int opt_idx, long opt_flags, long oldval, lo
|
|||||||
reset_v_option_vars();
|
reset_v_option_vars();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set the value of a boolean option, taking care of side effects
|
/// Ensure that options set to p_force_on cannot be disabled.
|
||||||
///
|
static const char *did_set_force_on(bool *doskip)
|
||||||
/// @param[in] opt_idx Option index in options[] table.
|
|
||||||
/// @param[out] varp Pointer to the option variable.
|
|
||||||
/// @param[in] value New value.
|
|
||||||
/// @param[in] opt_flags OPT_LOCAL and/or OPT_GLOBAL.
|
|
||||||
///
|
|
||||||
/// @return NULL on success, error message on error.
|
|
||||||
static const char *set_bool_option(const int opt_idx, char *const varp, const int value,
|
|
||||||
const int opt_flags)
|
|
||||||
{
|
{
|
||||||
int old_value = *(int *)varp;
|
if (p_force_on == false) {
|
||||||
int old_global_value = 0;
|
|
||||||
const char *errmsg = NULL;
|
|
||||||
|
|
||||||
// Disallow changing some options from secure mode
|
|
||||||
if ((secure || sandbox != 0)
|
|
||||||
&& (options[opt_idx].flags & P_SECURE)) {
|
|
||||||
return e_secure;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Save the global value before changing anything. This is needed as for
|
|
||||||
// a global-only option setting the "local value" in fact sets the global
|
|
||||||
// value (since there is only one value).
|
|
||||||
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) {
|
|
||||||
old_global_value = *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
|
|
||||||
}
|
|
||||||
|
|
||||||
*(int *)varp = value; // set the new value
|
|
||||||
// Remember where the option was set.
|
|
||||||
set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
|
|
||||||
|
|
||||||
// May set global value for local option.
|
|
||||||
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) {
|
|
||||||
*(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure that options set to p_force_on cannot be disabled.
|
|
||||||
if ((int *)varp == &p_force_on && p_force_on == false) {
|
|
||||||
p_force_on = true;
|
p_force_on = true;
|
||||||
|
*doskip = true;
|
||||||
return e_unsupportedoption;
|
return e_unsupportedoption;
|
||||||
// Ensure that options set to p_force_off cannot be enabled.
|
}
|
||||||
} else if ((int *)varp == &p_force_off && p_force_off == true) {
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Ensure that options set to p_force_off cannot be enabled.
|
||||||
|
static const char *did_set_force_off(bool *doskip)
|
||||||
|
{
|
||||||
|
if (p_force_off == true) {
|
||||||
p_force_off = false;
|
p_force_off = false;
|
||||||
|
*doskip = true;
|
||||||
return e_unsupportedoption;
|
return e_unsupportedoption;
|
||||||
} else if ((int *)varp == &p_lrm) {
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'langremap' option value.
|
||||||
|
static void did_set_langremap(void)
|
||||||
|
{
|
||||||
// 'langremap' -> !'langnoremap'
|
// 'langremap' -> !'langnoremap'
|
||||||
p_lnr = !p_lrm;
|
p_lnr = !p_lrm;
|
||||||
} else if ((int *)varp == &p_lnr) {
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'langnoremap' option value.
|
||||||
|
static void did_set_langnoremap(void)
|
||||||
|
{
|
||||||
// 'langnoremap' -> !'langremap'
|
// 'langnoremap' -> !'langremap'
|
||||||
p_lrm = !p_lnr;
|
p_lrm = !p_lnr;
|
||||||
} else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf) {
|
}
|
||||||
// 'undofile'
|
|
||||||
|
/// Process the updated 'undofile' option value.
|
||||||
|
static void did_set_undofile(int opt_flags)
|
||||||
|
{
|
||||||
// Only take action when the option was set. When reset we do not
|
// Only take action when the option was set. When reset we do not
|
||||||
// delete the undo file, the option may be set again without making
|
// delete the undo file, the option may be set again without making
|
||||||
// any changes in between.
|
// any changes in between.
|
||||||
@@ -2068,7 +2054,11 @@ static const char *set_bool_option(const int opt_idx, char *const varp, const in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ((int *)varp == &curbuf->b_p_ro) {
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'readonly' option value.
|
||||||
|
static void did_set_readonly(int opt_flags)
|
||||||
|
{
|
||||||
// when 'readonly' is reset globally, also reset readonlymode
|
// when 'readonly' is reset globally, also reset readonlymode
|
||||||
if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0) {
|
if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0) {
|
||||||
readonlymode = false;
|
readonlymode = false;
|
||||||
@@ -2080,25 +2070,46 @@ static const char *set_bool_option(const int opt_idx, char *const varp, const in
|
|||||||
}
|
}
|
||||||
|
|
||||||
redraw_titles();
|
redraw_titles();
|
||||||
} else if ((int *)varp == &curbuf->b_p_ma) {
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'modifiable' option value.
|
||||||
|
static char *did_set_modifiable(void)
|
||||||
|
{
|
||||||
// when 'modifiable' is changed, redraw the window title
|
// when 'modifiable' is changed, redraw the window title
|
||||||
redraw_titles();
|
redraw_titles();
|
||||||
} else if ((int *)varp == &curbuf->b_p_eof
|
|
||||||
|| (int *)varp == &curbuf->b_p_eol
|
return NULL;
|
||||||
|| (int *)varp == &curbuf->b_p_fixeol
|
}
|
||||||
|| (int *)varp == &curbuf->b_p_bomb) {
|
|
||||||
// redraw the window title and tab page text when 'endoffile', 'endofline',
|
/// Process the updated 'endoffile' or 'endofline' or 'fixendofline' or 'bomb'
|
||||||
// 'fixeol' or 'bomb' is changed
|
/// option value.
|
||||||
|
static void did_set_eof_eol_fixeol_bomb(void)
|
||||||
|
{
|
||||||
|
// redraw the window title and tab page text
|
||||||
redraw_titles();
|
redraw_titles();
|
||||||
} else if ((int *)varp == &curbuf->b_p_bin) {
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'binary' option value.
|
||||||
|
static void did_set_binary(int opt_flags, long old_value)
|
||||||
|
{
|
||||||
// when 'bin' is set also set some other options
|
// when 'bin' is set also set some other options
|
||||||
set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
|
set_options_bin((int)old_value, curbuf->b_p_bin, opt_flags);
|
||||||
redraw_titles();
|
redraw_titles();
|
||||||
} else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl) {
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'buflisted' option value.
|
||||||
|
static void did_set_buflisted(long old_value)
|
||||||
|
{
|
||||||
// when 'buflisted' changes, trigger autocommands
|
// when 'buflisted' changes, trigger autocommands
|
||||||
|
if (old_value != curbuf->b_p_bl) {
|
||||||
apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
|
apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
|
||||||
NULL, NULL, true, curbuf);
|
NULL, NULL, true, curbuf);
|
||||||
} else if ((int *)varp == &curbuf->b_p_swf) {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'swapfile' option value.
|
||||||
|
static void did_set_swapfile(void)
|
||||||
|
{
|
||||||
// when 'swf' is set, create swapfile, when reset remove swapfile
|
// when 'swf' is set, create swapfile, when reset remove swapfile
|
||||||
if (curbuf->b_p_swf && p_uc) {
|
if (curbuf->b_p_swf && p_uc) {
|
||||||
ml_open_file(curbuf); // create the swap file
|
ml_open_file(curbuf); // create the swap file
|
||||||
@@ -2107,50 +2118,89 @@ static const char *set_bool_option(const int opt_idx, char *const varp, const in
|
|||||||
// buf->b_p_swf
|
// buf->b_p_swf
|
||||||
mf_close_file(curbuf, true); // remove the swap file
|
mf_close_file(curbuf, true); // remove the swap file
|
||||||
}
|
}
|
||||||
} else if ((int *)varp == &p_paste) {
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'paste' option value.
|
||||||
|
static void did_set_paste(void)
|
||||||
|
{
|
||||||
// when 'paste' is set or reset also change other options
|
// when 'paste' is set or reset also change other options
|
||||||
paste_option_changed();
|
paste_option_changed();
|
||||||
} else if ((int *)varp == &p_ic && p_hls) {
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'ignorecase' option value.
|
||||||
|
static void did_set_ignorecase(void)
|
||||||
|
{
|
||||||
// when 'ignorecase' is set or reset and 'hlsearch' is set, redraw
|
// when 'ignorecase' is set or reset and 'hlsearch' is set, redraw
|
||||||
|
if (p_hls) {
|
||||||
redraw_all_later(UPD_SOME_VALID);
|
redraw_all_later(UPD_SOME_VALID);
|
||||||
} else if ((int *)varp == &p_hls) {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'hlsearch' option value.
|
||||||
|
static void did_set_hlsearch(void)
|
||||||
|
{
|
||||||
// when 'hlsearch' is set or reset: reset no_hlsearch
|
// when 'hlsearch' is set or reset: reset no_hlsearch
|
||||||
set_no_hlsearch(false);
|
set_no_hlsearch(false);
|
||||||
} else if ((int *)varp == &curwin->w_p_scb) {
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'scrollbind' option value.
|
||||||
|
static void did_set_scrollbind(void)
|
||||||
|
{
|
||||||
// when 'scrollbind' is set: snapshot the current position to avoid a jump
|
// when 'scrollbind' is set: snapshot the current position to avoid a jump
|
||||||
// at the end of normal_cmd()
|
// at the end of normal_cmd()
|
||||||
if (curwin->w_p_scb) {
|
if (curwin->w_p_scb) {
|
||||||
do_check_scrollbind(false);
|
do_check_scrollbind(false);
|
||||||
curwin->w_scbind_pos = curwin->w_topline;
|
curwin->w_scbind_pos = curwin->w_topline;
|
||||||
}
|
}
|
||||||
} else if ((int *)varp == &curwin->w_p_pvw) {
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'previewwindow' option value.
|
||||||
|
static const char *did_set_previewwindow(bool *doskip)
|
||||||
|
{
|
||||||
|
if (!curwin->w_p_pvw) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// There can be only one window with 'previewwindow' set.
|
// There can be only one window with 'previewwindow' set.
|
||||||
if (curwin->w_p_pvw) {
|
|
||||||
FOR_ALL_WINDOWS_IN_TAB(win, curtab) {
|
FOR_ALL_WINDOWS_IN_TAB(win, curtab) {
|
||||||
if (win->w_p_pvw && win != curwin) {
|
if (win->w_p_pvw && win != curwin) {
|
||||||
curwin->w_p_pvw = false;
|
curwin->w_p_pvw = false;
|
||||||
|
*doskip = true;
|
||||||
return e_preview_window_already_exists;
|
return e_preview_window_already_exists;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else if (varp == (char *)&(curbuf->b_p_lisp)) {
|
return NULL;
|
||||||
// When 'lisp' option changes include/exclude '-' in
|
}
|
||||||
// keyword characters.
|
|
||||||
|
/// Process the updated 'lisp' option value.
|
||||||
|
static void did_set_lisp(void)
|
||||||
|
{
|
||||||
|
// When 'lisp' option changes include/exclude '-' in keyword characters.
|
||||||
(void)buf_init_chartab(curbuf, false); // ignore errors
|
(void)buf_init_chartab(curbuf, false); // ignore errors
|
||||||
} else if ((int *)varp == &p_title) {
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'title' or the 'icon' option value.
|
||||||
|
static void did_set_title_icon(void)
|
||||||
|
{
|
||||||
// when 'title' changed, may need to change the title; same for 'icon'
|
// when 'title' changed, may need to change the title; same for 'icon'
|
||||||
did_set_title();
|
did_set_title();
|
||||||
} else if ((int *)varp == &p_icon) {
|
}
|
||||||
did_set_title();
|
|
||||||
} else if ((int *)varp == &curbuf->b_changed) {
|
/// Process the updated 'modified' option value.
|
||||||
|
static void did_set_modified(long value)
|
||||||
|
{
|
||||||
if (!value) {
|
if (!value) {
|
||||||
save_file_ff(curbuf); // Buffer is unchanged
|
save_file_ff(curbuf); // Buffer is unchanged
|
||||||
}
|
}
|
||||||
redraw_titles();
|
redraw_titles();
|
||||||
modified_was_set = value;
|
modified_was_set = (int)value;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef BACKSLASH_IN_FILENAME
|
#ifdef BACKSLASH_IN_FILENAME
|
||||||
} else if ((int *)varp == &p_ssl) {
|
/// Process the updated 'shellslash' option value.
|
||||||
|
static void did_set_shellslash(void)
|
||||||
|
{
|
||||||
if (p_ssl) {
|
if (p_ssl) {
|
||||||
psepc = '/';
|
psepc = '/';
|
||||||
psepcN = '\\';
|
psepcN = '\\';
|
||||||
@@ -2165,35 +2215,57 @@ static const char *set_bool_option(const int opt_idx, char *const varp, const in
|
|||||||
buflist_slash_adjust();
|
buflist_slash_adjust();
|
||||||
alist_slash_adjust();
|
alist_slash_adjust();
|
||||||
scriptnames_slash_adjust();
|
scriptnames_slash_adjust();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if ((int *)varp == &curwin->w_p_wrap) {
|
|
||||||
|
/// Process the updated 'wrap' option value.
|
||||||
|
static void did_set_wrap(void)
|
||||||
|
{
|
||||||
// If 'wrap' is set, set w_leftcol to zero.
|
// If 'wrap' is set, set w_leftcol to zero.
|
||||||
if (curwin->w_p_wrap) {
|
if (curwin->w_p_wrap) {
|
||||||
curwin->w_leftcol = 0;
|
curwin->w_leftcol = 0;
|
||||||
}
|
}
|
||||||
} else if ((int *)varp == &p_ea) {
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'equalalways' option value.
|
||||||
|
static void did_set_equalalways(long old_value)
|
||||||
|
{
|
||||||
if (p_ea && !old_value) {
|
if (p_ea && !old_value) {
|
||||||
win_equal(curwin, false, 0);
|
win_equal(curwin, false, 0);
|
||||||
}
|
}
|
||||||
} else if ((int *)varp == &p_acd) {
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'autochdir' option value.
|
||||||
|
static void did_set_autochdir(void)
|
||||||
|
{
|
||||||
// Change directories when the 'acd' option is set now.
|
// Change directories when the 'acd' option is set now.
|
||||||
do_autochdir();
|
do_autochdir();
|
||||||
} else if ((int *)varp == &curwin->w_p_diff) { // 'diff'
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'diff' option value.
|
||||||
|
static void did_set_diff(void)
|
||||||
|
{
|
||||||
// May add or remove the buffer from the list of diff buffers.
|
// May add or remove the buffer from the list of diff buffers.
|
||||||
diff_buf_adjust(curwin);
|
diff_buf_adjust(curwin);
|
||||||
if (foldmethodIsDiff(curwin)) {
|
if (foldmethodIsDiff(curwin)) {
|
||||||
foldUpdateAll(curwin);
|
foldUpdateAll(curwin);
|
||||||
}
|
}
|
||||||
} else if ((int *)varp == &curwin->w_p_spell) { // 'spell'
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'spell' option value.
|
||||||
|
static char *did_set_spell(void)
|
||||||
|
{
|
||||||
if (curwin->w_p_spell) {
|
if (curwin->w_p_spell) {
|
||||||
errmsg = did_set_spelllang(curwin);
|
return did_set_spelllang(curwin);
|
||||||
}
|
|
||||||
} else if ((int *)varp == &curwin->w_p_nu && *curwin->w_p_stc != NUL) {
|
|
||||||
// When 'number' is changed and 'statuscolumn' is set, make sure width is reset.
|
|
||||||
curwin->w_nrwidth_line_count = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((int *)varp == &curwin->w_p_arab) {
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Process the updated 'arabic' option value.
|
||||||
|
static const char *did_set_arabic(void)
|
||||||
|
{
|
||||||
|
const char *errmsg = NULL;
|
||||||
if (curwin->w_p_arab) {
|
if (curwin->w_p_arab) {
|
||||||
// 'arabic' is set, handle various sub-settings.
|
// 'arabic' is set, handle various sub-settings.
|
||||||
if (!p_tbidi) {
|
if (!p_tbidi) {
|
||||||
@@ -2245,9 +2317,133 @@ static const char *set_bool_option(const int opt_idx, char *const varp, const in
|
|||||||
curbuf->b_p_iminsert = B_IMODE_NONE;
|
curbuf->b_p_iminsert = B_IMODE_NONE;
|
||||||
curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
|
curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return errmsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void did_set_number_relativenumber(void)
|
||||||
|
{
|
||||||
|
if (*curwin->w_p_stc != NUL) {
|
||||||
|
// When 'relativenumber'/'number' is changed and 'statuscolumn' is set, reset width.
|
||||||
|
curwin->w_nrwidth_line_count = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// When some boolean options are changed, need to take some action.
|
||||||
|
static const char *did_set_bool_option(const char *varp, int opt_flags, long value, long old_value,
|
||||||
|
bool *doskip)
|
||||||
|
{
|
||||||
|
const char *errmsg = NULL;
|
||||||
|
|
||||||
|
if ((int *)varp == &p_force_on) {
|
||||||
|
errmsg = did_set_force_on(doskip);
|
||||||
|
} else if ((int *)varp == &p_force_off) {
|
||||||
|
errmsg = did_set_force_off(doskip);
|
||||||
|
} else if ((int *)varp == &p_lrm) { // 'langremap'
|
||||||
|
did_set_langremap();
|
||||||
|
} else if ((int *)varp == &p_lnr) { // 'langnoremap'
|
||||||
|
did_set_langnoremap();
|
||||||
|
} else if ((int *)varp == &curbuf->b_p_udf // buffer local 'undofile'
|
||||||
|
|| (int *)varp == &p_udf) { // 'undofile'
|
||||||
|
did_set_undofile(opt_flags);
|
||||||
|
} else if ((int *)varp == &curbuf->b_p_ro) { // 'readonly'
|
||||||
|
did_set_readonly(opt_flags);
|
||||||
|
} else if ((int *)varp == &curbuf->b_p_ma) {
|
||||||
|
errmsg = did_set_modifiable(); // 'modifiable'
|
||||||
|
} else if ((int *)varp == &curbuf->b_p_eof // 'endoffile'
|
||||||
|
|| (int *)varp == &curbuf->b_p_eol // 'endofline'
|
||||||
|
|| (int *)varp == &curbuf->b_p_fixeol // 'fixendofline'
|
||||||
|
|| (int *)varp == &curbuf->b_p_bomb) { // 'bomb'
|
||||||
|
did_set_eof_eol_fixeol_bomb();
|
||||||
|
} else if ((int *)varp == &curbuf->b_p_bin) { // 'binary'
|
||||||
|
did_set_binary(opt_flags, old_value);
|
||||||
|
} else if ((int *)varp == &curbuf->b_p_bl) { // 'buflisted'
|
||||||
|
did_set_buflisted(old_value);
|
||||||
|
} else if ((int *)varp == &curbuf->b_p_swf) { // 'swapfile'
|
||||||
|
did_set_swapfile();
|
||||||
|
} else if ((int *)varp == &p_paste) { // 'paste'
|
||||||
|
did_set_paste();
|
||||||
|
} else if ((int *)varp == &p_ic) { // 'ignorecase'
|
||||||
|
did_set_ignorecase();
|
||||||
|
} else if ((int *)varp == &p_hls) { // 'hlsearch'
|
||||||
|
did_set_hlsearch();
|
||||||
|
} else if ((int *)varp == &curwin->w_p_scb) { // 'scrollbind'
|
||||||
|
did_set_scrollbind();
|
||||||
|
} else if ((int *)varp == &curwin->w_p_pvw) { // 'previewwindow'
|
||||||
|
errmsg = did_set_previewwindow(doskip);
|
||||||
|
} else if (varp == (char *)&(curbuf->b_p_lisp)) { // 'lisp'
|
||||||
|
did_set_lisp();
|
||||||
|
} else if ((int *)varp == &p_title // 'title'
|
||||||
|
|| (int *)varp == &p_icon) { // 'icon'
|
||||||
|
did_set_title_icon();
|
||||||
|
} else if ((int *)varp == &curbuf->b_changed) { // 'modified'
|
||||||
|
did_set_modified(value);
|
||||||
|
#ifdef BACKSLASH_IN_FILENAME
|
||||||
|
} else if ((int *)varp == &p_ssl) { // 'shellslash'
|
||||||
|
did_set_shellslash();
|
||||||
|
#endif
|
||||||
|
} else if ((int *)varp == &curwin->w_p_wrap) { // 'wrap'
|
||||||
|
did_set_wrap();
|
||||||
|
} else if ((int *)varp == &p_ea) { // 'equalalways'
|
||||||
|
did_set_equalalways(old_value);
|
||||||
|
} else if ((int *)varp == &p_acd) { // 'autochdir'
|
||||||
|
did_set_autochdir();
|
||||||
|
} else if ((int *)varp == &curwin->w_p_diff) { // 'diff'
|
||||||
|
did_set_diff();
|
||||||
|
} else if ((int *)varp == &curwin->w_p_spell) { // 'spell'
|
||||||
|
errmsg = did_set_spell();
|
||||||
|
} else if ((int *)varp == &curwin->w_p_arab) { // 'arabic'
|
||||||
|
errmsg = did_set_arabic();
|
||||||
|
} else if ((int *)varp == &curwin->w_p_nu // 'number'
|
||||||
|
|| (int *)varp == &curwin->w_p_rnu) { // 'relativenumber'
|
||||||
|
did_set_number_relativenumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
// End of handling side effects for bool options.
|
return errmsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the value of a boolean option, taking care of side effects
|
||||||
|
///
|
||||||
|
/// @param[in] opt_idx Option index in options[] table.
|
||||||
|
/// @param[out] varp Pointer to the option variable.
|
||||||
|
/// @param[in] value New value.
|
||||||
|
/// @param[in] opt_flags OPT_LOCAL and/or OPT_GLOBAL.
|
||||||
|
///
|
||||||
|
/// @return NULL on success, error message on error.
|
||||||
|
static const char *set_bool_option(const int opt_idx, char *const varp, const int value,
|
||||||
|
const int opt_flags)
|
||||||
|
{
|
||||||
|
int old_value = *(int *)varp;
|
||||||
|
int old_global_value = 0;
|
||||||
|
|
||||||
|
// Disallow changing some options from secure mode
|
||||||
|
if ((secure || sandbox != 0)
|
||||||
|
&& (options[opt_idx].flags & P_SECURE)) {
|
||||||
|
return e_secure;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save the global value before changing anything. This is needed as for
|
||||||
|
// a global-only option setting the "local value" in fact sets the global
|
||||||
|
// value (since there is only one value).
|
||||||
|
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) {
|
||||||
|
old_global_value = *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
*(int *)varp = value; // set the new value
|
||||||
|
// Remember where the option was set.
|
||||||
|
set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
|
||||||
|
|
||||||
|
// May set global value for local option.
|
||||||
|
if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0) {
|
||||||
|
*(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle side effects for changing a bool option.
|
||||||
|
bool doskip = false;
|
||||||
|
const char *errmsg = did_set_bool_option(varp, opt_flags, value, old_value, &doskip);
|
||||||
|
if (doskip) {
|
||||||
|
return errmsg;
|
||||||
|
}
|
||||||
|
|
||||||
// after handling side effects, call autocommand
|
// after handling side effects, call autocommand
|
||||||
|
|
||||||
@@ -3811,6 +4007,13 @@ char *get_varp_scope(vimoption_T *p, int scope)
|
|||||||
return get_varp_scope_from(p, scope, curbuf, curwin);
|
return get_varp_scope_from(p, scope, curbuf, curwin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get pointer to option variable at 'opt_idx', depending on local or global
|
||||||
|
/// scope.
|
||||||
|
char *get_option_varp_scope_from(int opt_idx, int scope, buf_T *buf, win_T *win)
|
||||||
|
{
|
||||||
|
return get_varp_scope_from(&(options[opt_idx]), scope, buf, win);
|
||||||
|
}
|
||||||
|
|
||||||
static char *get_varp_from(vimoption_T *p, buf_T *buf, win_T *win)
|
static char *get_varp_from(vimoption_T *p, buf_T *buf, win_T *win)
|
||||||
{
|
{
|
||||||
// hidden option, always return NULL
|
// hidden option, always return NULL
|
||||||
|
Reference in New Issue
Block a user