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