From 777175b0df8c5ec3cd30d19a2e887e661ac209c8 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Thu, 18 Nov 2021 22:08:57 +0000 Subject: 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) --- src/ops.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/ops.c') diff --git a/src/ops.c b/src/ops.c index 5a4855014..aa3b5dec4 100644 --- a/src/ops.c +++ b/src/ops.c @@ -3305,6 +3305,29 @@ op_colon(oparg_T *oap) // do_cmdline() does the rest } +// callback function for 'operatorfunc' +static callback_T opfunc_cb; + +/* + * Process the 'operatorfunc' option value. + * Returns OK or FAIL. + */ + int +set_operatorfunc_option(void) +{ + return option_set_callback_func(p_opfunc, &opfunc_cb); +} + +#if defined(EXITFREE) || defined(PROTO) + void +free_operatorfunc_option(void) +{ +# ifdef FEAT_EVAL + free_callback(&opfunc_cb); +# endif +} +#endif + /* * Handle the "g@" operator: call 'operatorfunc'. */ @@ -3317,6 +3340,7 @@ op_function(oparg_T *oap UNUSED) int save_finish_op = finish_op; pos_T orig_start = curbuf->b_op_start; pos_T orig_end = curbuf->b_op_end; + typval_T rettv; if (*p_opfunc == NUL) emsg(_("E774: 'operatorfunc' is empty")); @@ -3345,7 +3369,8 @@ op_function(oparg_T *oap UNUSED) // Reset finish_op so that mode() returns the right value. finish_op = FALSE; - (void)call_func_noret(p_opfunc, 1, argv); + if (call_callback(&opfunc_cb, 0, &rettv, 1, argv) != FAIL) + clear_tv(&rettv); virtual_op = save_virtual_op; finish_op = save_finish_op; -- cgit v1.2.1