diff options
author | Lewis Russell <lewis6991@gmail.com> | 2023-01-19 09:54:37 +0000 |
---|---|---|
committer | Lewis Russell <lewis6991@gmail.com> | 2023-01-25 11:48:52 +0000 |
commit | 5ec8bb73c268b8f23fe70374863ba3bafc036b22 (patch) | |
tree | c048f30610fb9ad10834049d53cea100d175164c | |
parent | e334f5a57d3d00d4fc6ca0aeca8a6254e7e5da81 (diff) | |
download | rneovim-5ec8bb73c268b8f23fe70374863ba3bafc036b22.tar.gz rneovim-5ec8bb73c268b8f23fe70374863ba3bafc036b22.tar.bz2 rneovim-5ec8bb73c268b8f23fe70374863ba3bafc036b22.zip |
refactor(optionstr.c): break up did_set_string_option 5
-rw-r--r-- | src/nvim/optionstr.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index dcefd450ca..b1ae2fd409 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -704,6 +704,29 @@ static void did_set_helplang(char **errmsg) } } +static void did_set_background(char **errmsg) +{ + if (check_opt_strings(p_bg, p_bg_values, false) != OK) { + *errmsg = e_invarg; + return; + } + + int dark = (*p_bg == 'd'); + + init_highlight(false, false); + + if (dark != (*p_bg == 'd') && get_var_value("g:colors_name") != NULL) { + // The color scheme must have set 'background' back to another + // value, that's not what we want here. Disable the color + // scheme and set the colors again. + do_unlet(S_LEN("g:colors_name"), true); + free_string_option(p_bg); + p_bg = xstrdup((dark ? "dark" : "light")); + check_string_option(&p_bg); + init_highlight(false, false); + } +} + /// Handle string options that need some action to perform when changed. /// The new value must be allocated. /// @@ -814,24 +837,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf errmsg = check_chars_options(); } } else if (varp == &p_bg) { // 'background' - if (check_opt_strings(p_bg, p_bg_values, false) == OK) { - int dark = (*p_bg == 'd'); - - init_highlight(false, false); - - if (dark != (*p_bg == 'd') && get_var_value("g:colors_name") != NULL) { - // The color scheme must have set 'background' back to another - // value, that's not what we want here. Disable the color - // scheme and set the colors again. - do_unlet(S_LEN("g:colors_name"), true); - free_string_option(p_bg); - p_bg = xstrdup((dark ? "dark" : "light")); - check_string_option(&p_bg); - init_highlight(false, false); - } - } else { - errmsg = e_invarg; - } + did_set_background(&errmsg); } else if (varp == &p_wim) { // 'wildmode' if (check_opt_wim() == FAIL) { errmsg = e_invarg; |