Mercurial > dotfiles
diff vim/autoload/ctrlp/projectjump.vim @ 240:3a6b11d16a2a
Simpler registration for CtrlP extensions.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Fri, 12 Dec 2014 16:53:19 -0800 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vim/autoload/ctrlp/projectjump.vim Fri Dec 12 16:53:19 2014 -0800 @@ -0,0 +1,88 @@ +" ============================================================================= +" File: autoload/ctrlp/projectjump.vim +" Description: Project Jumper Extension +" Author: Ludovic Chabant <github.com/ludovicchabant> +" ============================================================================= + + +" Global Settings {{{ + +if !exists('g:ctrlp_projectjump_debug') + let g:ctrlp_projectjump_debug = 0 +endif + +if !exists('g:ctrlp_projectjump_trace') + let g:ctrlp_projectjump_trace = 0 +endif + +if exists('g:ctrlp_projectjump_loaded') && g:ctrlp_projectjump_loaded + \ && !g:ctrlp_projectjump_debug + finish +endif +let g:ctrlp_projectjump_loaded = 1 + +if !exists('g:ctrlp_projectjump_roots') + let g:ctrlp_projectjump_roots = [] +endif + +" }}} + +" Init {{{ + +if !exists('g:ctrlp_ext_vars') + let g:ctrlp_ext_vars = [] +endif +call add(g:ctrlp_ext_vars, { + \ 'init': 'ctrlp#projectjump#init()', + \ 'exit': 'ctrlp#projectjump#exit()', + \ 'accept': 'ctrlp#projectjump#accept', + \ 'lname': 'projectjump', + \ 'sname': 'prjmp', + \ 'type': 'project' + \ }) +let s:ext_id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) + +command! CtrlPProjectJump call ctrlp#init(s:ext_id) + +" }}} + +" Callbacks {{{ + +function! ctrlp#projectjump#init() abort + let l:project_roots = [] + for prj in g:ctrlp_projectjump_roots + let l:prj_type = get(prj, 'type', 'project') + if l:prj_type == 'project' + call add(l:project_roots, prj['path']) + elseif l:prj_type == 'parent' + let l:subdirs = glob(prj['path'], 0, 1) + for sd in l:subdirs + call add(l:project_roots, sd) + endfor + else + echoerr "CtrlPProjectJump: Unsupported project root type: ".l:prj_type + endif + endfor + return l:project_roots +endfunction + +function! ctrlp#projectjump#accept(mode, str) abort + call ctrlp#exit() + call ctrlp#init(0, {'dir': a:str}) +endfunction + +function! ctrlp#projectjump#exit() abort +endfunction + +" }}} + +" Internals {{{ + +function! s:trace(message) abort + if g:ctrlp_projectjump_trace + echom "ctrlp_projectjump: " . a:message + endif +endfunction + +" }}} +