Problem: Vim9: error when using 'opfunc'.
Solution: Do not expect a return value from 'opfunc'. (closes #7510)
return retval;
}
+/*
+ * Call Vim script function like call_func_retnr() and drop the result.
+ * Returns FAIL when calling the function fails.
+ */
+ int
+call_func_noret(
+ char_u *func,
+ int argc,
+ typval_T *argv)
+{
+ typval_T rettv;
+
+ if (call_vim_function(func, argc, argv, &rettv) == FAIL)
+ return FAIL;
+ clear_tv(&rettv);
+ return OK;
+}
+
/*
* Call Vim script function "func" and return the result as a string.
+ * Uses "argv" and "argc" as call_func_retnr().
* Returns NULL when calling the function fails.
- * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should
- * have type VAR_UNKNOWN.
*/
void *
call_func_retstr(
/*
* Call Vim script function "func" and return the result as a List.
- * Uses argv[0] to argv[argc - 1] for the function arguments. argv[argc] should
- * have type VAR_UNKNOWN.
+ * Uses "argv" and "argc" as call_func_retnr().
* Returns NULL when there is something wrong.
*/
void *
// function.
virtual_op = MAYBE;
- (void)call_func_retnr(p_opfunc, 1, argv);
+ (void)call_func_noret(p_opfunc, 1, argv);
virtual_op = save_virtual_op;
if (cmdmod.cmod_flags & CMOD_LOCKMARKS)
typval_T *eval_expr(char_u *arg, exarg_T *eap);
int call_vim_function(char_u *func, int argc, typval_T *argv, typval_T *rettv);
varnumber_T call_func_retnr(char_u *func, int argc, typval_T *argv);
+int call_func_noret(char_u *func, int argc, typval_T *argv);
void *call_func_retstr(char_u *func, int argc, typval_T *argv);
void *call_func_retlist(char_u *func, int argc, typval_T *argv);
int eval_foldexpr(char_u *arg, int *cp);
CheckScriptSuccess(lines)
enddef
+def Test_opfunc()
+ nnoremap <F3> <cmd>set opfunc=Opfunc<cr>g@
+ def g:Opfunc(_: any): string
+ setline(1, 'ASDF')
+ return ''
+ enddef
+ new
+ setline(1, 'asdf')
+ feedkeys("\<F3>$", 'x')
+ assert_equal('ASDF', getline(1))
+
+ bwipe!
+ nunmap <F3>
+enddef
+
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 2186,
/**/
2185,
/**/