On-demand loading with <Plug> mappings (experimental)
e.g. Plug 'xxx', { 'on': '<Plug>xxx' }
			
			
This commit is contained in:
		
							parent
							
								
									1c2d394782
								
							
						
					
					
						commit
						cbe2e519d0
					
				
							
								
								
									
										29
									
								
								plug.vim
									
									
									
									
									
								
							
							
						
						
									
										29
									
								
								plug.vim
									
									
									
									
									
								
							|  | @ -114,9 +114,12 @@ function! plug#end() | ||||||
|     if has_key(plug, 'on') |     if has_key(plug, 'on') | ||||||
|       let commands = type(plug.on) == 1 ? [plug.on] : plug.on |       let commands = type(plug.on) == 1 ? [plug.on] : plug.on | ||||||
|       for cmd in commands |       for cmd in commands | ||||||
|         if !exists(':'.cmd) |         if cmd =~ '^<Plug>.\+' | ||||||
|           execute printf( |           execute printf( | ||||||
|           \ "command! -nargs=* -bang %s call s:lod(%s, '<bang>', <q-args>, %s)", |           \ "noremap %s :call <SID>lod_map(%s, %s)<CR>", cmd, string(cmd), string(plug)) | ||||||
|  |         elseif !exists(':'.cmd) | ||||||
|  |           execute printf( | ||||||
|  |           \ "command! -nargs=* -bang %s call s:lod_cmd(%s, '<bang>', <q-args>, %s)", | ||||||
|           \ cmd, string(cmd), string(plug)) |           \ cmd, string(cmd), string(plug)) | ||||||
|         endif |         endif | ||||||
|       endfor |       endfor | ||||||
|  | @ -143,8 +146,7 @@ function! s:add_rtp(rtp) | ||||||
|   endif |   endif | ||||||
| endfunction | endfunction | ||||||
| 
 | 
 | ||||||
| function! s:lod(cmd, bang, args, plug) | function! s:lod(plug) | ||||||
|   execute 'delc '.a:cmd |  | ||||||
|   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', 'after'] |   for dir in ['plugin', 'after'] | ||||||
|  | @ -152,9 +154,28 @@ function! s:lod(cmd, bang, args, plug) | ||||||
|       execute 'source '.vim |       execute 'source '.vim | ||||||
|     endfor |     endfor | ||||||
|   endfor |   endfor | ||||||
|  | endfunction | ||||||
|  | 
 | ||||||
|  | function! s:lod_cmd(cmd, bang, args, plug) | ||||||
|  |   execute 'delc '.a:cmd | ||||||
|  |   call s:lod(a:plug) | ||||||
|   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) | ||||||
|  |   execute 'unmap '.a:map | ||||||
|  |   call s:lod(a:plug) | ||||||
|  |   let extra = '' | ||||||
|  |   while 1 | ||||||
|  |     let c = getchar(0) | ||||||
|  |     if c == 0 | ||||||
|  |       break | ||||||
|  |     endif | ||||||
|  |     let extra .= nr2char(c) | ||||||
|  |   endwhile | ||||||
|  |   call feedkeys(substitute(a:map, '^<Plug>', "\<Plug>", '') . extra) | ||||||
|  | endfunction | ||||||
|  | 
 | ||||||
| function! s:add(...) | function! s:add(...) | ||||||
|   let force = a:1 |   let force = a:1 | ||||||
|   let opts = { 'branch': 'master' } |   let opts = { 'branch': 'master' } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user