comparison vim/autoload/plug.vim @ 226:55ff9bb3ea22

Clean up vimrc
author zegervdv <zegervdv@me.com>
date Wed, 21 Jan 2015 10:40:29 +0100
parents ed108055146c
children d29157c632c0
comparison
equal deleted inserted replaced
225:1d9bec72b9b3 226:55ff9bb3ea22
71 let s:plug_src = 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' 71 let s:plug_src = 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
72 let s:plug_tab = get(s:, 'plug_tab', -1) 72 let s:plug_tab = get(s:, 'plug_tab', -1)
73 let s:plug_buf = get(s:, 'plug_buf', -1) 73 let s:plug_buf = get(s:, 'plug_buf', -1)
74 let s:mac_gui = has('gui_macvim') && has('gui_running') 74 let s:mac_gui = has('gui_macvim') && has('gui_running')
75 let s:is_win = has('win32') || has('win64') 75 let s:is_win = has('win32') || has('win64')
76 let s:nvim = exists('##JobActivity') && !s:is_win 76 let s:nvim = has('nvim') && !s:is_win
77 let s:me = resolve(expand('<sfile>:p')) 77 let s:me = resolve(expand('<sfile>:p'))
78 let s:base_spec = { 'branch': 'master', 'frozen': 0 } 78 let s:base_spec = { 'branch': 'master', 'frozen': 0 }
79 let s:TYPE = { 79 let s:TYPE = {
80 \ 'string': type(''), 80 \ 'string': type(''),
81 \ 'list': type([]), 81 \ 'list': type([]),
134 execute 'source' vim 134 execute 'source' vim
135 endfor 135 endfor
136 endfor 136 endfor
137 endfunction 137 endfunction
138 138
139 function! s:assoc(dict, key, val)
140 let a:dict[a:key] = add(get(a:dict, a:key, []), a:val)
141 endfunction
142
139 function! plug#end() 143 function! plug#end()
140 if !exists('g:plugs') 144 if !exists('g:plugs')
141 return s:err('Call plug#begin() first') 145 return s:err('Call plug#begin() first')
142 endif 146 endif
143 147
145 augroup PlugLOD 149 augroup PlugLOD
146 autocmd! 150 autocmd!
147 augroup END 151 augroup END
148 augroup! PlugLOD 152 augroup! PlugLOD
149 endif 153 endif
150 let lod = {} 154 let lod = { 'ft': {}, 'map': {}, 'cmd': {} }
151 155
152 filetype off 156 filetype off
153 for name in g:plugs_order 157 for name in g:plugs_order
154 let plug = g:plugs[name] 158 let plug = g:plugs[name]
155 if get(s:loaded, name, 0) || !has_key(plug, 'on') && !has_key(plug, 'for') 159 if get(s:loaded, name, 0) || !has_key(plug, 'on') && !has_key(plug, 'for')
160 if has_key(plug, 'on') 164 if has_key(plug, 'on')
161 let s:triggers[name] = { 'map': [], 'cmd': [] } 165 let s:triggers[name] = { 'map': [], 'cmd': [] }
162 for cmd in s:to_a(plug.on) 166 for cmd in s:to_a(plug.on)
163 if cmd =~ '^<Plug>.\+' 167 if cmd =~ '^<Plug>.\+'
164 if empty(mapcheck(cmd)) && empty(mapcheck(cmd, 'i')) 168 if empty(mapcheck(cmd)) && empty(mapcheck(cmd, 'i'))
165 for [mode, map_prefix, key_prefix] in 169 call s:assoc(lod.map, cmd, name)
166 \ [['i', '<C-O>', ''], ['n', '', ''], ['v', '', 'gv'], ['o', '', '']]
167 execute printf(
168 \ '%snoremap <silent> %s %s:<C-U>call <SID>lod_map(%s, %s, "%s")<CR>',
169 \ mode, cmd, map_prefix, string(cmd), string(name), key_prefix)
170 endfor
171 endif 170 endif
172 call add(s:triggers[name].map, cmd) 171 call add(s:triggers[name].map, cmd)
173 elseif cmd =~ '^[A-Z]' 172 elseif cmd =~ '^[A-Z]'
174 if exists(':'.cmd) != 2 173 if exists(':'.cmd) != 2
175 execute printf( 174 call s:assoc(lod.cmd, cmd, name)
176 \ 'command! -nargs=* -range -bang %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, %s)',
177 \ cmd, string(cmd), string(name))
178 endif 175 endif
179 call add(s:triggers[name].cmd, cmd) 176 call add(s:triggers[name].cmd, cmd)
180 endif 177 endif
181 endfor 178 endfor
182 endif 179 endif
184 if has_key(plug, 'for') 181 if has_key(plug, 'for')
185 let types = s:to_a(plug.for) 182 let types = s:to_a(plug.for)
186 if !empty(types) 183 if !empty(types)
187 call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim') 184 call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim')
188 endif 185 endif
189 for key in types 186 for type in types
190 if !has_key(lod, key) 187 call s:assoc(lod.ft, type, name)
191 let lod[key] = []
192 endif
193 call add(lod[key], name)
194 endfor 188 endfor
195 endif 189 endif
196 endfor 190 endfor
197 191
198 for [key, names] in items(lod) 192 for [cmd, names] in items(lod.cmd)
193 execute printf(
194 \ 'command! -nargs=* -range -bang %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, %s)',
195 \ cmd, string(cmd), string(names))
196 endfor
197
198 for [map, names] in items(lod.map)
199 for [mode, map_prefix, key_prefix] in
200 \ [['i', '<C-O>', ''], ['n', '', ''], ['v', '', 'gv'], ['o', '', '']]
201 execute printf(
202 \ '%snoremap <silent> %s %s:<C-U>call <SID>lod_map(%s, %s, "%s")<CR>',
203 \ mode, map, map_prefix, string(map), string(names), key_prefix)
204 endfor
205 endfor
206
207 for [ft, names] in items(lod.ft)
199 augroup PlugLOD 208 augroup PlugLOD
200 execute printf('autocmd FileType %s call <SID>lod_ft(%s, %s)', 209 execute printf('autocmd FileType %s call <SID>lod_ft(%s, %s)',
201 \ key, string(key), string(names)) 210 \ ft, string(ft), string(names))
202 augroup END 211 augroup END
203 endfor 212 endfor
204 213
205 call s:reorg_rtp() 214 call s:reorg_rtp()
206 filetype plugin indent on 215 filetype plugin indent on
334 function! s:remove_triggers(name) 343 function! s:remove_triggers(name)
335 if !has_key(s:triggers, a:name) 344 if !has_key(s:triggers, a:name)
336 return 345 return
337 endif 346 endif
338 for cmd in s:triggers[a:name].cmd 347 for cmd in s:triggers[a:name].cmd
339 execute 'delc' cmd 348 execute 'silent! delc' cmd
340 endfor 349 endfor
341 for map in s:triggers[a:name].map 350 for map in s:triggers[a:name].map
342 execute 'unmap' map 351 execute 'silent! unmap' map
343 execute 'iunmap' map 352 execute 'silent! iunmap' map
344 endfor 353 endfor
345 call remove(s:triggers, a:name) 354 call remove(s:triggers, a:name)
346 endfunction 355 endfunction
347 356
348 function! s:lod(names, types) 357 function! s:lod(names, types)
365 execute 'autocmd! PlugLOD FileType' a:pat 374 execute 'autocmd! PlugLOD FileType' a:pat
366 doautocmd filetypeplugin FileType 375 doautocmd filetypeplugin FileType
367 doautocmd filetypeindent FileType 376 doautocmd filetypeindent FileType
368 endfunction 377 endfunction
369 378
370 function! s:lod_cmd(cmd, bang, l1, l2, args, name) 379 function! s:lod_cmd(cmd, bang, l1, l2, args, names)
371 call s:lod([a:name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin']) 380 call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
372 execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args) 381 execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
373 endfunction 382 endfunction
374 383
375 function! s:lod_map(map, name, prefix) 384 function! s:lod_map(map, names, prefix)
376 call s:lod([a:name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin']) 385 call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
377 let extra = '' 386 let extra = ''
378 while 1 387 while 1
379 let c = getchar(0) 388 let c = getchar(0)
380 if c == 0 389 if c == 0
381 break 390 break