Mercurial > public > dotfiles
comparison vim/vimfiles/bundle/ctrlp.vim/autoload/ctrlp/bookmarkdir.vim @ 7:86e0ac713642
Re-added the latest ctrlp.vim plugin.
The ctrlp.vim commit was e61e7d5b801ade5fcefeab3aca75c1f37d54bdf1.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 29 Apr 2012 16:20:31 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
6:ff60fbc930de | 7:86e0ac713642 |
---|---|
1 " ============================================================================= | |
2 " File: autoload/ctrlp/bookmarkdir.vim | |
3 " Description: Bookmarked directories extension | |
4 " Author: Kien Nguyen <github.com/kien> | |
5 " ============================================================================= | |
6 | |
7 " Init {{{1 | |
8 if exists('g:loaded_ctrlp_bookmarkdir') && g:loaded_ctrlp_bookmarkdir | |
9 fini | |
10 en | |
11 let g:loaded_ctrlp_bookmarkdir = 1 | |
12 | |
13 cal add(g:ctrlp_ext_vars, { | |
14 \ 'init': 'ctrlp#bookmarkdir#init()', | |
15 \ 'accept': 'ctrlp#bookmarkdir#accept', | |
16 \ 'lname': 'bookmarked dirs', | |
17 \ 'sname': 'bkd', | |
18 \ 'type': 'tabs', | |
19 \ 'opmul': 1, | |
20 \ 'nolim': 1, | |
21 \ 'wipe': 'ctrlp#bookmarkdir#remove', | |
22 \ }) | |
23 | |
24 let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) | |
25 " Utilities {{{1 | |
26 fu! s:getinput(str, ...) | |
27 echoh Identifier | |
28 cal inputsave() | |
29 let input = call('input', a:0 ? [a:str] + a:000 : [a:str]) | |
30 cal inputrestore() | |
31 echoh None | |
32 retu input | |
33 endf | |
34 | |
35 fu! s:cachefile() | |
36 if !exists('s:cadir') || !exists('s:cafile') | |
37 let s:cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'bkd' | |
38 let s:cafile = s:cadir.ctrlp#utils#lash().'cache.txt' | |
39 en | |
40 retu s:cafile | |
41 endf | |
42 | |
43 fu! s:writecache(lines) | |
44 cal ctrlp#utils#writecache(a:lines, s:cadir, s:cafile) | |
45 endf | |
46 | |
47 fu! s:getbookmarks() | |
48 retu ctrlp#utils#readfile(s:cachefile()) | |
49 endf | |
50 | |
51 fu! s:savebookmark(name, cwd) | |
52 let entries = filter(s:getbookmarks(), 's:parts(v:val)[1] != a:cwd') | |
53 cal s:writecache(insert(entries, a:name.' '.a:cwd)) | |
54 endf | |
55 | |
56 fu! s:setentries() | |
57 let time = getftime(s:cachefile()) | |
58 if !( exists('s:bookmarks') && time == s:bookmarks[0] ) | |
59 let s:bookmarks = [time, s:getbookmarks()] | |
60 en | |
61 endf | |
62 | |
63 fu! s:parts(str) | |
64 let mlist = matchlist(a:str, '\v([^\t]+)\t(.*)$') | |
65 retu mlist != [] ? mlist[1:2] : ['', ''] | |
66 endf | |
67 | |
68 fu! s:process(entries, type) | |
69 retu map(a:entries, 's:modify(v:val, a:type)') | |
70 endf | |
71 | |
72 fu! s:modify(entry, type) | |
73 let [name, dir] = s:parts(a:entry) | |
74 let dir = fnamemodify(dir, a:type) | |
75 retu name.' '.( dir == '' ? '.' : dir ) | |
76 endf | |
77 | |
78 fu! s:msg(name, cwd) | |
79 redr | |
80 echoh Identifier | echon 'Bookmarked ' | echoh Constant | |
81 echon a:name.' ' | echoh Directory | echon a:cwd | |
82 echoh None | |
83 endf | |
84 | |
85 fu! s:syntax() | |
86 if !ctrlp#nosy() | |
87 cal ctrlp#hicheck('CtrlPBookmark', 'Identifier') | |
88 cal ctrlp#hicheck('CtrlPTabExtra', 'Comment') | |
89 sy match CtrlPBookmark '^> [^\t]\+' contains=CtrlPLinePre | |
90 sy match CtrlPTabExtra '\zs\t.*\ze$' | |
91 en | |
92 endf | |
93 " Public {{{1 | |
94 fu! ctrlp#bookmarkdir#init() | |
95 cal s:setentries() | |
96 cal s:syntax() | |
97 retu s:process(copy(s:bookmarks[1]), ':.') | |
98 endf | |
99 | |
100 fu! ctrlp#bookmarkdir#accept(mode, str) | |
101 let parts = s:parts(s:modify(a:str, ':p')) | |
102 cal call('s:savebookmark', parts) | |
103 if a:mode =~ 't\|v\|h' | |
104 cal ctrlp#exit() | |
105 en | |
106 cal ctrlp#setdir(parts[1], a:mode =~ 't\|h' ? 'chd!' : 'lc!') | |
107 if a:mode == 'e' | |
108 cal ctrlp#switchtype(0) | |
109 cal ctrlp#recordhist() | |
110 cal ctrlp#prtclear() | |
111 en | |
112 endf | |
113 | |
114 fu! ctrlp#bookmarkdir#add(dir) | |
115 let str = 'Directory to bookmark: ' | |
116 let cwd = a:dir != '' ? a:dir : s:getinput(str, getcwd(), 'dir') | |
117 if cwd == '' | retu | en | |
118 let cwd = fnamemodify(cwd, ':p') | |
119 let name = s:getinput('Bookmark as: ', cwd) | |
120 if name == '' | retu | en | |
121 let name = tr(name, ' ', ' ') | |
122 cal s:savebookmark(name, cwd) | |
123 cal s:msg(name, cwd) | |
124 endf | |
125 | |
126 fu! ctrlp#bookmarkdir#remove(entries) | |
127 cal s:process(a:entries, ':p') | |
128 cal s:writecache(a:entries == [] ? [] : | |
129 \ filter(s:getbookmarks(), 'index(a:entries, v:val) < 0')) | |
130 cal s:setentries() | |
131 retu s:process(copy(s:bookmarks[1]), ':.') | |
132 endf | |
133 | |
134 fu! ctrlp#bookmarkdir#id() | |
135 retu s:id | |
136 endf | |
137 "}}} | |
138 | |
139 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 |