# HG changeset patch # User Bram Moolenaar # Date 1649764805 -7200 # Node ID 4fbdd4ce9edb8d4fd13e26a6f072e6729c42702f # Parent 957dde5a4688eff48505df91f7534eefeeb8c017 patch 8.2.4740: when expand() fails there is no error message Commit: https://github.com/vim/vim/commit/575445200bd35283191ecd7a0d596b37c5b477a4 Author: Bram Moolenaar Date: Tue Apr 12 12:54:11 2022 +0100 patch 8.2.4740: when expand() fails there is no error message Problem: When expand() fails there is no error message. Solution: When 'verbose' is set give an error message. diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -2270,6 +2270,9 @@ expand({string} [, {nosuf} [, {list}]]) is not defined, an empty string is used. Using "%:p" in a buffer with no name, results in the current directory, with a '/' added. + When 'verbose' is set then expanding '%', '#' and <> items + will result in an error message if the argument cannot be + expanded. When {string} does not start with '%', '#' or '<', it is expanded like a file name is expanded on the command line. diff --git a/src/evalfunc.c b/src/evalfunc.c --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -4065,7 +4065,6 @@ f_expand(typval_T *argvars, typval_T *re { char_u *s; int len; - char *errormsg; int options = WILD_SILENT|WILD_USE_NL|WILD_LIST_NOTFOUND; expand_T xpc; int error = FALSE; @@ -4096,9 +4095,15 @@ f_expand(typval_T *argvars, typval_T *re s = tv_get_string(&argvars[0]); if (*s == '%' || *s == '#' || *s == '<') { - ++emsg_off; + char *errormsg = NULL; + + if (p_verbose == 0) + ++emsg_off; result = eval_vars(s, s, &len, NULL, &errormsg, NULL); - --emsg_off; + if (p_verbose == 0) + --emsg_off; + else if (errormsg != NULL) + emsg(errormsg); if (rettv->v_type == VAR_LIST) { if (rettv_list_alloc(rettv) != FAIL && result != NULL) diff --git a/src/testdir/test_expand.vim b/src/testdir/test_expand.vim --- a/src/testdir/test_expand.vim +++ b/src/testdir/test_expand.vim @@ -128,13 +128,21 @@ func Test_source_sfile() :call assert_equal('edit ', expandcmd("edit ")) :call assert_equal('edit ', expandcmd("edit ")) :call assert_fails('autocmd User MyCmd echo ""', 'E498:') + : + :call assert_equal('', expand('