Mercurial > vim
comparison src/userfunc.c @ 26757:3a2b222107a6 v8.2.3907
patch 8.2.3907: error messages are spread out
Commit: https://github.com/vim/vim/commit/c553a21e189aa440515a19c5b25f8b6b50c5d53d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Dec 26 20:20:34 2021 +0000
patch 8.2.3907: error messages are spread out
Problem: Error messages are spread out.
Solution: Move error messages to errors.h. Avoid duplicates.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 26 Dec 2021 21:30:03 +0100 |
parents | a8a4e1e7b111 |
children | fc859aea8cec |
comparison
equal
deleted
inserted
replaced
26756:a129f3236f52 | 26757:3a2b222107a6 |
---|---|
27 | 27 |
28 // Pointer to list of previously used funccal, still around because some | 28 // Pointer to list of previously used funccal, still around because some |
29 // item in it is still being used. | 29 // item in it is still being used. |
30 static funccall_T *previous_funccal = NULL; | 30 static funccall_T *previous_funccal = NULL; |
31 | 31 |
32 static char *e_funcexts = N_("E122: Function %s already exists, add ! to replace it"); | |
33 static char *e_funcdict = N_("E717: Dictionary entry already exists"); | 32 static char *e_funcdict = N_("E717: Dictionary entry already exists"); |
34 static char *e_funcref = N_("E718: Funcref required"); | 33 static char *e_funcref = N_("E718: Funcref required"); |
35 static char *e_nofunc = N_("E130: Unknown function: %s"); | |
36 | 34 |
37 static void funccal_unref(funccall_T *fc, ufunc_T *fp, int force); | 35 static void funccal_unref(funccall_T *fc, ufunc_T *fp, int force); |
38 static void func_clear(ufunc_T *fp, int force); | 36 static void func_clear(ufunc_T *fp, int force); |
39 static int func_free(ufunc_T *fp, int force); | 37 static int func_free(ufunc_T *fp, int force); |
40 | 38 |
81 || (argtypes == NULL | 79 || (argtypes == NULL |
82 && ((p - arg == 9 && STRNCMP(arg, "firstline", 9) == 0) | 80 && ((p - arg == 9 && STRNCMP(arg, "firstline", 9) == 0) |
83 || (p - arg == 8 && STRNCMP(arg, "lastline", 8) == 0)))) | 81 || (p - arg == 8 && STRNCMP(arg, "lastline", 8) == 0)))) |
84 { | 82 { |
85 if (!skip) | 83 if (!skip) |
86 semsg(_("E125: Illegal argument: %s"), arg); | 84 semsg(_(e_illegal_argument_str), arg); |
87 return arg; | 85 return arg; |
88 } | 86 } |
89 | 87 |
90 // Vim9 script: cannot use script var name for argument. In function: also | 88 // Vim9 script: cannot use script var name for argument. In function: also |
91 // check local vars and arguments. | 89 // check local vars and arguments. |
741 else if (nesting_inline[nesting]) | 739 else if (nesting_inline[nesting]) |
742 emsg(_(e_missing_end_block)); | 740 emsg(_(e_missing_end_block)); |
743 else if (eap->cmdidx == CMD_def) | 741 else if (eap->cmdidx == CMD_def) |
744 emsg(_(e_missing_enddef)); | 742 emsg(_(e_missing_enddef)); |
745 else | 743 else |
746 emsg(_("E126: Missing :endfunction")); | 744 emsg(_(e_missing_endfunction)); |
747 goto theend; | 745 goto theend; |
748 } | 746 } |
749 | 747 |
750 // Detect line continuation: SOURCING_LNUM increased more than one. | 748 // Detect line continuation: SOURCING_LNUM increased more than one. |
751 sourcing_lnum_off = get_sourced_lnum(eap->getline, eap->cookie); | 749 sourcing_lnum_off = get_sourced_lnum(eap->getline, eap->cookie); |
1783 else if (!aborting()) | 1781 else if (!aborting()) |
1784 { | 1782 { |
1785 if (argcount == MAX_FUNC_ARGS) | 1783 if (argcount == MAX_FUNC_ARGS) |
1786 emsg_funcname(N_("E740: Too many arguments for function %s"), name); | 1784 emsg_funcname(N_("E740: Too many arguments for function %s"), name); |
1787 else | 1785 else |
1788 emsg_funcname(N_(e_invalid_arguments_for_function_str), name); | 1786 emsg_funcname(e_invalid_arguments_for_function_str, name); |
1789 } | 1787 } |
1790 | 1788 |
1791 while (--argcount >= 0) | 1789 while (--argcount >= 0) |
1792 clear_tv(&argvars[argcount]); | 1790 clear_tv(&argvars[argcount]); |
1793 | 1791 |
2339 | 2337 |
2340 fp = find_func(global, TRUE, NULL); | 2338 fp = find_func(global, TRUE, NULL); |
2341 if (fp != NULL) | 2339 if (fp != NULL) |
2342 { | 2340 { |
2343 // TODO: handle ! to overwrite | 2341 // TODO: handle ! to overwrite |
2344 semsg(_(e_funcexts), global); | 2342 semsg(_(e_function_str_already_exists_add_excl_to_replace), global); |
2345 return FAIL; | 2343 return FAIL; |
2346 } | 2344 } |
2347 | 2345 |
2348 fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(global) + 1); | 2346 fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(global) + 1); |
2349 if (fp == NULL) | 2347 if (fp == NULL) |
2419 int | 2417 int |
2420 funcdepth_increment(void) | 2418 funcdepth_increment(void) |
2421 { | 2419 { |
2422 if (funcdepth >= p_mfd) | 2420 if (funcdepth >= p_mfd) |
2423 { | 2421 { |
2424 emsg(_("E132: Function call depth is higher than 'maxfuncdepth'")); | 2422 emsg(_(e_function_call_depth_is_higher_than_macfuncdepth)); |
2425 return FAIL; | 2423 return FAIL; |
2426 } | 2424 } |
2427 ++funcdepth; | 2425 ++funcdepth; |
2428 return OK; | 2426 return OK; |
2429 } | 2427 } |
3250 case FCERR_NOTMETHOD: | 3248 case FCERR_NOTMETHOD: |
3251 emsg_funcname( | 3249 emsg_funcname( |
3252 N_("E276: Cannot use function as a method: %s"), name); | 3250 N_("E276: Cannot use function as a method: %s"), name); |
3253 break; | 3251 break; |
3254 case FCERR_DELETED: | 3252 case FCERR_DELETED: |
3255 emsg_funcname(N_(e_func_deleted), name); | 3253 emsg_funcname(e_func_deleted, name); |
3256 break; | 3254 break; |
3257 case FCERR_TOOMANY: | 3255 case FCERR_TOOMANY: |
3258 emsg_funcname((char *)e_too_many_arguments_for_function_str, | 3256 emsg_funcname((char *)e_too_many_arguments_for_function_str, |
3259 name); | 3257 name); |
3260 break; | 3258 break; |
3262 emsg_funcname((char *)e_not_enough_arguments_for_function_str, | 3260 emsg_funcname((char *)e_not_enough_arguments_for_function_str, |
3263 name); | 3261 name); |
3264 break; | 3262 break; |
3265 case FCERR_SCRIPT: | 3263 case FCERR_SCRIPT: |
3266 emsg_funcname( | 3264 emsg_funcname( |
3267 N_(e_using_sid_not_in_script_context_str), name); | 3265 e_using_sid_not_in_script_context_str, name); |
3268 break; | 3266 break; |
3269 case FCERR_DICT: | 3267 case FCERR_DICT: |
3270 emsg_funcname( | 3268 emsg_funcname( |
3271 N_("E725: Calling dict function without Dictionary: %s"), | 3269 N_("E725: Calling dict function without Dictionary: %s"), |
3272 name); | 3270 name); |
3625 char_u sid_buf[20]; | 3623 char_u sid_buf[20]; |
3626 int len; | 3624 int len; |
3627 int extra = 0; | 3625 int extra = 0; |
3628 lval_T lv; | 3626 lval_T lv; |
3629 int vim9script; | 3627 int vim9script; |
3630 static char *e_function_name = N_("E129: Function name required"); | |
3631 | 3628 |
3632 if (fdp != NULL) | 3629 if (fdp != NULL) |
3633 CLEAR_POINTER(fdp); | 3630 CLEAR_POINTER(fdp); |
3634 start = *pp; | 3631 start = *pp; |
3635 | 3632 |
3653 end = get_lval(start, NULL, &lv, FALSE, skip, flags | GLV_READ_ONLY, | 3650 end = get_lval(start, NULL, &lv, FALSE, skip, flags | GLV_READ_ONLY, |
3654 lead > 2 ? 0 : FNE_CHECK_START); | 3651 lead > 2 ? 0 : FNE_CHECK_START); |
3655 if (end == start) | 3652 if (end == start) |
3656 { | 3653 { |
3657 if (!skip) | 3654 if (!skip) |
3658 emsg(_(e_function_name)); | 3655 emsg(_(e_function_name_required)); |
3659 goto theend; | 3656 goto theend; |
3660 } | 3657 } |
3661 if (end == NULL || (lv.ll_tv != NULL && (lead > 2 || lv.ll_range))) | 3658 if (end == NULL || (lv.ll_tv != NULL && (lead > 2 || lv.ll_range))) |
3662 { | 3659 { |
3663 /* | 3660 /* |
3773 len = (int)(end - lv.ll_name); | 3770 len = (int)(end - lv.ll_name); |
3774 } | 3771 } |
3775 if (len <= 0) | 3772 if (len <= 0) |
3776 { | 3773 { |
3777 if (!skip) | 3774 if (!skip) |
3778 emsg(_(e_function_name)); | 3775 emsg(_(e_function_name_required)); |
3779 goto theend; | 3776 goto theend; |
3780 } | 3777 } |
3781 | 3778 |
3782 // In Vim9 script a user function is script-local by default, unless it | 3779 // In Vim9 script a user function is script-local by default, unless it |
3783 // starts with a lower case character: dict.func(). | 3780 // starts with a lower case character: dict.func(). |
3821 } | 3818 } |
3822 } | 3819 } |
3823 else if (!(flags & TFN_INT) && (builtin_function(lv.ll_name, len) | 3820 else if (!(flags & TFN_INT) && (builtin_function(lv.ll_name, len) |
3824 || (in_vim9script() && *lv.ll_name == '_'))) | 3821 || (in_vim9script() && *lv.ll_name == '_'))) |
3825 { | 3822 { |
3826 semsg(_("E128: Function name must start with a capital or \"s:\": %s"), | 3823 semsg(_(e_function_name_must_start_with_capital_or_s_str), start); |
3827 start); | |
3828 goto theend; | 3824 goto theend; |
3829 } | 3825 } |
3830 if (!skip && !(flags & TFN_QUIET) && !(flags & TFN_NO_DEREF)) | 3826 if (!skip && !(flags & TFN_QUIET) && !(flags & TFN_NO_DEREF)) |
3831 { | 3827 { |
3832 char_u *cp = vim_strchr(lv.ll_name, ':'); | 3828 char_u *cp = vim_strchr(lv.ll_name, ':'); |
4169 else | 4165 else |
4170 msg_puts(" endfunction"); | 4166 msg_puts(" endfunction"); |
4171 } | 4167 } |
4172 } | 4168 } |
4173 else | 4169 else |
4174 emsg_funcname(N_("E123: Undefined function: %s"), eap->arg); | 4170 emsg_funcname(e_undefined_function_str, eap->arg); |
4175 } | 4171 } |
4176 goto ret_free; | 4172 goto ret_free; |
4177 } | 4173 } |
4178 | 4174 |
4179 /* | 4175 /* |
4182 p = skipwhite(p); | 4178 p = skipwhite(p); |
4183 if (*p != '(') | 4179 if (*p != '(') |
4184 { | 4180 { |
4185 if (!eap->skip) | 4181 if (!eap->skip) |
4186 { | 4182 { |
4187 semsg(_("E124: Missing '(': %s"), eap->arg); | 4183 semsg(_(e_missing_paren_str), eap->arg); |
4188 goto ret_free; | 4184 goto ret_free; |
4189 } | 4185 } |
4190 // attempt to continue by skipping some text | 4186 // attempt to continue by skipping some text |
4191 if (vim_strchr(p, '(') != NULL) | 4187 if (vim_strchr(p, '(') != NULL) |
4192 p = vim_strchr(p, '('); | 4188 p = vim_strchr(p, '('); |
4355 if (!eap->skip && !eap->forceit) | 4351 if (!eap->skip && !eap->forceit) |
4356 { | 4352 { |
4357 if (fudi.fd_dict != NULL && fudi.fd_newkey == NULL) | 4353 if (fudi.fd_dict != NULL && fudi.fd_newkey == NULL) |
4358 emsg(_(e_funcdict)); | 4354 emsg(_(e_funcdict)); |
4359 else if (name != NULL && find_func(name, is_global, NULL) != NULL) | 4355 else if (name != NULL && find_func(name, is_global, NULL) != NULL) |
4360 emsg_funcname(e_funcexts, name); | 4356 emsg_funcname(e_function_str_already_exists_add_excl_to_replace, name); |
4361 } | 4357 } |
4362 | 4358 |
4363 if (!eap->skip && did_emsg) | 4359 if (!eap->skip && did_emsg) |
4364 goto erret; | 4360 goto erret; |
4365 | 4361 |
4413 { | 4409 { |
4414 SOURCING_LNUM = sourcing_lnum_top; | 4410 SOURCING_LNUM = sourcing_lnum_top; |
4415 if (vim9script) | 4411 if (vim9script) |
4416 emsg_funcname(e_name_already_defined_str, name); | 4412 emsg_funcname(e_name_already_defined_str, name); |
4417 else | 4413 else |
4418 emsg_funcname(e_funcexts, name); | 4414 emsg_funcname(e_function_str_already_exists_add_excl_to_replace, name); |
4419 goto erret; | 4415 goto erret; |
4420 } | 4416 } |
4421 if (fp->uf_calls > 0) | 4417 if (fp->uf_calls > 0) |
4422 { | 4418 { |
4423 emsg_funcname( | 4419 emsg_funcname( |
4424 N_("E127: Cannot redefine function %s: It is in use"), | 4420 e_cannot_redefine_function_str_it_is_in_use, name); |
4425 name); | |
4426 goto erret; | 4421 goto erret; |
4427 } | 4422 } |
4428 if (fp->uf_refcount > 1) | 4423 if (fp->uf_refcount > 1) |
4429 { | 4424 { |
4430 // This function is referenced somewhere, don't redefine it but | 4425 // This function is referenced somewhere, don't redefine it but |
4898 if (!eap->skip) | 4893 if (!eap->skip) |
4899 { | 4894 { |
4900 if (fp == NULL) | 4895 if (fp == NULL) |
4901 { | 4896 { |
4902 if (!eap->forceit) | 4897 if (!eap->forceit) |
4903 semsg(_(e_nofunc), eap->arg); | 4898 semsg(_(e_unknown_function_str), eap->arg); |
4904 return; | 4899 return; |
4905 } | 4900 } |
4906 if (fp->uf_calls > 0) | 4901 if (fp->uf_calls > 0) |
4907 { | 4902 { |
4908 semsg(_("E131: Cannot delete function %s: It is in use"), eap->arg); | 4903 semsg(_(e_cannot_delete_function_str_it_is_in_use), eap->arg); |
4909 return; | 4904 return; |
4910 } | 4905 } |
4911 if (fp->uf_flags & FC_VIM9) | 4906 if (fp->uf_flags & FC_VIM9) |
4912 { | 4907 { |
4913 semsg(_(e_cannot_delete_vim9_script_function_str), eap->arg); | 4908 semsg(_(e_cannot_delete_vim9_script_function_str), eap->arg); |
5035 int returning = FALSE; | 5030 int returning = FALSE; |
5036 evalarg_T evalarg; | 5031 evalarg_T evalarg; |
5037 | 5032 |
5038 if (current_funccal == NULL) | 5033 if (current_funccal == NULL) |
5039 { | 5034 { |
5040 emsg(_("E133: :return not inside a function")); | 5035 emsg(_(e_return_not_inside_function)); |
5041 return; | 5036 return; |
5042 } | 5037 } |
5043 | 5038 |
5044 init_evalarg(&evalarg); | 5039 init_evalarg(&evalarg); |
5045 evalarg.eval_flags = eap->skip ? 0 : EVAL_EVALUATE; | 5040 evalarg.eval_flags = eap->skip ? 0 : EVAL_EVALUATE; |