comparison 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
comparison
equal deleted inserted replaced
239:ec74791ee042 240:3a6b11d16a2a
1 " =============================================================================
2 " File: autoload/ctrlp/projectjump.vim
3 " Description: Project Jumper Extension
4 " Author: Ludovic Chabant <github.com/ludovicchabant>
5 " =============================================================================
6
7
8 " Global Settings {{{
9
10 if !exists('g:ctrlp_projectjump_debug')
11 let g:ctrlp_projectjump_debug = 0
12 endif
13
14 if !exists('g:ctrlp_projectjump_trace')
15 let g:ctrlp_projectjump_trace = 0
16 endif
17
18 if exists('g:ctrlp_projectjump_loaded') && g:ctrlp_projectjump_loaded
19 \ && !g:ctrlp_projectjump_debug
20 finish
21 endif
22 let g:ctrlp_projectjump_loaded = 1
23
24 if !exists('g:ctrlp_projectjump_roots')
25 let g:ctrlp_projectjump_roots = []
26 endif
27
28 " }}}
29
30 " Init {{{
31
32 if !exists('g:ctrlp_ext_vars')
33 let g:ctrlp_ext_vars = []
34 endif
35 call add(g:ctrlp_ext_vars, {
36 \ 'init': 'ctrlp#projectjump#init()',
37 \ 'exit': 'ctrlp#projectjump#exit()',
38 \ 'accept': 'ctrlp#projectjump#accept',
39 \ 'lname': 'projectjump',
40 \ 'sname': 'prjmp',
41 \ 'type': 'project'
42 \ })
43 let s:ext_id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
44
45 command! CtrlPProjectJump call ctrlp#init(s:ext_id)
46
47 " }}}
48
49 " Callbacks {{{
50
51 function! ctrlp#projectjump#init() abort
52 let l:project_roots = []
53 for prj in g:ctrlp_projectjump_roots
54 let l:prj_type = get(prj, 'type', 'project')
55 if l:prj_type == 'project'
56 call add(l:project_roots, prj['path'])
57 elseif l:prj_type == 'parent'
58 let l:subdirs = glob(prj['path'], 0, 1)
59 for sd in l:subdirs
60 call add(l:project_roots, sd)
61 endfor
62 else
63 echoerr "CtrlPProjectJump: Unsupported project root type: ".l:prj_type
64 endif
65 endfor
66 return l:project_roots
67 endfunction
68
69 function! ctrlp#projectjump#accept(mode, str) abort
70 call ctrlp#exit()
71 call ctrlp#init(0, {'dir': a:str})
72 endfunction
73
74 function! ctrlp#projectjump#exit() abort
75 endfunction
76
77 " }}}
78
79 " Internals {{{
80
81 function! s:trace(message) abort
82 if g:ctrlp_projectjump_trace
83 echom "ctrlp_projectjump: " . a:message
84 endif
85 endfunction
86
87 " }}}
88