On-demand loading on filetypes (#21)
This commit is contained in:
parent
7e69a50890
commit
b5b687ad9a
|
@ -38,7 +38,8 @@ call plug#begin('~/.vim/plugged')
|
||||||
|
|
||||||
Plug 'junegunn/seoul256.vim'
|
Plug 'junegunn/seoul256.vim'
|
||||||
Plug 'junegunn/vim-easy-align'
|
Plug 'junegunn/vim-easy-align'
|
||||||
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
|
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
|
||||||
|
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
|
||||||
" Plug 'user/repo1', 'branch_or_tag'
|
" Plug 'user/repo1', 'branch_or_tag'
|
||||||
" Plug 'user/repo2', { 'rtp': 'vim/plugin/dir', 'branch': 'devel' }
|
" Plug 'user/repo2', { 'rtp': 'vim/plugin/dir', 'branch': 'devel' }
|
||||||
" Plug 'git@github.com:junegunn/vim-github-dashboard.git'
|
" Plug 'git@github.com:junegunn/vim-github-dashboard.git'
|
||||||
|
@ -97,6 +98,12 @@ Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
|
||||||
|
|
||||||
" Multiple commands
|
" Multiple commands
|
||||||
Plug 'junegunn/vim-github-dashboard', { 'on': ['GHDashboard', 'GHActivity'] }
|
Plug 'junegunn/vim-github-dashboard', { 'on': ['GHDashboard', 'GHActivity'] }
|
||||||
|
|
||||||
|
" Loaded when clojure file is opened
|
||||||
|
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
|
||||||
|
|
||||||
|
" On-demand loading on both conditions
|
||||||
|
Plug 'junegunn/vader.vim', { 'on': 'Vader', 'for': 'vader' }
|
||||||
```
|
```
|
||||||
|
|
||||||
### Dependency resolution
|
### Dependency resolution
|
||||||
|
|
47
plug.vim
47
plug.vim
|
@ -58,6 +58,7 @@ set cpo&vim
|
||||||
let s:plug_source = 'https://raw.github.com/junegunn/vim-plug/master/plug.vim'
|
let s:plug_source = 'https://raw.github.com/junegunn/vim-plug/master/plug.vim'
|
||||||
let s:plug_file = 'Plugfile'
|
let s:plug_file = 'Plugfile'
|
||||||
let s:plug_buf = -1
|
let s:plug_buf = -1
|
||||||
|
let s:loaded = {}
|
||||||
let s:is_win = has('win32') || has('win64')
|
let s:is_win = has('win32') || has('win64')
|
||||||
let s:me = expand('<sfile>:p')
|
let s:me = expand('<sfile>:p')
|
||||||
|
|
||||||
|
@ -102,6 +103,10 @@ function! plug#begin(...)
|
||||||
return 1
|
return 1
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:to_a(v)
|
||||||
|
return type(a:v) == 3 ? a:v : [a:v]
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! plug#end()
|
function! plug#end()
|
||||||
if !exists('g:plugs')
|
if !exists('g:plugs')
|
||||||
echoerr 'Call plug#begin() first'
|
echoerr 'Call plug#begin() first'
|
||||||
|
@ -112,6 +117,13 @@ function! plug#end()
|
||||||
let keys = keys(s:extend(keys))
|
let keys = keys(s:extend(keys))
|
||||||
endwhile
|
endwhile
|
||||||
|
|
||||||
|
if exists('#PlugLOD')
|
||||||
|
augroup PlugLOD
|
||||||
|
autocmd!
|
||||||
|
augroup END
|
||||||
|
augroup! PlugLOD
|
||||||
|
endif
|
||||||
|
|
||||||
filetype off
|
filetype off
|
||||||
" we want to make sure the plugin directories are added to rtp in the same
|
" we want to make sure the plugin directories are added to rtp in the same
|
||||||
" order that they are registered with the Plug command. since the s:add_rtp
|
" order that they are registered with the Plug command. since the s:add_rtp
|
||||||
|
@ -119,8 +131,13 @@ function! plug#end()
|
||||||
" need to loop through the plugins in reverse
|
" need to loop through the plugins in reverse
|
||||||
for name in reverse(copy(g:plugs_order))
|
for name in reverse(copy(g:plugs_order))
|
||||||
let plug = g:plugs[name]
|
let plug = g:plugs[name]
|
||||||
|
if !has_key(plug, 'on') && !has_key(plug, 'for')
|
||||||
|
call s:add_rtp(s:rtp(plug))
|
||||||
|
continue
|
||||||
|
endif
|
||||||
|
|
||||||
if has_key(plug, 'on')
|
if has_key(plug, 'on')
|
||||||
let commands = type(plug.on) == 1 ? [plug.on] : plug.on
|
let commands = s:to_a(plug.on)
|
||||||
for cmd in commands
|
for cmd in commands
|
||||||
if cmd =~ '^<Plug>.\+'
|
if cmd =~ '^<Plug>.\+'
|
||||||
if empty(mapcheck(cmd)) && empty(mapcheck(cmd, 'i'))
|
if empty(mapcheck(cmd)) && empty(mapcheck(cmd, 'i'))
|
||||||
|
@ -136,8 +153,16 @@ function! plug#end()
|
||||||
\ cmd, string(cmd), string(plug))
|
\ cmd, string(cmd), string(plug))
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
else
|
endif
|
||||||
call s:add_rtp(s:rtp(plug))
|
|
||||||
|
if has_key(plug, 'for')
|
||||||
|
for vim in split(globpath(s:rtp(plug), 'ftdetect/**/*.vim'), '\n')
|
||||||
|
execute 'source '.vim
|
||||||
|
endfor
|
||||||
|
augroup PlugLOD
|
||||||
|
execute printf('autocmd FileType %s call <SID>lod_ft(%s, %s)',
|
||||||
|
\ join(s:to_a(plug.for), ','), string(name), string(plug))
|
||||||
|
augroup END
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
filetype plugin indent on
|
filetype plugin indent on
|
||||||
|
@ -163,26 +188,34 @@ function! s:add_rtp(rtp)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:lod(plug)
|
function! s:lod(plug, types)
|
||||||
let rtp = s:rtp(a:plug)
|
let rtp = s:rtp(a:plug)
|
||||||
call s:add_rtp(rtp)
|
call s:add_rtp(rtp)
|
||||||
for dir in ['plugin', 'ftdetect', 'after']
|
for dir in a:types
|
||||||
for vim in split(globpath(rtp, dir.'/**/*.vim'), '\n')
|
for vim in split(globpath(rtp, dir.'/**/*.vim'), '\n')
|
||||||
execute 'source '.vim
|
execute 'source '.vim
|
||||||
endfor
|
endfor
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:lod_ft(name, plug)
|
||||||
|
if has_key(s:loaded, a:name)
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
call s:lod(a:plug, ['plugin', 'after'])
|
||||||
|
let s:loaded[a:name] = 1
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:lod_cmd(cmd, bang, args, plug)
|
function! s:lod_cmd(cmd, bang, args, plug)
|
||||||
execute 'delc '.a:cmd
|
execute 'delc '.a:cmd
|
||||||
call s:lod(a:plug)
|
call s:lod(a:plug, ['plugin', 'ftdetect', 'after'])
|
||||||
execute printf("%s%s %s", a:cmd, a:bang, a:args)
|
execute printf("%s%s %s", a:cmd, a:bang, a:args)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:lod_map(map, plug)
|
function! s:lod_map(map, plug)
|
||||||
execute 'unmap '.a:map
|
execute 'unmap '.a:map
|
||||||
execute 'iunmap '.a:map
|
execute 'iunmap '.a:map
|
||||||
call s:lod(a:plug)
|
call s:lod(a:plug, ['plugin', 'ftdetect', 'after'])
|
||||||
let extra = ''
|
let extra = ''
|
||||||
while 1
|
while 1
|
||||||
let c = getchar(0)
|
let c = getchar(0)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user