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:
parent
f43067c7a5
commit
6272f5e289
3 changed files with 94 additions and 17 deletions
51
plug.vim
51
plug.vim
|
@ -80,6 +80,7 @@ let s:TYPE = {
|
||||||
\ 'dict': type({}),
|
\ 'dict': type({}),
|
||||||
\ 'funcref': type(function('call'))
|
\ 'funcref': type(function('call'))
|
||||||
\ }
|
\ }
|
||||||
|
let s:loaded = get(s:, 'loaded', {})
|
||||||
|
|
||||||
function! plug#begin(...)
|
function! plug#begin(...)
|
||||||
if a:0 > 0
|
if a:0 > 0
|
||||||
|
@ -148,9 +149,8 @@ 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')
|
if get(s:loaded, plug.dir, 0) || !has_key(plug, 'on') && !has_key(plug, 'for')
|
||||||
let rtp = s:rtp(plug)
|
let rtp = s:add_rtp(plug)
|
||||||
call s:add_rtp(rtp)
|
|
||||||
if reload
|
if reload
|
||||||
call s:source(rtp, 'plugin/**/*.vim', 'after/plugin/**/*.vim')
|
call s:source(rtp, 'plugin/**/*.vim', 'after/plugin/**/*.vim')
|
||||||
endif
|
endif
|
||||||
|
@ -177,8 +177,11 @@ function! plug#end()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if has_key(plug, 'for')
|
if has_key(plug, 'for')
|
||||||
call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim')
|
let types = s:to_a(plug.for)
|
||||||
for key in 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)
|
if !has_key(lod, key)
|
||||||
let lod[key] = []
|
let lod[key] = []
|
||||||
endif
|
endif
|
||||||
|
@ -247,12 +250,15 @@ function! s:esc(path)
|
||||||
return substitute(a:path, ' ', '\\ ', 'g')
|
return substitute(a:path, ' ', '\\ ', 'g')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:add_rtp(rtp)
|
function! s:add_rtp(plug)
|
||||||
execute 'set rtp^='.s:esc(a:rtp)
|
let rtp = s:rtp(a:plug)
|
||||||
let after = globpath(a:rtp, 'after')
|
execute 'set rtp^='.s:esc(rtp)
|
||||||
|
let after = globpath(rtp, 'after')
|
||||||
if isdirectory(after)
|
if isdirectory(after)
|
||||||
execute 'set rtp+='.s:esc(after)
|
execute 'set rtp+='.s:esc(after)
|
||||||
endif
|
endif
|
||||||
|
let s:loaded[a:plug.dir] = 1
|
||||||
|
return rtp
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:reorg_rtp()
|
function! s:reorg_rtp()
|
||||||
|
@ -287,8 +293,7 @@ function! plug#load(...)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:lod(plug, types)
|
function! s:lod(plug, types)
|
||||||
let rtp = s:rtp(a:plug)
|
let rtp = s:add_rtp(a:plug)
|
||||||
call s:add_rtp(rtp)
|
|
||||||
for dir in a:types
|
for dir in a:types
|
||||||
call s:source(rtp, dir.'/**/*.vim')
|
call s:source(rtp, dir.'/**/*.vim')
|
||||||
endfor
|
endfor
|
||||||
|
@ -339,6 +344,7 @@ function! s:add(repo, ...)
|
||||||
\ a:0 == 1 ? s:parse_options(a:1) : s:base_spec)
|
\ a:0 == 1 ? s:parse_options(a:1) : s:base_spec)
|
||||||
let g:plugs[name] = spec
|
let g:plugs[name] = spec
|
||||||
let g:plugs_order += [name]
|
let g:plugs_order += [name]
|
||||||
|
let s:loaded[spec.dir] = 0
|
||||||
catch
|
catch
|
||||||
return s:err(v:exception)
|
return s:err(v:exception)
|
||||||
endtry
|
endtry
|
||||||
|
@ -419,6 +425,7 @@ function! s:syntax()
|
||||||
syn match plugCommit /^ [0-9a-z]\{7} .*/ contains=plugRelDate,plugSha
|
syn match plugCommit /^ [0-9a-z]\{7} .*/ contains=plugRelDate,plugSha
|
||||||
syn match plugSha /\(^ \)\@<=[0-9a-z]\{7}/ contained
|
syn match plugSha /\(^ \)\@<=[0-9a-z]\{7}/ contained
|
||||||
syn match plugRelDate /([^)]*)$/ contained
|
syn match plugRelDate /([^)]*)$/ contained
|
||||||
|
syn match plugNotLoaded /(not loaded)$/
|
||||||
syn match plugError /^x.*/
|
syn match plugError /^x.*/
|
||||||
syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean
|
syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean
|
||||||
hi def link plug1 Title
|
hi def link plug1 Title
|
||||||
|
@ -439,6 +446,8 @@ function! s:syntax()
|
||||||
hi def link plugError Error
|
hi def link plugError Error
|
||||||
hi def link plugRelDate Comment
|
hi def link plugRelDate Comment
|
||||||
hi def link plugSha Identifier
|
hi def link plugSha Identifier
|
||||||
|
|
||||||
|
hi def link plugNotLoaded Comment
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:lpad(str, len)
|
function! s:lpad(str, len)
|
||||||
|
@ -473,6 +482,7 @@ function! s:prepare()
|
||||||
call s:assign_name()
|
call s:assign_name()
|
||||||
endif
|
endif
|
||||||
silent! unmap <buffer> <cr>
|
silent! unmap <buffer> <cr>
|
||||||
|
silent! unmap <buffer> L
|
||||||
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap cursorline
|
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap cursorline
|
||||||
setf vim-plug
|
setf vim-plug
|
||||||
call s:syntax()
|
call s:syntax()
|
||||||
|
@ -1072,6 +1082,7 @@ function! s:status()
|
||||||
call append(1, '')
|
call append(1, '')
|
||||||
|
|
||||||
let ecnt = 0
|
let ecnt = 0
|
||||||
|
let unloaded = 0
|
||||||
let [cnt, total] = [0, len(g:plugs)]
|
let [cnt, total] = [0, len(g:plugs)]
|
||||||
for [name, spec] in items(g:plugs)
|
for [name, spec] in items(g:plugs)
|
||||||
if has_key(spec, 'uri')
|
if has_key(spec, 'uri')
|
||||||
|
@ -1089,6 +1100,11 @@ function! s:status()
|
||||||
endif
|
endif
|
||||||
let cnt += 1
|
let cnt += 1
|
||||||
let ecnt += !valid
|
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 s:progress_bar(2, repeat('=', cnt), total)
|
||||||
call append(3, s:format_message(valid, name, msg))
|
call append(3, s:format_message(valid, name, msg))
|
||||||
normal! 2G
|
normal! 2G
|
||||||
|
@ -1096,6 +1112,21 @@ function! s:status()
|
||||||
endfor
|
endfor
|
||||||
call setline(1, 'Finished. '.ecnt.' error(s).')
|
call setline(1, 'Finished. '.ecnt.' error(s).')
|
||||||
normal! gg
|
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
|
endfunction
|
||||||
|
|
||||||
function! s:is_preview_window_open()
|
function! s:is_preview_window_open()
|
||||||
|
|
12
test/run
12
test/run
|
@ -21,20 +21,24 @@ make_dirs() {
|
||||||
for d in *; do
|
for d in *; do
|
||||||
cat > $d/xxx.vim << EOF
|
cat > $d/xxx.vim << EOF
|
||||||
" echom expand('<sfile>')
|
" echom expand('<sfile>')
|
||||||
let g:xxx = get(g:, 'xxx', [])
|
let g:$2 = get(g:, '$2', [])
|
||||||
call add(g:xxx, '${1:4}/$d')
|
call add(g:$2, '${1:4}/$d')
|
||||||
EOF
|
EOF
|
||||||
done
|
done
|
||||||
cd - > /dev/null
|
cd - > /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
make_dirs xxx/
|
make_dirs xxx/ xxx
|
||||||
make_dirs xxx/after
|
make_dirs xxx/after xxx
|
||||||
mkdir xxx/doc
|
mkdir xxx/doc
|
||||||
cat > xxx/doc/xxx.txt << DOC
|
cat > xxx/doc/xxx.txt << DOC
|
||||||
hello *xxx*
|
hello *xxx*
|
||||||
DOC
|
DOC
|
||||||
|
|
||||||
|
make_dirs yyy/ yyy
|
||||||
|
make_dirs z1/ z1
|
||||||
|
make_dirs z2/ z2
|
||||||
|
|
||||||
cat > /tmp/mini-vimrc << VIMRC
|
cat > /tmp/mini-vimrc << VIMRC
|
||||||
set rtp+=vader.vim
|
set rtp+=vader.vim
|
||||||
set shell=/bin/bash
|
set shell=/bin/bash
|
||||||
|
|
|
@ -761,6 +761,8 @@ Execute (Filetype-based on-demand loading):
|
||||||
setf xxx
|
setf xxx
|
||||||
AssertEqual ['/ftdetect', 'after/ftdetect', '/plugin', 'after/plugin', '/ftplugin', 'after/ftplugin', '/indent', 'after/indent', '/syntax', 'after/syntax'], g:xxx
|
AssertEqual ['/ftdetect', 'after/ftdetect', '/plugin', 'after/plugin', '/ftplugin', 'after/ftplugin', '/indent', 'after/indent', '/syntax', 'after/syntax'], g:xxx
|
||||||
|
|
||||||
|
Before:
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
~ plug#helptags()
|
~ plug#helptags()
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
@ -772,7 +774,7 @@ Execute (plug#helptags):
|
||||||
Assert filereadable(expand('$PWD/xxx/doc/tags'))
|
Assert filereadable(expand('$PWD/xxx/doc/tags'))
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
~ plug#load()
|
~ Manual loading
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
|
|
||||||
Execute (plug#load - invalid arguments):
|
Execute (plug#load - invalid arguments):
|
||||||
|
@ -783,13 +785,19 @@ Execute (plug#load - invalid arguments):
|
||||||
AssertEqual 0, plug#load('xxx', 'non-existent-plugin')
|
AssertEqual 0, plug#load('xxx', 'non-existent-plugin')
|
||||||
AssertEqual 0, plug#load('non-existent-plugin', 'xxx')
|
AssertEqual 0, plug#load('non-existent-plugin', 'xxx')
|
||||||
|
|
||||||
Execute (plug#load):
|
Execute (on: []):
|
||||||
call plug#begin()
|
call plug#begin()
|
||||||
Plug 'junegunn/rust.vim', { 'on': [] }
|
Plug 'junegunn/rust.vim', { 'on': [] }
|
||||||
call plug#end()
|
call plug#end()
|
||||||
PlugInstall
|
PlugInstall
|
||||||
q
|
q
|
||||||
|
|
||||||
|
Execute (PlugStatus reports (not loaded)):
|
||||||
|
PlugStatus
|
||||||
|
AssertExpect 'not loaded', 1
|
||||||
|
q
|
||||||
|
|
||||||
|
Execute (plug#load to load it):
|
||||||
setf xxx
|
setf xxx
|
||||||
f test.rs
|
f test.rs
|
||||||
Log &filetype
|
Log &filetype
|
||||||
|
@ -797,7 +805,41 @@ Execute (plug#load):
|
||||||
AssertEqual 1, plug#load('rust.vim')
|
AssertEqual 1, plug#load('rust.vim')
|
||||||
AssertEqual 'rust', &filetype
|
AssertEqual 'rust', &filetype
|
||||||
|
|
||||||
Before:
|
Execute (PlugStatus should not contain (not loaded)):
|
||||||
|
PlugStatus
|
||||||
|
AssertExpect 'not loaded', 0
|
||||||
|
q
|
||||||
|
|
||||||
|
Execute (Load plugin from PlugStatus screen with L key in normal mode):
|
||||||
|
call plug#begin()
|
||||||
|
Plug '$PWD/yyy', { 'on': [] }
|
||||||
|
call plug#end()
|
||||||
|
|
||||||
|
PlugStatus
|
||||||
|
AssertExpect 'not loaded', 1
|
||||||
|
Assert !exists('g:yyy'), 'yyy not loaded'
|
||||||
|
/not loaded
|
||||||
|
normal L
|
||||||
|
AssertExpect 'not loaded', 0
|
||||||
|
Assert exists('g:yyy'), 'yyy loaded'
|
||||||
|
q
|
||||||
|
|
||||||
|
Execute (Load plugin from PlugStatus screen with L key in visual mode):
|
||||||
|
call plug#begin()
|
||||||
|
Plug '$PWD/z1', { 'on': [] }
|
||||||
|
Plug '$PWD/z2', { 'for': [] }
|
||||||
|
call plug#end()
|
||||||
|
|
||||||
|
PlugStatus
|
||||||
|
AssertExpect 'not loaded', 2
|
||||||
|
Assert !exists('g:z1'), 'z1 not loaded'
|
||||||
|
Assert !exists('g:z2'), 'z2 not loaded'
|
||||||
|
normal ggVGL
|
||||||
|
AssertExpect 'not loaded', 0
|
||||||
|
Assert exists('g:z1'), 'z1 loaded'
|
||||||
|
Assert exists('g:z2'), 'z2 loaded'
|
||||||
|
q
|
||||||
|
|
||||||
Execute (Cleanup):
|
Execute (Cleanup):
|
||||||
silent! call system('rm -rf '.temp_plugged)
|
silent! call system('rm -rf '.temp_plugged)
|
||||||
silent! call rename('fzf', 'fzf-staged')
|
silent! call rename('fzf', 'fzf-staged')
|
||||||
|
|
Loading…
Reference in a new issue