comparison src/ops.c @ 26175:6b4f017d7005 v8.2.3619

patch 8.2.3619: cannot use a lambda for 'operatorfunc' Commit: https://github.com/vim/vim/commit/777175b0df8c5ec3cd30d19a2e887e661ac209c8 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Thu Nov 18 22:08:57 2021 +0000 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)
author Bram Moolenaar <Bram@vim.org>
date Thu, 18 Nov 2021 23:15:04 +0100
parents 1d2e1c23e458
children 9a8e9383e4cd
comparison
equal deleted inserted replaced
26174:00e8f1ac9c6d 26175:6b4f017d7005
3303 } 3303 }
3304 3304
3305 // do_cmdline() does the rest 3305 // do_cmdline() does the rest
3306 } 3306 }
3307 3307
3308 // callback function for 'operatorfunc'
3309 static callback_T opfunc_cb;
3310
3311 /*
3312 * Process the 'operatorfunc' option value.
3313 * Returns OK or FAIL.
3314 */
3315 int
3316 set_operatorfunc_option(void)
3317 {
3318 return option_set_callback_func(p_opfunc, &opfunc_cb);
3319 }
3320
3321 #if defined(EXITFREE) || defined(PROTO)
3322 void
3323 free_operatorfunc_option(void)
3324 {
3325 # ifdef FEAT_EVAL
3326 free_callback(&opfunc_cb);
3327 # endif
3328 }
3329 #endif
3330
3308 /* 3331 /*
3309 * Handle the "g@" operator: call 'operatorfunc'. 3332 * Handle the "g@" operator: call 'operatorfunc'.
3310 */ 3333 */
3311 static void 3334 static void
3312 op_function(oparg_T *oap UNUSED) 3335 op_function(oparg_T *oap UNUSED)
3315 typval_T argv[2]; 3338 typval_T argv[2];
3316 int save_virtual_op = virtual_op; 3339 int save_virtual_op = virtual_op;
3317 int save_finish_op = finish_op; 3340 int save_finish_op = finish_op;
3318 pos_T orig_start = curbuf->b_op_start; 3341 pos_T orig_start = curbuf->b_op_start;
3319 pos_T orig_end = curbuf->b_op_end; 3342 pos_T orig_end = curbuf->b_op_end;
3343 typval_T rettv;
3320 3344
3321 if (*p_opfunc == NUL) 3345 if (*p_opfunc == NUL)
3322 emsg(_("E774: 'operatorfunc' is empty")); 3346 emsg(_("E774: 'operatorfunc' is empty"));
3323 else 3347 else
3324 { 3348 {
3343 virtual_op = MAYBE; 3367 virtual_op = MAYBE;
3344 3368
3345 // Reset finish_op so that mode() returns the right value. 3369 // Reset finish_op so that mode() returns the right value.
3346 finish_op = FALSE; 3370 finish_op = FALSE;
3347 3371
3348 (void)call_func_noret(p_opfunc, 1, argv); 3372 if (call_callback(&opfunc_cb, 0, &rettv, 1, argv) != FAIL)
3373 clear_tv(&rettv);
3349 3374
3350 virtual_op = save_virtual_op; 3375 virtual_op = save_virtual_op;
3351 finish_op = save_finish_op; 3376 finish_op = save_finish_op;
3352 if (cmdmod.cmod_flags & CMOD_LOCKMARKS) 3377 if (cmdmod.cmod_flags & CMOD_LOCKMARKS)
3353 { 3378 {