forked from aniani/vim
patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Problem: Cannot use a lambda for 'operatorfunc'. Solution: Support using a lambda or partial. (Yegappan Lakshmanan, closes #8775)
This commit is contained in:
committed by
Bram Moolenaar
parent
851c7a699a
commit
777175b0df
47
src/option.c
47
src/option.c
@@ -809,6 +809,7 @@ free_all_options(void)
|
||||
// buffer-local option: free global value
|
||||
clear_string_option((char_u **)options[i].var);
|
||||
}
|
||||
free_operatorfunc_option();
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -7184,3 +7185,49 @@ magic_isset(void)
|
||||
#endif
|
||||
return p_magic;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the callback function value for an option that accepts a function name,
|
||||
* lambda, et al. (e.g. 'operatorfunc', 'tagfunc', etc.)
|
||||
* Returns OK if the option is successfully set to a function, otherwise
|
||||
* returns FAIL.
|
||||
*/
|
||||
int
|
||||
option_set_callback_func(char_u *optval UNUSED, callback_T *optcb UNUSED)
|
||||
{
|
||||
#ifdef FEAT_EVAL
|
||||
typval_T *tv;
|
||||
callback_T cb;
|
||||
|
||||
if (optval == NULL || *optval == NUL)
|
||||
{
|
||||
free_callback(optcb);
|
||||
return OK;
|
||||
}
|
||||
|
||||
if (*optval == '{'
|
||||
|| (STRNCMP(optval, "function(", 9) == 0)
|
||||
|| (STRNCMP(optval, "funcref(", 8) == 0))
|
||||
// Lambda expression or a funcref
|
||||
tv = eval_expr(optval, NULL);
|
||||
else
|
||||
// treat everything else as a function name string
|
||||
tv = alloc_string_tv(vim_strsave(optval));
|
||||
if (tv == NULL)
|
||||
return FAIL;
|
||||
|
||||
cb = get_callback(tv);
|
||||
if (cb.cb_name == NULL)
|
||||
{
|
||||
free_tv(tv);
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
free_callback(optcb);
|
||||
set_callback(optcb, &cb);
|
||||
free_tv(tv);
|
||||
return OK;
|
||||
#else
|
||||
return FAIL;
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user