vim-patch:7.4.1384

Problem:    It is not easy to use a set of plugins and their dependencies.
Solution:   Add packages, ":loadopt", 'packpath'.

f6fee0e2d4
This commit is contained in:
James McCoy 2016-04-25 23:07:51 -04:00
parent 6cee9d1a17
commit e902a172ef
12 changed files with 206 additions and 28 deletions

View File

@ -1,4 +1,4 @@
*options.txt* For Vim version 7.4. Last change: 2016 Feb 20
*options.txt* For Vim version 7.4. Last change: 2016 Feb 21
VIM REFERENCE MANUAL by Bram Moolenaar
@ -4499,6 +4499,13 @@ A jump table for the options with a short description can be found at |Q_op|.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.
*'packpath'* *'pp'*
'packpath' 'pp' string (default: see 'runtimepath')
{not in Vi}
{not available without the |+packages| feature}
Directories used to find packages. See |packages|.
*'paragraphs'* *'para'*
'paragraphs' 'para' string (default "IPLPPPQPP TPHPLIPpLpItpplpipbp")
global

View File

@ -1,4 +1,4 @@
*repeat.txt* For Vim version 7.4. Last change: 2016 Feb 12
*repeat.txt* For Vim version 7.4. Last change: 2016 Feb 21
VIM REFERENCE MANUAL by Bram Moolenaar
@ -12,8 +12,9 @@ Chapter 26 of the user manual introduces repeating |usr_26.txt|.
2. Multiple repeats |multi-repeat|
3. Complex repeats |complex-repeat|
4. Using Vim scripts |using-scripts|
5. Debugging scripts |debug-scripts|
6. Profiling |profiling|
5. Using Vim packages |packages|
6. Debugging scripts |debug-scripts|
7. Profiling |profiling|
==============================================================================
1. Single repeats *single-repeat*
@ -203,6 +204,22 @@ For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
When 'verbose' is two or higher, there is a message
about each searched file.
*:loadp* *:loadplugin*
:loadp[lugin] {name} Search for an optional plugin directory and source the
plugin files found. It is similar to: >
:runtime pack/*/opt/{name}/plugin/*.vim
< However, `:loadplugin` uses 'packpath' instead of
'runtimepath'. And the directory found is added to
'runtimepath'.
Note that {name} is the directory name, not the name
of the .vim file. If the "{name}/plugin" directory
contains more than one file they are all sourced.
Also see |load-plugin|.
{not available without the |+packages| feature}
:scripte[ncoding] [encoding] *:scripte* *:scriptencoding* *E167*
Specify the character encoding used in the script.
The following lines will be converted from [encoding]
@ -373,7 +390,56 @@ Rationale:
< Therefore the unusual leading backslash is used.
==============================================================================
5. Debugging scripts *debug-scripts*
5. Using Vim packages *packages*
A Vim package is a directory that contains one or more plugins. The
advantages over normal plugins:
- A package can be downloaded as an archive and unpacked in its own directory.
That makes it easy to updated and/or remove.
- A package can be a git, mercurial, etc. respository. That makes it really
easy to update.
- A package can contain multiple plugins that depend on each other.
- A package can contain plugins that are automatically loaded on startup and
ones that are only loaded when needed with `:loadplugin`.
Let's assume your Vim files are in the "~/.local/share/nvim/site" directory
and you want to add a package from a zip archive "/tmp/mypack.zip":
% mkdir -p ~/.local/share/nvim/site/pack/my
% cd ~/.local/share/nvim/site/pack/my
% unzip /tmp/mypack.zip
The directory name "my" is arbitrary, you can pick anything you like.
You would now have these files under ~/.local/share/nvim/site:
pack/my/README.txt
pack/my/ever/always/plugin/always.vim
pack/my/ever/always/syntax/always.vim
pack/my/opt/mydebug/plugin/debugger.vim
When Vim starts up it scans all directories in 'packpath' for plugins under the
"ever" directory and loads them. When found that directory is added to
'runtimepath'.
In the example Vim will find "my/ever/always/plugin/always.vim" and adds
"~/.local/share/nvim/site/pack/my/ever/always" to 'runtimepath'.
If the "always" plugin kicks in and sets the 'filetype' to "always", Vim will
find the syntax/always.vim file, because its directory is in 'runtimepath'.
*load-plugin*
To load an optional plugin from a pack use the `:loadplugin` command: >
:loadplugin mydebug
This could be done inside always.vim, if some conditions are met.
Or you could add this command to your |.vimrc|.
It is perfectly normal for a package to only have files in the "opt"
directory. You then need to load each plugin when you want to use it.
Loading packages will not happen if loading plugins is disabled, see
|load-plugins|.
==============================================================================
6. Debugging scripts *debug-scripts*
Besides the obvious messages that you can add to your scripts to find out what
they are doing, Vim offers a debug mode. This allows you to step through a
@ -597,7 +663,7 @@ OBSCURE
user, don't use typeahead for debug commands.
==============================================================================
6. Profiling *profile* *profiling*
7. Profiling *profile* *profiling*
Profiling means that Vim measures the time that is spent on executing
functions and/or scripts. The |+profile| feature is required for this.

View File

@ -1,4 +1,4 @@
*starting.txt* For Vim version 7.4. Last change: 2016 Feb 18
*starting.txt* For Vim version 7.4. Last change: 2016 Feb 21
VIM REFERENCE MANUAL by Bram Moolenaar
@ -463,6 +463,10 @@ accordingly. Vim proceeds in this order:
commands from the command line have not been executed yet. You can
use "--cmd 'set noloadplugins'" |--cmd|.
Plugin packs are loaded. These are plugins, as above, but found in
'packpath' directories. Every plugin directory found is added in
'runtimepath'. See |packages|.
7. Set 'shellpipe' and 'shellredir'
The 'shellpipe' and 'shellredir' options are set according to the
value of the 'shell' option, unless they have been set before.

View File

@ -1,7 +1,7 @@
" These commands create the option window.
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last Change: 2015 Jul 22
" Last Change: 2016 Feb 21
" If there already is an option window, jump to that one.
if bufwinnr("option-window") > 0
@ -228,6 +228,8 @@ else
endif
call append("$", "runtimepath\tlist of directories used for runtime files and plugins")
call <SID>OptionG("rtp", &rtp)
call append("$", "packpath\tlist of directories used for plugin packages")
call <SID>OptionG("pp", &pp)
call append("$", "helpfile\tname of the main help file")
call <SID>OptionG("hf", &hf)

View File

@ -10782,6 +10782,7 @@ static void f_has(typval_T *argvars, typval_T *rettv)
"mouse",
"multi_byte",
"multi_lang",
"packages",
"path_extra",
"persistent_undo",
"postscript",

View File

@ -1452,6 +1452,12 @@ return {
addr_type=ADDR_LINES,
func='ex_loadkeymap',
},
{
command='loadplugin',
flags=bit.bor(BANG, FILE1, TRLBAR, SBOXOK, CMDWIN),
addr_type=ADDR_LINES,
func='ex_loadplugin',
},
{
command='lockmarks',
flags=bit.bor(NEEDARG, EXTRA, NOTRLCOM),

View File

@ -2284,21 +2284,9 @@ int source_runtime(char_u *name, int all)
return do_in_runtimepath(name, all, source_callback, NULL);
}
/// Find "name" in 'runtimepath'. When found, invoke the callback function for
/// it: callback(fname, "cookie")
/// When "all" is true repeat for all matches, otherwise only the first one is
/// used.
/// Returns OK when at least one match found, FAIL otherwise.
/// If "name" is NULL calls callback for each entry in runtimepath. Cookie is
/// passed by reference in this case, setting it to NULL indicates that callback
/// has done its job.
int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback,
void *cookie)
static int do_in_path(char_u *path, char_u *name, bool all,
DoInRuntimepathCB callback, void *cookie)
{
char_u *rtp;
char_u *np;
char_u *buf;
char_u *rtp_copy;
char_u *tail;
int num_files;
char_u **files;
@ -2307,18 +2295,18 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback,
// Make a copy of 'runtimepath'. Invoking the callback may change the
// value.
rtp_copy = vim_strsave(p_rtp);
buf = xmallocz(MAXPATHL);
char_u *rtp_copy = vim_strsave(path);
char_u *buf = xmallocz(MAXPATHL);
{
if (p_verbose > 1 && name != NULL) {
verbose_enter();
smsg(_("Searching for \"%s\" in \"%s\""),
(char *)name, (char *)p_rtp);
(char *)name, (char *)path);
verbose_leave();
}
// Loop over all entries in 'runtimepath'.
rtp = rtp_copy;
char_u *rtp = rtp_copy;
while (*rtp != NUL && (all || !did_one)) {
// Copy the path from 'runtimepath' to buf[].
copy_option_part(&rtp, buf, MAXPATHL, ",");
@ -2332,7 +2320,7 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback,
tail = buf + STRLEN(buf);
// Loop over all patterns in "name"
np = name;
char_u *np = name;
while (*np != NUL && (all || !did_one)) {
// Append the pattern from "name" to buf[].
assert(MAXPATHL >= (tail - buf));
@ -2373,6 +2361,95 @@ int do_in_runtimepath(char_u *name, int all, DoInRuntimepathCB callback,
return did_one ? OK : FAIL;
}
/// Find "name" in 'runtimepath'. When found, invoke the callback function for
/// it: callback(fname, "cookie")
/// When "all" is true repeat for all matches, otherwise only the first one is
/// used.
/// Returns OK when at least one match found, FAIL otherwise.
/// If "name" is NULL calls callback for each entry in runtimepath. Cookie is
/// passed by reference in this case, setting it to NULL indicates that callback
/// has done its job.
int do_in_runtimepath(char_u *name, bool all, DoInRuntimepathCB callback,
void *cookie)
{
return do_in_path(p_rtp, name, all, callback, cookie);
}
static void source_pack_plugin(char_u *fname, void *cookie)
{
char_u *p6, *p5, *p4, *p3, *p2, *p1, *p;
char_u *new_rtp;
p4 = p3 = p2 = p1 = get_past_head(fname);
for (p = p1; *p; mb_ptr_adv(p)) {
if (vim_ispathsep_nocolon(*p)) {
p6 = p5; p5 = p4; p4 = p3; p3 = p2; p2 = p1; p1 = p;
}
}
// now we have:
// rtp/pack/name/ever/name/plugin/name.vim
// p6 p5 p4 p3 p2 p1
// find the part up to "pack" in 'runtimepath'
char_u c = *p6;
*p6 = NUL;
p = (char_u *)strstr((char *)p_rtp, (char *)fname);
if (p == NULL) {
// not found, append at the end
p = p_rtp + STRLEN(p_rtp);
} else {
// append after the matching directory.
p += STRLEN(fname);
}
*p6 = c;
c = *p2;
*p2 = NUL;
if (strstr((char *)p_rtp, (char *)fname) == NULL) {
// directory not in 'runtimepath', add it
size_t oldlen = STRLEN(p_rtp);
size_t addlen = STRLEN(fname);
new_rtp = try_malloc(oldlen + addlen + 1);
if (new_rtp == NULL) {
*p2 = c;
return;
}
uintptr_t keep = (uintptr_t)(p - p_rtp);
memmove(new_rtp, p_rtp, keep);
new_rtp[keep] = ',';
memmove(new_rtp + keep + 1, fname, addlen + 1);
if (p_rtp[keep] != NUL) {
memmove(new_rtp + keep + 1 + addlen, p_rtp + keep,
oldlen - keep + 1);
}
free_string_option(p_rtp);
p_rtp = new_rtp;
}
*p2 = c;
(void)do_source(fname, false, DOSO_NONE);
}
// Source the plugins in the package directories.
void source_packages(void)
{
do_in_path(p_pp, (char_u *)"pack/*/ever/*/plugin/*.vim",
true, source_pack_plugin, NULL);
}
// ":loadplugin {name}"
void ex_loadplugin(exarg_T *eap)
{
static const char *pattern = "pack/*/opt/%s/plugin/*.vim";
size_t len = STRLEN(pattern) + STRLEN(eap->arg);
char *pat = xmallocz(len);
vim_snprintf(pat, len, pattern, eap->arg);
do_in_path(p_pp, (char_u *)pat, true, source_pack_plugin, NULL);
xfree(pat);
}
/// ":options"
void ex_options(exarg_T *eap)
{

View File

@ -1243,6 +1243,9 @@ static void load_plugins(void)
if (p_lpl) {
source_runtime((char_u *)"plugin/**/*.vim", TRUE);
TIME_MSG("loading plugins");
source_packages();
TIME_MSG("loading packages");
}
}

View File

@ -5839,6 +5839,7 @@ set_context_in_set_cmd (
if (p == (char_u *)&p_bdir
|| p == (char_u *)&p_dir
|| p == (char_u *)&p_path
|| p == (char_u *)&p_pp
|| p == (char_u *)&p_rtp
|| p == (char_u *)&p_cdpath
|| p == (char_u *)&p_vdir

View File

@ -521,6 +521,7 @@ EXTERN int p_ari; /* 'allowrevins' */
EXTERN int p_ri; /* 'revins' */
EXTERN int p_ru; /* 'ruler' */
EXTERN char_u *p_ruf; /* 'rulerformat' */
EXTERN char_u *p_pp; /* 'packpath' */
EXTERN char_u *p_rtp; /* 'runtimepath' */
EXTERN long p_sj; /* 'scrolljump' */
EXTERN long p_so; /* 'scrolloff' */

View File

@ -1639,6 +1639,16 @@ return {
varname='p_opfunc',
defaults={if_true={vi=""}}
},
{
full_name='packpath', abbreviation='pp',
type='string', list='onecomma', scope={'global'},
deny_duplicates=true,
secure=true,
vi_def=true,
expand=true,
varname='p_pp',
defaults={if_true={vi=''}}
},
{
full_name='paragraphs', abbreviation='para',
type='string', scope={'global'},

View File

@ -311,7 +311,7 @@ static int included_patches[] = {
// 1387 NA
// 1386 NA
// 1385 NA
// 1384,
1384,
// 1383 NA
// 1382 NA
// 1381 NA