diff vim/autoload/plug.vim @ 216:d216f4d5508e

Setup latex compiler for dispatch
author zegervdv <zegervdv@me.com>
date Tue, 09 Dec 2014 19:51:07 +0100
parents 4e723feac624
children ed108055146c
line wrap: on
line diff
--- a/vim/autoload/plug.vim	Fri Dec 05 23:06:30 2014 +0100
+++ b/vim/autoload/plug.vim	Tue Dec 09 19:51:07 2014 +0100
@@ -83,6 +83,7 @@
 \   'funcref': type(function('call'))
 \ }
 let s:loaded = get(s:, 'loaded', {})
+let s:triggers = get(s:, 'triggers', {})
 
 function! plug#begin(...)
   if a:0 > 0
@@ -99,6 +100,7 @@
   let g:plug_home = home
   let g:plugs = {}
   let g:plugs_order = []
+  let s:triggers = {}
 
   call s:define_commands()
   return 1
@@ -156,6 +158,7 @@
     endif
 
     if has_key(plug, 'on')
+      let s:triggers[name] = { 'map': [], 'cmd': [] }
       for cmd in s:to_a(plug.on)
         if cmd =~ '^<Plug>.\+'
           if empty(mapcheck(cmd)) && empty(mapcheck(cmd, 'i'))
@@ -166,10 +169,14 @@
               \ mode, cmd, map_prefix, string(cmd), string(name), key_prefix)
             endfor
           endif
-        elseif !exists(':'.cmd)
-          execute printf(
-          \ 'command! -nargs=* -range -bang %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, %s)',
-          \ cmd, string(cmd), string(name))
+          call add(s:triggers[name].map, cmd)
+        elseif cmd =~ '^[A-Z]'
+          if exists(':'.cmd) != 2
+            execute printf(
+            \ 'command! -nargs=* -range -bang %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, %s)',
+            \ cmd, string(cmd), string(name))
+          endif
+          call add(s:triggers[name].cmd, cmd)
         endif
       endfor
     endif
@@ -324,8 +331,23 @@
   return 1
 endfunction
 
+function! s:remove_triggers(name)
+  if !has_key(s:triggers, a:name)
+    return
+  endif
+  for cmd in s:triggers[a:name].cmd
+    execute 'delc' cmd
+  endfor
+  for map in s:triggers[a:name].map
+    execute 'unmap' map
+    execute 'iunmap' map
+  endfor
+  call remove(s:triggers, a:name)
+endfunction
+
 function! s:lod(names, types)
   for name in a:names
+    call s:remove_triggers(name)
     let s:loaded[name] = 1
   endfor
   call s:reorg_rtp()
@@ -346,14 +368,11 @@
 endfunction
 
 function! s:lod_cmd(cmd, bang, l1, l2, args, name)
-  execute 'delc' a:cmd
   call s:lod([a:name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
   execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
 endfunction
 
 function! s:lod_map(map, name, prefix)
-  execute 'unmap' a:map
-  execute 'iunmap' a:map
   call s:lod([a:name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
   let extra = ''
   while 1
@@ -676,7 +695,7 @@
     try
       call mkdir(g:plug_home, 'p')
     catch
-      return s:err(printf('Invalid plug directory: %s.'
+      return s:err(printf('Invalid plug directory: %s. '.
               \ 'Try to call plug#begin with a valid directory', g:plug_home))
     endtry
   endif
@@ -1247,7 +1266,7 @@
     call append(line('$'), 'Already clean.')
   else
     call inputsave()
-    let yes = a:force || (input('Proceed? (Y/N) ') =~? '^y')
+    let yes = a:force || (input('Proceed? (y/N) ') =~? '^y')
     call inputrestore()
     if yes
       for dir in todo
@@ -1464,7 +1483,7 @@
 function! s:revert()
   let name = s:find_name(line('.'))
   if empty(name) || !has_key(g:plugs, name) ||
-    \ input(printf('Revert the update of %s? (Y/N) ', name)) !~? '^y'
+    \ input(printf('Revert the update of %s? (y/N) ', name)) !~? '^y'
     return
   endif