mirror of
https://github.com/junegunn/vim-plug.git
synced 2025-12-24 17:41:26 +08:00
Improve PlugStatus
- Display load status - Load plugin with 'L' key (This commit also allows not loading a plugin with `'for': []`. It used to load ftdetect files.)
This commit is contained in:
51
plug.vim
51
plug.vim
@@ -80,6 +80,7 @@ let s:TYPE = {
|
||||
\ 'dict': type({}),
|
||||
\ 'funcref': type(function('call'))
|
||||
\ }
|
||||
let s:loaded = get(s:, 'loaded', {})
|
||||
|
||||
function! plug#begin(...)
|
||||
if a:0 > 0
|
||||
@@ -148,9 +149,8 @@ function! plug#end()
|
||||
" need to loop through the plugins in reverse
|
||||
for name in reverse(copy(g:plugs_order))
|
||||
let plug = g:plugs[name]
|
||||
if !has_key(plug, 'on') && !has_key(plug, 'for')
|
||||
let rtp = s:rtp(plug)
|
||||
call s:add_rtp(rtp)
|
||||
if get(s:loaded, plug.dir, 0) || !has_key(plug, 'on') && !has_key(plug, 'for')
|
||||
let rtp = s:add_rtp(plug)
|
||||
if reload
|
||||
call s:source(rtp, 'plugin/**/*.vim', 'after/plugin/**/*.vim')
|
||||
endif
|
||||
@@ -177,8 +177,11 @@ function! plug#end()
|
||||
endif
|
||||
|
||||
if has_key(plug, 'for')
|
||||
call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim')
|
||||
for key in s:to_a(plug.for)
|
||||
let types = s:to_a(plug.for)
|
||||
if !empty(types)
|
||||
call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim')
|
||||
endif
|
||||
for key in types
|
||||
if !has_key(lod, key)
|
||||
let lod[key] = []
|
||||
endif
|
||||
@@ -247,12 +250,15 @@ function! s:esc(path)
|
||||
return substitute(a:path, ' ', '\\ ', 'g')
|
||||
endfunction
|
||||
|
||||
function! s:add_rtp(rtp)
|
||||
execute 'set rtp^='.s:esc(a:rtp)
|
||||
let after = globpath(a:rtp, 'after')
|
||||
function! s:add_rtp(plug)
|
||||
let rtp = s:rtp(a:plug)
|
||||
execute 'set rtp^='.s:esc(rtp)
|
||||
let after = globpath(rtp, 'after')
|
||||
if isdirectory(after)
|
||||
execute 'set rtp+='.s:esc(after)
|
||||
endif
|
||||
let s:loaded[a:plug.dir] = 1
|
||||
return rtp
|
||||
endfunction
|
||||
|
||||
function! s:reorg_rtp()
|
||||
@@ -287,8 +293,7 @@ function! plug#load(...)
|
||||
endfunction
|
||||
|
||||
function! s:lod(plug, types)
|
||||
let rtp = s:rtp(a:plug)
|
||||
call s:add_rtp(rtp)
|
||||
let rtp = s:add_rtp(a:plug)
|
||||
for dir in a:types
|
||||
call s:source(rtp, dir.'/**/*.vim')
|
||||
endfor
|
||||
@@ -339,6 +344,7 @@ function! s:add(repo, ...)
|
||||
\ a:0 == 1 ? s:parse_options(a:1) : s:base_spec)
|
||||
let g:plugs[name] = spec
|
||||
let g:plugs_order += [name]
|
||||
let s:loaded[spec.dir] = 0
|
||||
catch
|
||||
return s:err(v:exception)
|
||||
endtry
|
||||
@@ -419,6 +425,7 @@ function! s:syntax()
|
||||
syn match plugCommit /^ [0-9a-z]\{7} .*/ contains=plugRelDate,plugSha
|
||||
syn match plugSha /\(^ \)\@<=[0-9a-z]\{7}/ contained
|
||||
syn match plugRelDate /([^)]*)$/ contained
|
||||
syn match plugNotLoaded /(not loaded)$/
|
||||
syn match plugError /^x.*/
|
||||
syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean
|
||||
hi def link plug1 Title
|
||||
@@ -439,6 +446,8 @@ function! s:syntax()
|
||||
hi def link plugError Error
|
||||
hi def link plugRelDate Comment
|
||||
hi def link plugSha Identifier
|
||||
|
||||
hi def link plugNotLoaded Comment
|
||||
endfunction
|
||||
|
||||
function! s:lpad(str, len)
|
||||
@@ -473,6 +482,7 @@ function! s:prepare()
|
||||
call s:assign_name()
|
||||
endif
|
||||
silent! unmap <buffer> <cr>
|
||||
silent! unmap <buffer> L
|
||||
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap cursorline
|
||||
setf vim-plug
|
||||
call s:syntax()
|
||||
@@ -1072,6 +1082,7 @@ function! s:status()
|
||||
call append(1, '')
|
||||
|
||||
let ecnt = 0
|
||||
let unloaded = 0
|
||||
let [cnt, total] = [0, len(g:plugs)]
|
||||
for [name, spec] in items(g:plugs)
|
||||
if has_key(spec, 'uri')
|
||||
@@ -1089,6 +1100,11 @@ function! s:status()
|
||||
endif
|
||||
let cnt += 1
|
||||
let ecnt += !valid
|
||||
" `s:loaded` entry can be missing if PlugUpgraded
|
||||
if valid && get(s:loaded, spec.dir, -1) == 0
|
||||
let unloaded = 1
|
||||
let msg .= ' (not loaded)'
|
||||
endif
|
||||
call s:progress_bar(2, repeat('=', cnt), total)
|
||||
call append(3, s:format_message(valid, name, msg))
|
||||
normal! 2G
|
||||
@@ -1096,6 +1112,21 @@ function! s:status()
|
||||
endfor
|
||||
call setline(1, 'Finished. '.ecnt.' error(s).')
|
||||
normal! gg
|
||||
if unloaded
|
||||
echo "Press 'L' on each line to load plugin"
|
||||
nnoremap <silent> <buffer> L :call <SID>status_load(line('.'))<cr>
|
||||
xnoremap <silent> <buffer> L :call <SID>status_load(line('.'))<cr>
|
||||
end
|
||||
endfunction
|
||||
|
||||
function! s:status_load(lnum)
|
||||
let line = getline(a:lnum)
|
||||
let matches = matchlist(line, '^- \([^:]*\):.*(not loaded)$')
|
||||
if !empty(matches)
|
||||
let name = matches[1]
|
||||
call plug#load(name)
|
||||
call setline(a:lnum, substitute(line, ' (not loaded)$', '', ''))
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:is_preview_window_open()
|
||||
|
||||
Reference in New Issue
Block a user