Skip to content

Commit 8dcf259

Browse files
committed
patch 7.4.1553
Problem: ":runtime" does not use 'packpath'. Solution: Add "what" argument.
1 parent 7f8989d commit 8dcf259

File tree

5 files changed

+114
-11
lines changed

5 files changed

+114
-11
lines changed

runtime/doc/repeat.txt

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,12 @@ For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
182182
{not in Vi}
183183

184184
*:ru* *:runtime*
185-
:ru[ntime][!] {file} ..
185+
:ru[ntime][!] [where] {file} ..
186186
Read Ex commands from {file} in each directory given
187-
by 'runtimepath'. There is no error for non-existing
188-
files. Example: >
187+
by 'runtimepath' and/or 'packpath'. There is no error
188+
for non-existing files.
189+
190+
Example: >
189191
:runtime syntax/c.vim
190192
191193
< There can be multiple {file} arguments, separated by
@@ -199,6 +201,15 @@ For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
199201
When it is not included only the first found file is
200202
sourced.
201203

204+
When [where] is omitted only 'runtimepath' is used.
205+
Other values:
206+
START search under "start" in 'packpath'
207+
OPT search under "opt" in 'packpath'
208+
PACK search under "start" and "opt" in
209+
'packpath'
210+
ALL first use 'runtimepath', then search
211+
under "start" and "opt" in 'packpath'
212+
202213
When {file} contains wildcards it is expanded to all
203214
matching files. Example: >
204215
:runtime! plugin/*.vim
@@ -238,6 +249,16 @@ For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
238249

239250
Also see |pack-add|.
240251

252+
:packloadall[!] Load all packages in the "start" directories under
253+
'packpath'. The directories found are added to
254+
'runtimepath'.
255+
This normally done during startup, after loading your
256+
.vimrc file. With this command it can be done
257+
earlier.
258+
Packages will be loaded only once. After this command
259+
it won't happen again. When the optional ! is added
260+
this command will load packages even when done before.
261+
See |packages|.
241262

242263
:scripte[ncoding] [encoding] *:scripte* *:scriptencoding* *E167*
243264
Specify the character encoding used in the script.
@@ -461,8 +482,13 @@ Note that the files under "pack/foo/opt" or not loaded automatically, only the
461482
ones under "pack/foo/start". See |pack-add| below for how the "opt" directory
462483
is used.
463484

464-
Loading packages will not happen if loading plugins is disabled, see
465-
|load-plugins|.
485+
Loading packages automatically will not happen if loading plugins is disabled,
486+
see |load-plugins|.
487+
488+
To load packages earlier, so that 'runtimepath' gets updated: >
489+
:packloadall
490+
This also works when loading plugins is disabled. The automatic loading will
491+
only happen once.
466492

467493

468494
Using a single plugin and loading it automatically ~

src/ex_cmds2.c

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,12 +2901,38 @@ ex_compiler(exarg_T *eap)
29012901
#endif
29022902

29032903
/*
2904-
* ":runtime {name}"
2904+
* ":runtime [what] {name}"
29052905
*/
29062906
void
29072907
ex_runtime(exarg_T *eap)
29082908
{
2909-
source_runtime(eap->arg, eap->forceit ? DIP_ALL : 0);
2909+
char_u *arg = eap->arg;
2910+
char_u *p = skiptowhite(arg);
2911+
int len = (int)(p - arg);
2912+
int flags = eap->forceit ? DIP_ALL : 0;
2913+
2914+
if (STRNCMP(arg, "START", len) == 0)
2915+
{
2916+
flags += DIP_START + DIP_NORTP;
2917+
arg = skipwhite(arg + len);
2918+
}
2919+
else if (STRNCMP(arg, "OPT", len) == 0)
2920+
{
2921+
flags += DIP_OPT + DIP_NORTP;
2922+
arg = skipwhite(arg + len);
2923+
}
2924+
else if (STRNCMP(arg, "PACK", len) == 0)
2925+
{
2926+
flags += DIP_START + DIP_OPT + DIP_NORTP;
2927+
arg = skipwhite(arg + len);
2928+
}
2929+
else if (STRNCMP(arg, "ALL", len) == 0)
2930+
{
2931+
flags += DIP_START + DIP_OPT;
2932+
arg = skipwhite(arg + len);
2933+
}
2934+
2935+
source_runtime(arg, flags);
29102936
}
29112937

29122938
static void
@@ -3067,15 +3093,16 @@ do_in_runtimepath(
30673093
void (*callback)(char_u *fname, void *ck),
30683094
void *cookie)
30693095
{
3070-
int done;
3096+
int done = FAIL;
30713097
char_u *s;
30723098
int len;
30733099
char *start_dir = "pack/*/start/*/%s";
30743100
char *opt_dir = "pack/*/opt/*/%s";
30753101

3076-
done = do_in_path(p_rtp, name, flags, callback, cookie);
3102+
if ((flags & DIP_NORTP) == 0)
3103+
done = do_in_path(p_rtp, name, flags, callback, cookie);
30773104

3078-
if (done == FAIL && (flags & DIP_START))
3105+
if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_START))
30793106
{
30803107
len = STRLEN(start_dir) + STRLEN(name);
30813108
s = alloc(len);
@@ -3086,7 +3113,7 @@ do_in_runtimepath(
30863113
vim_free(s);
30873114
}
30883115

3089-
if (done == FAIL && (flags & DIP_OPT))
3116+
if ((done == FAIL || (flags & DIP_ALL)) && (flags & DIP_OPT))
30903117
{
30913118
len = STRLEN(opt_dir) + STRLEN(name);
30923119
s = alloc(len);

src/testdir/test_packadd.vim

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,50 @@ func Test_colorscheme()
134134
colorscheme three
135135
call assert_equal(1, g:found_three)
136136
endfunc
137+
138+
func Test_runtime()
139+
let rundir = &packpath . '/runtime/extra'
140+
let startdir = &packpath . '/pack/mine/start/foo/extra'
141+
let optdir = &packpath . '/pack/mine/opt/bar/extra'
142+
call mkdir(rundir, 'p')
143+
call mkdir(startdir, 'p')
144+
call mkdir(optdir, 'p')
145+
call writefile(['let g:sequence .= "run"'], rundir . '/bar.vim')
146+
call writefile(['let g:sequence .= "start"'], startdir . '/bar.vim')
147+
call writefile(['let g:sequence .= "foostart"'], startdir . '/foo.vim')
148+
call writefile(['let g:sequence .= "opt"'], optdir . '/bar.vim')
149+
call writefile(['let g:sequence .= "xxxopt"'], optdir . '/xxx.vim')
150+
exe 'set rtp=' . &packpath . '/runtime'
151+
152+
let g:sequence = ''
153+
runtime extra/bar.vim
154+
call assert_equal('run', g:sequence)
155+
let g:sequence = ''
156+
runtime START extra/bar.vim
157+
call assert_equal('start', g:sequence)
158+
let g:sequence = ''
159+
runtime OPT extra/bar.vim
160+
call assert_equal('opt', g:sequence)
161+
let g:sequence = ''
162+
runtime PACK extra/bar.vim
163+
call assert_equal('start', g:sequence)
164+
let g:sequence = ''
165+
runtime! PACK extra/bar.vim
166+
call assert_equal('startopt', g:sequence)
167+
let g:sequence = ''
168+
runtime PACK extra/xxx.vim
169+
call assert_equal('xxxopt', g:sequence)
170+
171+
let g:sequence = ''
172+
runtime ALL extra/bar.vim
173+
call assert_equal('run', g:sequence)
174+
let g:sequence = ''
175+
runtime ALL extra/foo.vim
176+
call assert_equal('foostart', g:sequence)
177+
let g:sequence = ''
178+
runtime! ALL extra/xxx.vim
179+
call assert_equal('xxxopt', g:sequence)
180+
let g:sequence = ''
181+
runtime! ALL extra/bar.vim
182+
call assert_equal('runstartopt', g:sequence)
183+
endfunc

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+
1553,
746748
/**/
747749
1552,
748750
/**/

src/vim.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,5 +2294,6 @@ int vim_main2(int argc, char **argv);
22942294
#define DIP_ERR 0x04 /* give an error message when none found. */
22952295
#define DIP_START 0x08 /* also use "start" directory in 'packpath' */
22962296
#define DIP_OPT 0x10 /* also use "opt" directory in 'packpath' */
2297+
#define DIP_NORTP 0x20 /* do not use 'runtimepath' */
22972298

22982299
#endif /* VIM__H */

0 commit comments

Comments
 (0)