Skip to content

Commit be82c25

Browse files
committed
patch 7.4.1499
Problem: No error message when :packadd does not find anything. Solution: Add an error message. (Hirohito Higashi)
1 parent 2588b5a commit be82c25

6 files changed

Lines changed: 36 additions & 12 deletions

File tree

runtime/doc/repeat.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
213213
about each searched file.
214214
{not in Vi}
215215

216-
*:pa* *:packadd*
216+
*:pa* *:packadd* *E919*
217217
:pa[ckadd][!] {name} Search for an optional plugin directory in 'packpath'
218218
and source any plugin files found. The directory must
219219
match:

src/ex_cmds.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ EX(CMD_print, "print", ex_print,
10121012
RANGE|WHOLEFOLD|COUNT|EXFLAGS|TRLBAR|CMDWIN|SBOXOK,
10131013
ADDR_LINES),
10141014
EX(CMD_packadd, "packadd", ex_packadd,
1015-
BANG|FILE1|TRLBAR|SBOXOK|CMDWIN,
1015+
BANG|FILE1|NEEDARG|TRLBAR|SBOXOK|CMDWIN,
10161016
ADDR_LINES),
10171017
EX(CMD_pclose, "pclose", ex_pclose,
10181018
BANG|TRLBAR,

src/ex_cmds2.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,8 +2918,7 @@ source_callback(char_u *fname, void *cookie UNUSED)
29182918
/*
29192919
* Source the file "name" from all directories in 'runtimepath'.
29202920
* "name" can contain wildcards.
2921-
* When "flags" has DIP_ALL: source all files, otherwise only the first one.
2922-
* When "flags" has DIP_DIR: find directories instead of files.
2921+
* When "all" is TRUE: source all files, otherwise only the first one.
29232922
*
29242923
* return FAIL when no file could be sourced, OK otherwise.
29252924
*/
@@ -2931,7 +2930,18 @@ source_runtime(char_u *name, int all)
29312930

29322931
#define DIP_ALL 1 /* all matches, not just the first one */
29332932
#define DIP_DIR 2 /* find directories instead of files. */
2933+
#define DIP_ERR 4 /* give an error message when none found. */
29342934

2935+
/*
2936+
* Find the file "name" in all directories in "path" and invoke
2937+
* "callback(fname, cookie)".
2938+
* "name" can contain wildcards.
2939+
* When "flags" has DIP_ALL: source all files, otherwise only the first one.
2940+
* When "flags" has DIP_DIR: find directories instead of files.
2941+
* When "flags" has DIP_ERR: give an error message if there is no match.
2942+
*
2943+
* return FAIL when no file could be sourced, OK otherwise.
2944+
*/
29352945
static int
29362946
do_in_path(
29372947
char_u *path,
@@ -3022,11 +3032,18 @@ do_in_path(
30223032
}
30233033
vim_free(buf);
30243034
vim_free(rtp_copy);
3025-
if (p_verbose > 0 && !did_one && name != NULL)
3035+
if (!did_one && name != NULL)
30263036
{
3027-
verbose_enter();
3028-
smsg((char_u *)_("not found in 'runtimepath': \"%s\""), name);
3029-
verbose_leave();
3037+
char *basepath = path == p_rtp ? "runtimepath" : "packpath";
3038+
3039+
if (flags & DIP_ERR)
3040+
EMSG3(_(e_dirnotf), basepath, name);
3041+
else if (p_verbose > 0)
3042+
{
3043+
verbose_enter();
3044+
smsg((char_u *)_("not found in '%s': \"%s\""), basepath, name);
3045+
verbose_leave();
3046+
}
30303047
}
30313048

30323049
#ifdef AMIGA
@@ -3178,8 +3195,8 @@ add_pack_plugin(char_u *fname, void *cookie)
31783195
void
31793196
source_packages()
31803197
{
3181-
do_in_path(p_pp, (char_u *)"pack/*/ever/*",
3182-
DIP_ALL + DIP_DIR, add_pack_plugin, p_pp);
3198+
do_in_path(p_pp, (char_u *)"pack/*/ever/*", DIP_ALL + DIP_DIR,
3199+
add_pack_plugin, p_pp);
31833200
}
31843201

31853202
/*
@@ -3197,8 +3214,8 @@ ex_packadd(exarg_T *eap)
31973214
if (pat == NULL)
31983215
return;
31993216
vim_snprintf(pat, len, plugpat, eap->arg);
3200-
do_in_path(p_pp, (char_u *)pat, DIP_ALL + DIP_DIR, add_pack_plugin,
3201-
eap->forceit ? NULL : p_pp);
3217+
do_in_path(p_pp, (char_u *)pat, DIP_ALL + DIP_DIR + DIP_ERR,
3218+
add_pack_plugin, eap->forceit ? NULL : p_pp);
32023219
vim_free(pat);
32033220
}
32043221

src/globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,7 @@ EXTERN char_u e_notset[] INIT(= N_("E764: Option '%s' is not set"));
15771577
#ifndef FEAT_CLIPBOARD
15781578
EXTERN char_u e_invalidreg[] INIT(= N_("E850: Invalid register name"));
15791579
#endif
1580+
EXTERN char_u e_dirnotf[] INIT(= N_("E919: Directory not found in '%s': \"%s\""));
15801581

15811582
#ifdef MACOS_X_UNIX
15821583
EXTERN short disallow_gui INIT(= FALSE);

src/testdir/test_packadd.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func Test_packadd()
3131
call assert_equal(17, g:ftdetect_works)
3232
call assert_true(len(&rtp) > len(rtp))
3333
call assert_true(&rtp =~ 'testdir/Xdir/pack/mine/opt/mytest\($\|,\)')
34+
35+
" Check exception
36+
call assert_fails("packadd directorynotfound", 'E919:')
37+
call assert_fails("packadd", 'E471:')
3438
endfunc
3539

3640
func Test_packadd_noload()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,8 @@ static char *(features[]) =
743743

744744
static int included_patches[] =
745745
{ /* Add new patch number below this line */
746+
/**/
747+
1499,
746748
/**/
747749
1498,
748750
/**/

0 commit comments

Comments
 (0)