From e8618df7f826d2ca4d524f12fc712d7c52ea158c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 20 Aug 2022 06:12:02 +0800 Subject: 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) https://github.com/vim/vim/commit/777175b0df8c5ec3cd30d19a2e887e661ac209c8 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. --- src/nvim/ops.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index c3edc5b315..b4fc7534bc 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -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; -- cgit