Mercurial > ec-dotfiles
comparison vendor/vim-packs/ctrlp.vim/autoload/ctrlp/bookmarkdir.vim @ 707:4576f1471f53
[update-vendor, vim] add ctrlp
author | nanaya <me@nanaya.net> |
---|---|
date | Sun, 18 Dec 2022 22:27:56 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
706:4b30df382167 | 707:4576f1471f53 |
---|---|
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 cwds = exists('+ssl') ? [tr(a:cwd, '\', '/'), tr(a:cwd, '/', '\')] : [a:cwd] | |
53 let entries = filter(s:getbookmarks(), 'index(cwds, s:parts(v:val)[1]) < 0') | |
54 cal s:writecache(insert(entries, a:name.' '.a:cwd)) | |
55 endf | |
56 | |
57 fu! s:setentries() | |
58 let time = getftime(s:cachefile()) | |
59 if !( exists('s:bookmarks') && time == s:bookmarks[0] ) | |
60 let s:bookmarks = [time, s:getbookmarks()] | |
61 en | |
62 endf | |
63 | |
64 fu! s:parts(str) | |
65 let mlist = matchlist(a:str, '\v([^\t]+)\t(.*)$') | |
66 retu mlist != [] ? mlist[1:2] : ['', ''] | |
67 endf | |
68 | |
69 fu! s:process(entries, type) | |
70 retu map(a:entries, 's:modify(v:val, a:type)') | |
71 endf | |
72 | |
73 fu! s:modify(entry, type) | |
74 let [name, dir] = s:parts(a:entry) | |
75 let dir = fnamemodify(dir, a:type) | |
76 retu name.' '.( dir == '' ? '.' : dir ) | |
77 endf | |
78 | |
79 fu! s:msg(name, cwd) | |
80 redr | |
81 echoh Identifier | echon 'Bookmarked ' | echoh Constant | |
82 echon a:name.' ' | echoh Directory | echon a:cwd | |
83 echoh None | |
84 endf | |
85 | |
86 fu! s:syntax() | |
87 if !ctrlp#nosy() | |
88 cal ctrlp#hicheck('CtrlPBookmark', 'Identifier') | |
89 cal ctrlp#hicheck('CtrlPTabExtra', 'Comment') | |
90 sy match CtrlPBookmark '^> [^\t]\+' contains=CtrlPLinePre | |
91 sy match CtrlPTabExtra '\zs\t.*\ze$' | |
92 en | |
93 endf | |
94 " Public {{{1 | |
95 fu! ctrlp#bookmarkdir#init() | |
96 cal s:setentries() | |
97 cal s:syntax() | |
98 retu s:process(copy(s:bookmarks[1]), ':.') | |
99 endf | |
100 | |
101 fu! ctrlp#bookmarkdir#accept(mode, str) | |
102 let parts = s:parts(s:modify(a:str, ':p')) | |
103 cal call('s:savebookmark', parts) | |
104 if a:mode =~ 't\|v\|h' | |
105 cal ctrlp#exit() | |
106 en | |
107 cal ctrlp#setdir(parts[1], a:mode =~ 't\|h' ? 'chd!' : 'lc!') | |
108 if a:mode == 'e' | |
109 cal ctrlp#switchtype(0) | |
110 cal ctrlp#recordhist() | |
111 cal ctrlp#prtclear() | |
112 en | |
113 endf | |
114 | |
115 fu! ctrlp#bookmarkdir#add(bang, dir, ...) | |
116 let ctrlp_tilde_homedir = get(g:, 'ctrlp_tilde_homedir', 0) | |
117 let cwd = fnamemodify(getcwd(), ctrlp_tilde_homedir ? ':p:~' : ':p') | |
118 let dir = fnamemodify(a:dir, ctrlp_tilde_homedir ? ':p:~' : ':p') | |
119 if a:bang == '!' | |
120 let cwd = dir != '' ? dir : cwd | |
121 let name = a:0 && a:1 != '' ? a:1 : cwd | |
122 el | |
123 let str = 'Directory to bookmark: ' | |
124 let cwd = dir != '' ? dir : s:getinput(str, cwd, 'dir') | |
125 if cwd == '' | retu | en | |
126 let name = a:0 && a:1 != '' ? a:1 : s:getinput('Bookmark as: ', cwd) | |
127 if name == '' | retu | en | |
128 en | |
129 let name = tr(name, ' ', ' ') | |
130 cal s:savebookmark(name, cwd) | |
131 cal s:msg(name, cwd) | |
132 endf | |
133 | |
134 fu! ctrlp#bookmarkdir#remove(entries) | |
135 cal s:process(a:entries, ':p') | |
136 cal s:writecache(a:entries == [] ? [] : | |
137 \ filter(s:getbookmarks(), 'index(a:entries, v:val) < 0')) | |
138 cal s:setentries() | |
139 retu s:process(copy(s:bookmarks[1]), ':.') | |
140 endf | |
141 | |
142 fu! ctrlp#bookmarkdir#id() | |
143 retu s:id | |
144 endf | |
145 "}}} | |
146 | |
147 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 |