1
0
forked from aniani/vim

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.
This commit is contained in:
Bram Moolenaar
2022-04-12 12:54:11 +01:00
parent d58862d18f
commit 575445200b
4 changed files with 23 additions and 5 deletions

View File

@@ -2270,6 +2270,9 @@ expand({string} [, {nosuf} [, {list}]]) *expand()*
is not defined, an empty string is used. Using "%:p" in a is not defined, an empty string is used. Using "%:p" in a
buffer with no name, results in the current directory, with a buffer with no name, results in the current directory, with a
'/' added. '/' 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 When {string} does not start with '%', '#' or '<', it is
expanded like a file name is expanded on the command line. expanded like a file name is expanded on the command line.

View File

@@ -4065,7 +4065,6 @@ f_expand(typval_T *argvars, typval_T *rettv)
{ {
char_u *s; char_u *s;
int len; int len;
char *errormsg;
int options = WILD_SILENT|WILD_USE_NL|WILD_LIST_NOTFOUND; int options = WILD_SILENT|WILD_USE_NL|WILD_LIST_NOTFOUND;
expand_T xpc; expand_T xpc;
int error = FALSE; int error = FALSE;
@@ -4096,9 +4095,15 @@ f_expand(typval_T *argvars, typval_T *rettv)
s = tv_get_string(&argvars[0]); s = tv_get_string(&argvars[0]);
if (*s == '%' || *s == '#' || *s == '<') if (*s == '%' || *s == '#' || *s == '<')
{ {
char *errormsg = NULL;
if (p_verbose == 0)
++emsg_off; ++emsg_off;
result = eval_vars(s, s, &len, NULL, &errormsg, NULL); result = eval_vars(s, s, &len, NULL, &errormsg, NULL);
if (p_verbose == 0)
--emsg_off; --emsg_off;
else if (errormsg != NULL)
emsg(errormsg);
if (rettv->v_type == VAR_LIST) if (rettv->v_type == VAR_LIST)
{ {
if (rettv_list_alloc(rettv) != FAIL && result != NULL) if (rettv_list_alloc(rettv) != FAIL && result != NULL)

View File

@@ -128,13 +128,21 @@ func Test_source_sfile()
:call assert_equal('edit <cword>', expandcmd("edit <cword>")) :call assert_equal('edit <cword>', expandcmd("edit <cword>"))
:call assert_equal('edit <cexpr>', expandcmd("edit <cexpr>")) :call assert_equal('edit <cexpr>', expandcmd("edit <cexpr>"))
:call assert_fails('autocmd User MyCmd echo "<sfile>"', 'E498:') :call assert_fails('autocmd User MyCmd echo "<sfile>"', 'E498:')
:
:call assert_equal('', expand('<script>'))
:verbose echo expand('<script>')
:call add(v:errors, v:errmsg)
:verbose echo expand('<sfile>')
:call add(v:errors, v:errmsg)
:call writefile(v:errors, 'Xresult') :call writefile(v:errors, 'Xresult')
:qall! :qall!
[SCRIPT] [SCRIPT]
call writefile(lines, 'Xscript') call writefile(lines, 'Xscript')
if RunVim([], [], '--clean -s Xscript') if RunVim([], [], '--clean -s Xscript')
call assert_equal([], readfile('Xresult')) call assert_equal([
\ 'E1274: No script file name to substitute for "<script>"',
\ 'E498: no :source file name to substitute for "<sfile>"'],
\ readfile('Xresult'))
endif endif
call delete('Xscript') call delete('Xscript')
call delete('Xresult') call delete('Xresult')

View File

@@ -746,6 +746,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
4740,
/**/ /**/
4739, 4739,
/**/ /**/