comparison src/userfunc.c @ 28263:c446812efd60 v8.2.4657

patch 8.2.4657: errors for functions are sometimes hard to read Commit: https://github.com/vim/vim/commit/a6c18d38ca2df0a92403f2265a480d9dba08290f Author: Bram Moolenaar <Bram@vim.org> Date: Thu Mar 31 20:02:56 2022 +0100 patch 8.2.4657: errors for functions are sometimes hard to read Problem: Errors for functions are sometimes hard to read. Solution: Use printable_func_name() in more places.
author Bram Moolenaar <Bram@vim.org>
date Thu, 31 Mar 2022 21:15:03 +0200
parents 4b322951ebac
children 39a833e69bf3
comparison
equal deleted inserted replaced
28262:59a7125e87f4 28263:c446812efd60
522 { 522 {
523 STRCPY(fp->uf_name_exp, "<SNR>"); 523 STRCPY(fp->uf_name_exp, "<SNR>");
524 STRCAT(fp->uf_name_exp, fp->uf_name + 3); 524 STRCAT(fp->uf_name_exp, fp->uf_name + 3);
525 } 525 }
526 } 526 }
527 }
528
529 /*
530 * If "name" starts with K_SPECIAL and "buf[bufsize]" is big enough
531 * return "buf" filled with a readable function name.
532 * Otherwise just return "name", thus the return value can always be used.
533 * "name" and "buf" may be equal.
534 */
535 char_u *
536 make_ufunc_name_readable(char_u *name, char_u *buf, size_t bufsize)
537 {
538 size_t len;
539
540 if (name[0] != K_SPECIAL)
541 return name;
542 len = STRLEN(name);
543 if (len + 3 > bufsize)
544 return name;
545
546 mch_memmove(buf + 5, name + 3, len + 1);
547 mch_memmove(buf, "<SNR>", 5);
548 return buf;
527 } 549 }
528 550
529 /* 551 /*
530 * Get a name for a lambda. Returned in static memory. 552 * Get a name for a lambda. Returned in static memory.
531 */ 553 */
3352 { 3374 {
3353 switch (error) 3375 switch (error)
3354 { 3376 {
3355 case FCERR_UNKNOWN: 3377 case FCERR_UNKNOWN:
3356 if (funcexe->fe_found_var) 3378 if (funcexe->fe_found_var)
3357 semsg(_(e_not_callable_type_str), name); 3379 emsg_funcname(e_not_callable_type_str, name);
3358 else 3380 else
3359 emsg_funcname(e_unknown_function_str, name); 3381 emsg_funcname(e_unknown_function_str, name);
3360 break; 3382 break;
3361 case FCERR_NOTMETHOD: 3383 case FCERR_NOTMETHOD:
3362 emsg_funcname( 3384 emsg_funcname(e_cannot_use_function_as_method_str, name);
3363 N_(e_cannot_use_function_as_method_str), name);
3364 break; 3385 break;
3365 case FCERR_DELETED: 3386 case FCERR_DELETED:
3366 emsg_funcname(e_function_was_deleted_str, name); 3387 emsg_funcname(e_function_was_deleted_str, name);
3367 break; 3388 break;
3368 case FCERR_TOOMANY: 3389 case FCERR_TOOMANY:
3370 break; 3391 break;
3371 case FCERR_TOOFEW: 3392 case FCERR_TOOFEW:
3372 emsg_funcname(e_not_enough_arguments_for_function_str, name); 3393 emsg_funcname(e_not_enough_arguments_for_function_str, name);
3373 break; 3394 break;
3374 case FCERR_SCRIPT: 3395 case FCERR_SCRIPT:
3375 emsg_funcname( 3396 emsg_funcname(e_using_sid_not_in_script_context_str, name);
3376 e_using_sid_not_in_script_context_str, name);
3377 break; 3397 break;
3378 case FCERR_DICT: 3398 case FCERR_DICT:
3379 emsg_funcname(e_calling_dict_function_without_dictionary_str, 3399 emsg_funcname(e_calling_dict_function_without_dictionary_str,
3380 name); 3400 name);
3381 break; 3401 break;
3611 /* 3631 /*
3612 * Report an error unless the argument evaluation or function call has been 3632 * Report an error unless the argument evaluation or function call has been
3613 * cancelled due to an aborting error, an interrupt, or an exception. 3633 * cancelled due to an aborting error, an interrupt, or an exception.
3614 */ 3634 */
3615 if (!aborting()) 3635 if (!aborting())
3616 {
3617 user_func_error(error, (name != NULL) ? name : funcname, funcexe); 3636 user_func_error(error, (name != NULL) ? name : funcname, funcexe);
3618 }
3619 3637
3620 // clear the copies made from the partial 3638 // clear the copies made from the partial
3621 while (argv_clear > 0) 3639 while (argv_clear > 0)
3622 clear_tv(&argv[--argv_clear + argv_base]); 3640 clear_tv(&argv[--argv_clear + argv_base]);
3623 3641