vim-patch:8.2.3619: cannot use a lambda for 'operatorfunc' (#19846)

Problem:    Cannot use a lambda for 'operatorfunc'.
Solution:   Support using a lambda or partial. (Yegappan Lakshmanan,
            closes vim/vim#8775)
777175b0df

Omit duplicate docs. It's removed in patch 8.2.3623.
Nvim doesn't seem to need callback_set() as it was omitted when patch 8.1.1437
was first ported.
This commit is contained in:
zeertzjq
2022-08-20 06:12:02 +08:00
committed by GitHub
parent ebd5720901
commit e8618df7f8
6 changed files with 163 additions and 37 deletions

View File

@@ -6136,6 +6136,23 @@ static void op_colon(oparg_T *oap)
// do_cmdline() does the rest
}
/// callback function for 'operatorfunc'
static Callback opfunc_cb;
/// Process the 'operatorfunc' option value.
/// @return OK or FAIL
int set_operatorfunc_option(void)
{
return option_set_callback_func(p_opfunc, &opfunc_cb);
}
#if defined(EXITFREE)
void free_operatorfunc_option(void)
{
callback_free(&opfunc_cb);
}
#endif
/// Handle the "g@" operator: call 'operatorfunc'.
static void op_function(const oparg_T *oap)
FUNC_ATTR_NONNULL_ALL
@@ -6173,7 +6190,10 @@ static void op_function(const oparg_T *oap)
// Reset finish_op so that mode() returns the right value.
finish_op = false;
(void)call_func_retnr((char *)p_opfunc, 1, argv);
typval_T rettv;
if (callback_call(&opfunc_cb, 1, argv, &rettv) != FAIL) {
tv_clear(&rettv);
}
virtual_op = save_virtual_op;
finish_op = save_finish_op;