Mercurial > vim
diff 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 |
line wrap: on
line diff
--- a/src/userfunc.c +++ b/src/userfunc.c @@ -527,6 +527,28 @@ set_ufunc_name(ufunc_T *fp, char_u *name } /* + * If "name" starts with K_SPECIAL and "buf[bufsize]" is big enough + * return "buf" filled with a readable function name. + * Otherwise just return "name", thus the return value can always be used. + * "name" and "buf" may be equal. + */ + char_u * +make_ufunc_name_readable(char_u *name, char_u *buf, size_t bufsize) +{ + size_t len; + + if (name[0] != K_SPECIAL) + return name; + len = STRLEN(name); + if (len + 3 > bufsize) + return name; + + mch_memmove(buf + 5, name + 3, len + 1); + mch_memmove(buf, "<SNR>", 5); + return buf; +} + +/* * Get a name for a lambda. Returned in static memory. */ char_u * @@ -3354,13 +3376,12 @@ user_func_error(int error, char_u *name, { case FCERR_UNKNOWN: if (funcexe->fe_found_var) - semsg(_(e_not_callable_type_str), name); + emsg_funcname(e_not_callable_type_str, name); else emsg_funcname(e_unknown_function_str, name); break; case FCERR_NOTMETHOD: - emsg_funcname( - N_(e_cannot_use_function_as_method_str), name); + emsg_funcname(e_cannot_use_function_as_method_str, name); break; case FCERR_DELETED: emsg_funcname(e_function_was_deleted_str, name); @@ -3372,8 +3393,7 @@ user_func_error(int error, char_u *name, emsg_funcname(e_not_enough_arguments_for_function_str, name); break; case FCERR_SCRIPT: - emsg_funcname( - e_using_sid_not_in_script_context_str, name); + emsg_funcname(e_using_sid_not_in_script_context_str, name); break; case FCERR_DICT: emsg_funcname(e_calling_dict_function_without_dictionary_str, @@ -3613,9 +3633,7 @@ theend: * cancelled due to an aborting error, an interrupt, or an exception. */ if (!aborting()) - { user_func_error(error, (name != NULL) ? name : funcname, funcexe); - } // clear the copies made from the partial while (argv_clear > 0)