Merge pull request #21885 from lewis6991/refactor/options

Problems:
    - Scope of local variables in options code is too large.
    - did_set_string_option() is too large (>1000LOC).
    - Setting options for a particular window or buffer requires a changing context (assigning curwin/curbuf).

Solutions:
    - Reduce the scope of local variables.
    - Break up did_set_string_option so it doesn't contain specific logic about each individual option (1038 LOC -> 310 LOC).
    - Begin work on making functions not depend on curbuf or curwin and pass window or buffer handles explicitly.
This commit is contained in:
Lewis Russell 2023-01-25 13:46:23 +00:00 committed by GitHub
commit e2a9d71521
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 1472 additions and 1240 deletions

View File

@ -3474,7 +3474,7 @@ static void ins_ctrl_hat(void)
State |= MODE_LANGMAP;
}
}
set_iminsert_global();
set_iminsert_global(curbuf);
showmode();
// Show/unshow value of 'keymap' in status lines.
status_redraw_curbuf();

View File

@ -1557,9 +1557,9 @@ static void command_line_toggle_langmap(CommandLineState *s)
if (s->b_im_ptr != NULL) {
if (s->b_im_ptr == &curbuf->b_p_iminsert) {
set_iminsert_global();
set_iminsert_global(curbuf);
} else {
set_imsearch_global();
set_imsearch_global(curbuf);
}
}
ui_cursor_shape(); // may show different cursor shape

View File

@ -2258,14 +2258,14 @@ static void copy_global_to_buflocal_cb(Callback *globcb, Callback *bufcb)
/// Invoked when the 'completefunc' option is set. The option value can be a
/// name of a function (string), or function(<name>) or funcref(<name>) or a
/// lambda expression.
int set_completefunc_option(void)
void set_completefunc_option(char **errmsg)
{
int retval = option_set_callback_func(curbuf->b_p_cfu, &cfu_cb);
if (retval == OK) {
set_buflocal_cfu_callback(curbuf);
if (option_set_callback_func(curbuf->b_p_cfu, &cfu_cb) == FAIL) {
*errmsg = e_invarg;
return;
}
return retval;
set_buflocal_cfu_callback(curbuf);
}
/// Copy the global 'completefunc' callback function to the buffer-local
@ -2279,14 +2279,13 @@ void set_buflocal_cfu_callback(buf_T *buf)
/// Invoked when the 'omnifunc' option is set. The option value can be a
/// name of a function (string), or function(<name>) or funcref(<name>) or a
/// lambda expression.
int set_omnifunc_option(void)
void set_omnifunc_option(buf_T *buf, char **errmsg)
{
int retval = option_set_callback_func(curbuf->b_p_ofu, &ofu_cb);
if (retval == OK) {
set_buflocal_ofu_callback(curbuf);
if (option_set_callback_func(buf->b_p_ofu, &ofu_cb) == FAIL) {
*errmsg = e_invarg;
return;
}
return retval;
set_buflocal_ofu_callback(buf);
}
/// Copy the global 'omnifunc' callback function to the buffer-local 'omnifunc'
@ -2300,7 +2299,7 @@ void set_buflocal_ofu_callback(buf_T *buf)
/// Invoked when the 'thesaurusfunc' option is set. The option value can be a
/// name of a function (string), or function(<name>) or funcref(<name>) or a
/// lambda expression.
int set_thesaurusfunc_option(void)
void set_thesaurusfunc_option(char **errmsg)
{
int retval;
@ -2312,7 +2311,9 @@ int set_thesaurusfunc_option(void)
retval = option_set_callback_func(p_tsrfu, &tsrfu_cb);
}
return retval;
if (retval == FAIL) {
*errmsg = e_invarg;
}
}
/// Mark the global 'completefunc' 'omnifunc' and 'thesaurusfunc' callbacks with

View File

@ -5626,10 +5626,11 @@ static void op_colon(oparg_T *oap)
static Callback opfunc_cb;
/// Process the 'operatorfunc' option value.
/// @return OK or FAIL
int set_operatorfunc_option(void)
void set_operatorfunc_option(char **errmsg)
{
return option_set_callback_func(p_opfunc, &opfunc_cb);
if (option_set_callback_func(p_opfunc, &opfunc_cb) == FAIL) {
*errmsg = e_invarg;
}
}
#if defined(EXITFREE)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -3854,10 +3854,11 @@ static buf_T *qf_find_buf(qf_info_T *qi)
}
/// Process the 'quickfixtextfunc' option value.
/// @return OK or FAIL
int qf_process_qftf_option(void)
void qf_process_qftf_option(char **errmsg)
{
return option_set_callback_func(p_qftf, &qftf_cb);
if (option_set_callback_func(p_qftf, &qftf_cb) == FAIL) {
*errmsg = e_invarg;
}
}
/// Update the w:quickfix_title variable in the quickfix/location list window in

View File

@ -210,22 +210,20 @@ static Callback tfu_cb; // 'tagfunc' callback function
/// Reads the 'tagfunc' option value and convert that to a callback value.
/// Invoked when the 'tagfunc' option is set. The option value can be a name of
/// a function (string), or function(<name>) or funcref(<name>) or a lambda.
int set_tagfunc_option(void)
void set_tagfunc_option(char **errmsg)
{
callback_free(&tfu_cb);
callback_free(&curbuf->b_tfu_cb);
if (*curbuf->b_p_tfu == NUL) {
return OK;
return;
}
if (option_set_callback_func(curbuf->b_p_tfu, &tfu_cb) == FAIL) {
return FAIL;
*errmsg = e_invarg;
}
callback_copy(&curbuf->b_tfu_cb, &tfu_cb);
return OK;
}
#if defined(EXITFREE)