refactor(optionstr.c): break up did_set_string_option 25

This commit is contained in:
Lewis Russell
2023-01-19 10:34:54 +00:00
parent 12d065dceb
commit 7fa7c758e2

View File

@@ -1247,6 +1247,32 @@ static void did_set_filetype(buf_T *buf, char **varp, int opt_flags, bool value_
} }
} }
static void did_set_spelllang_source(win_T *win)
{
char fname[200];
char *q = win->w_s->b_p_spl;
// Skip the first name if it is "cjk".
if (strncmp(q, "cjk,", 4) == 0) {
q += 4;
}
// Source the spell/LANG.vim in 'runtimepath'.
// They could set 'spellcapcheck' depending on the language.
// Use the first name in 'spelllang' up to '_region' or
// '.encoding'.
char *p;
for (p = q; *p != NUL; p++) {
if (!ASCII_ISALNUM(*p) && *p != '-') {
break;
}
}
if (p > q) {
vim_snprintf(fname, sizeof(fname), "spell/%.*s.vim", (int)(p - q), q);
source_runtime(fname, DIP_ALL);
}
}
/// Handle string options that need some action to perform when changed. /// Handle string options that need some action to perform when changed.
/// The new value must be allocated. /// The new value must be allocated.
/// ///
@@ -1765,30 +1791,8 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf
did_set_syntax(curbuf, value_changed); did_set_syntax(curbuf, value_changed);
} else if (varp == &(curbuf->b_p_ft)) { } else if (varp == &(curbuf->b_p_ft)) {
did_set_filetype(curbuf, varp, opt_flags, value_changed); did_set_filetype(curbuf, varp, opt_flags, value_changed);
} } else if (varp == &(curwin->w_s->b_p_spl)) {
if (varp == &(curwin->w_s->b_p_spl)) { did_set_spelllang_source(curwin);
char fname[200];
char *q = curwin->w_s->b_p_spl;
// Skip the first name if it is "cjk".
if (strncmp(q, "cjk,", 4) == 0) {
q += 4;
}
// Source the spell/LANG.vim in 'runtimepath'.
// They could set 'spellcapcheck' depending on the language.
// Use the first name in 'spelllang' up to '_region' or
// '.encoding'.
char *p;
for (p = q; *p != NUL; p++) {
if (!ASCII_ISALNUM(*p) && *p != '-') {
break;
}
}
if (p > q) {
vim_snprintf(fname, sizeof(fname), "spell/%.*s.vim", (int)(p - q), q);
source_runtime(fname, DIP_ALL);
}
} }
} }