Commits

ZyX_I committed 39845f9

@%aurum/maputils: Added support for ctrlp

Comments (0)

Files changed (1)

autoload/aurum/maputils.vim

     endif
     return a:repo.functions.update(a:repo, rev, 0)
 endfunction
+"▶1 listplugs
+let s:F.listplugs={}
+let s:plug=0
+"▶2 commandt
+let s:F.listplugs.commandt={}
+function s:F.listplugs.commandt.init()
+    try
+        execute 'rubyfile' fnameescape(s:_r.os.path.join(s:_frawor.runtimepath,
+                    \'ruby', 'aurum-command-t-rubyinit.rb'))
+        return 1
+    catch
+        return 0
+    endtry
+endfunction
+function s:F.listplugs.commandt.call(files, cbargs)
+    let [b:aurum_callback_fun; b:aurum_addargs]=a:cbargs
+    ruby $comman_t_old = $command_t
+    ruby $command_t = $aurum_command_t
+    ruby $command_t.show_aurum_finder
+    " TODO The following does not work. Investigate why
+    autocmd BufWipeOut <buffer> ruby $command_t = $command_t_old
+endfunction
+"▶2 ctrlp
+function s:Accept(mode, str)
+    let d={}
+    let d.cbfun=b:aurum_callback_fun
+    let addargs=b:aurum_addargs
+    call ctrlp#exit()
+    return call(d.cbfun, [a:str]+addargs, {})
+endfunction
+let s:_functions+=['s:Accept']
+let s:ctrlp_ext_var={
+            \'init': '<SNR>'.s:_sid.'_Eval("s:ctrlp_files")',
+            \'accept': '<SNR>'.s:_sid.'_Accept',
+            \'lname': 'changeset files',
+            \'sname': 'changeset file',
+            \'type': 'path',
+        \}
+let s:ctrlp_id=0
+let s:ctrlp_files=[]
+let s:F.listplugs.ctrlp={}
+function s:F.listplugs.ctrlp.init()
+    runtime plugin/ctrlp.vim
+    try
+        call add(g:ctrlp_ext_vars, s:ctrlp_ext_var)
+        let s:ctrlp_id=g:ctrlp_builtins+len(g:ctrlp_ext_vars)
+        lockvar! s:ctlp_id
+        return 1
+    catch
+        return 0
+    endtry
+endfunction
+function s:F.listplugs.ctrlp.call(files, cbargs)
+    let s:ctrlp_files=a:files
+    call ctrlp#init(s:ctrlp_id)
+    let [b:aurum_callback_fun; b:aurum_addargs]=a:cbargs
+endfunction
 "▶1 promptuser
-let s:initialized_ruby=((has('ruby'))?(0):(-1))
 function s:r.promptuser(files, cbargs)
-    if !s:initialized_ruby
-        let s:initialized_ruby=1
-        try
-            execute 'rubyfile' fnameescape(s:_r.os.path.join(s:_frawor.runtimepath, 'ruby', 'aurum-command-t-rubyinit.rb'))
-        catch
-            let s:initialized_ruby=-1
-        endtry
-        lockvar s:initialized_ruby
+    if s:plug is 0
+        for plug in values(s:F.listplugs)
+            if plug.init()
+                unlet s:plug
+                let s:plug=plug
+                break
+            endif
+        endfor
+        if s:plug is 0
+            let s:plug=-1
+        endif
+        lockvar s:plug
     endif
-    if s:initialized_ruby==1
-        let [b:aurum_callback_fun; b:aurum_addargs]=a:cbargs
-        ruby $comman_t_old = $command_t
-        ruby $command_t = $aurum_command_t
-        ruby $command_t.show_aurum_finder
-        autocmd BufWipeOut <buffer> ruby $command_t = $command_t_old
-    else
+    if s:plug is -1
         let choice=inputlist(['Select file (0 to cancel):']+
                     \        map(copy(a:files), '(v:key+1).". ".v:val'))
         if choice
             return call(a:cbargs[0], [a:files[choice-1]]+a:cbargs[1:], {})
         endif
+    else
+        return s:plug.call(a:files, a:cbargs)
     endif
 endfunction
 "▶1 Post maputils resource
 call s:_f.postresource('maputils', s:r)
 "▶1
-call frawor#Lockvar(s:, 'initialized_ruby')
+call frawor#Lockvar(s:, 'plug,ctrlp_id,ctrlp_files')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲