Permalink
Browse files

updated ctrlp

  • Loading branch information...
1 parent 40b2c12 commit af13e75235f151a073300b157d8b6416d8a851d1 @SKoschnicke committed Dec 20, 2012
View
2,009 vim/autoload/ctrlp.vim 100755 → 100644

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,140 @@
+" =============================================================================
+" File: autoload/ctrlp/bookmarkdir.vim
+" Description: Bookmarked directories extension
+" Author: Kien Nguyen <github.com/kien>
+" =============================================================================
+
+" Init {{{1
+if exists('g:loaded_ctrlp_bookmarkdir') && g:loaded_ctrlp_bookmarkdir
+ fini
+en
+let g:loaded_ctrlp_bookmarkdir = 1
+
+cal add(g:ctrlp_ext_vars, {
+ \ 'init': 'ctrlp#bookmarkdir#init()',
+ \ 'accept': 'ctrlp#bookmarkdir#accept',
+ \ 'lname': 'bookmarked dirs',
+ \ 'sname': 'bkd',
+ \ 'type': 'tabs',
+ \ 'opmul': 1,
+ \ 'nolim': 1,
+ \ 'wipe': 'ctrlp#bookmarkdir#remove',
+ \ })
+
+let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
+" Utilities {{{1
+fu! s:getinput(str, ...)
+ echoh Identifier
+ cal inputsave()
+ let input = call('input', a:0 ? [a:str] + a:000 : [a:str])
+ cal inputrestore()
+ echoh None
+ retu input
+endf
+
+fu! s:cachefile()
+ if !exists('s:cadir') || !exists('s:cafile')
+ let s:cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'bkd'
+ let s:cafile = s:cadir.ctrlp#utils#lash().'cache.txt'
+ en
+ retu s:cafile
+endf
+
+fu! s:writecache(lines)
+ cal ctrlp#utils#writecache(a:lines, s:cadir, s:cafile)
+endf
+
+fu! s:getbookmarks()
+ retu ctrlp#utils#readfile(s:cachefile())
+endf
+
+fu! s:savebookmark(name, cwd)
+ let cwds = exists('+ssl') ? [tr(a:cwd, '\', '/'), tr(a:cwd, '/', '\')] : [a:cwd]
+ let entries = filter(s:getbookmarks(), 'index(cwds, s:parts(v:val)[1]) < 0')
+ cal s:writecache(insert(entries, a:name.' '.a:cwd))
+endf
+
+fu! s:setentries()
+ let time = getftime(s:cachefile())
+ if !( exists('s:bookmarks') && time == s:bookmarks[0] )
+ let s:bookmarks = [time, s:getbookmarks()]
+ en
+endf
+
+fu! s:parts(str)
+ let mlist = matchlist(a:str, '\v([^\t]+)\t(.*)$')
+ retu mlist != [] ? mlist[1:2] : ['', '']
+endf
+
+fu! s:process(entries, type)
+ retu map(a:entries, 's:modify(v:val, a:type)')
+endf
+
+fu! s:modify(entry, type)
+ let [name, dir] = s:parts(a:entry)
+ let dir = fnamemodify(dir, a:type)
+ retu name.' '.( dir == '' ? '.' : dir )
+endf
+
+fu! s:msg(name, cwd)
+ redr
+ echoh Identifier | echon 'Bookmarked ' | echoh Constant
+ echon a:name.' ' | echoh Directory | echon a:cwd
+ echoh None
+endf
+
+fu! s:syntax()
+ if !ctrlp#nosy()
+ cal ctrlp#hicheck('CtrlPBookmark', 'Identifier')
+ cal ctrlp#hicheck('CtrlPTabExtra', 'Comment')
+ sy match CtrlPBookmark '^> [^\t]\+' contains=CtrlPLinePre
+ sy match CtrlPTabExtra '\zs\t.*\ze$'
+ en
+endf
+" Public {{{1
+fu! ctrlp#bookmarkdir#init()
+ cal s:setentries()
+ cal s:syntax()
+ retu s:process(copy(s:bookmarks[1]), ':.')
+endf
+
+fu! ctrlp#bookmarkdir#accept(mode, str)
+ let parts = s:parts(s:modify(a:str, ':p'))
+ cal call('s:savebookmark', parts)
+ if a:mode =~ 't\|v\|h'
+ cal ctrlp#exit()
+ en
+ cal ctrlp#setdir(parts[1], a:mode =~ 't\|h' ? 'chd!' : 'lc!')
+ if a:mode == 'e'
+ cal ctrlp#switchtype(0)
+ cal ctrlp#recordhist()
+ cal ctrlp#prtclear()
+ en
+endf
+
+fu! ctrlp#bookmarkdir#add(dir)
+ let str = 'Directory to bookmark: '
+ let cwd = a:dir != '' ? a:dir : s:getinput(str, getcwd(), 'dir')
+ if cwd == '' | retu | en
+ let cwd = fnamemodify(cwd, ':p')
+ let name = s:getinput('Bookmark as: ', cwd)
+ if name == '' | retu | en
+ let name = tr(name, ' ', ' ')
+ cal s:savebookmark(name, cwd)
+ cal s:msg(name, cwd)
+endf
+
+fu! ctrlp#bookmarkdir#remove(entries)
+ cal s:process(a:entries, ':p')
+ cal s:writecache(a:entries == [] ? [] :
+ \ filter(s:getbookmarks(), 'index(a:entries, v:val) < 0'))
+ cal s:setentries()
+ retu s:process(copy(s:bookmarks[1]), ':.')
+endf
+
+fu! ctrlp#bookmarkdir#id()
+ retu s:id
+endf
+"}}}
+
+" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2
View
152 vim/autoload/ctrlp/buffertag.vim 100755 → 100644
@@ -13,55 +13,35 @@ if exists('g:loaded_ctrlp_buftag') && g:loaded_ctrlp_buftag
en
let g:loaded_ctrlp_buftag = 1
-let s:buftag_var = {
+cal add(g:ctrlp_ext_vars, {
\ 'init': 'ctrlp#buffertag#init(s:crfile)',
\ 'accept': 'ctrlp#buffertag#accept',
\ 'lname': 'buffer tags',
\ 'sname': 'bft',
\ 'exit': 'ctrlp#buffertag#exit()',
\ 'type': 'tabs',
- \ }
-
-let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
- \ ? add(g:ctrlp_ext_vars, s:buftag_var) : [s:buftag_var]
+ \ 'opts': 'ctrlp#buffertag#opts()',
+ \ })
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
-fu! s:opts()
- let opts = {
- \ 'g:ctrlp_buftag_systemenc': ['s:enc', &enc],
- \ 'g:ctrlp_buftag_ctags_bin': ['s:bin', ''],
- \ 'g:ctrlp_buftag_types': ['s:usr_types', ''],
- \ }
- for [ke, va] in items(opts)
- exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1])
- endfo
-endf
-cal s:opts()
-
-fu! s:bins()
- let bins = [
- \ 'ctags-exuberant',
- \ 'exuberant-ctags',
- \ 'exctags',
- \ '/usr/local/bin/ctags',
- \ '/opt/local/bin/ctags',
- \ 'ctags',
- \ 'ctags.exe',
- \ 'tags',
- \ ]
- if empty(s:bin)
- for bin in bins | if executable(bin)
- let s:bin = bin
- brea
- en | endfo
- el
- let s:bin = expand(s:bin, 1)
- en
-endf
-cal s:bins()
+let [s:pref, s:opts] = ['g:ctrlp_buftag_', {
+ \ 'systemenc': ['s:enc', &enc],
+ \ 'ctags_bin': ['s:bin', ''],
+ \ 'types': ['s:usr_types', {}],
+ \ }]
+
+let s:bins = [
+ \ 'ctags-exuberant',
+ \ 'exuberant-ctags',
+ \ 'exctags',
+ \ '/usr/local/bin/ctags',
+ \ '/opt/local/bin/ctags',
+ \ 'ctags',
+ \ 'ctags.exe',
+ \ 'tags',
+ \ ]
-" s:types {{{2
let s:types = {
\ 'asm' : '%sasm%sasm%sdlmt',
\ 'aspperl': '%sasp%sasp%sfsv',
@@ -108,9 +88,22 @@ if executable('jsctags')
cal extend(s:types, { 'javascript': { 'args': '-f -', 'bin': 'jsctags' } })
en
-if type(s:usr_types) == 4
+fu! ctrlp#buffertag#opts()
+ for [ke, va] in items(s:opts)
+ let {va[0]} = exists(s:pref.ke) ? {s:pref.ke} : va[1]
+ endfo
+ " Ctags bin
+ if empty(s:bin)
+ for bin in s:bins | if executable(bin)
+ let s:bin = bin
+ brea
+ en | endfo
+ el
+ let s:bin = expand(s:bin, 1)
+ en
+ " Types
cal extend(s:types, s:usr_types)
-en
+endf
" Utilities {{{1
fu! s:validfile(fname, ftype)
if ( !empty(a:fname) || !empty(a:ftype) ) && filereadable(a:fname)
@@ -156,18 +149,18 @@ fu! s:esctagscmd(bin, args, ...)
if exists('+ssl')
let [ssl, &ssl] = [&ssl, 0]
en
- let fname = a:0 == 1 ? shellescape(a:1) : ''
+ let fname = a:0 ? shellescape(a:1) : ''
let cmd = shellescape(a:bin).' '.a:args.' '.fname
+ if &sh =~ 'cmd\.exe'
+ let cmd = substitute(cmd, '[&()@^<>|]', '^\0', 'g')
+ en
if exists('+ssl')
let &ssl = ssl
en
if has('iconv')
let last = s:enc != &enc ? s:enc : !empty($LANG) ? $LANG : &enc
let cmd = iconv(cmd, &enc, last)
en
- if empty(cmd)
- cal ctrlp#msg("Encoding conversion failed!")
- en
retu cmd
endf
@@ -180,43 +173,76 @@ fu! s:process(fname, ftype)
el
let data = s:exectagsonfile(a:fname, a:ftype)
let [raw, lines] = [split(data, '\n\+'), []]
- for line in raw | if len(split(line, ';"')) == 2
- let parsed_line = s:parseline(line)
- if parsed_line != ''
- cal add(lines, parsed_line)
+ for line in raw
+ if line !~# '^!_TAG_' && len(split(line, ';"')) == 2
+ let parsed_line = s:parseline(line)
+ if parsed_line != ''
+ cal add(lines, parsed_line)
+ en
en
- en | endfo
+ endfo
let cache = { a:fname : { 'time': ftime, 'lines': lines } }
cal extend(g:ctrlp_buftags, cache)
en
retu lines
endf
fu! s:parseline(line)
- let eval = '\v^([^\t]+)\t(.+)\t\/\^(.+)\$\/\;\"\t(.+)\tline(no)?\:(\d+)'
- let vals = matchlist(a:line, eval)
- if empty(vals) | retu '' | en
- let [bufnr, bufname] = [bufnr(vals[2]), fnamemodify(vals[2], ':p:t')]
+ let vals = matchlist(a:line,
+ \ '\v^([^\t]+)\t(.+)\t[?/]\^?(.{-1,})\$?[?/]\;\"\t(.+)\tline(no)?\:(\d+)')
+ if vals == [] | retu '' | en
+ let [bufnr, bufname] = [bufnr('^'.vals[2].'$'), fnamemodify(vals[2], ':p:t')]
retu vals[1].' '.vals[4].'|'.bufnr.':'.bufname.'|'.vals[6].'| '.vals[3]
endf
+
+fu! s:syntax()
+ if !ctrlp#nosy()
+ cal ctrlp#hicheck('CtrlPTagKind', 'Title')
+ cal ctrlp#hicheck('CtrlPBufName', 'Directory')
+ cal ctrlp#hicheck('CtrlPTabExtra', 'Comment')
+ sy match CtrlPTagKind '\zs[^\t|]\+\ze|\d\+:[^|]\+|\d\+|'
+ sy match CtrlPBufName '|\d\+:\zs[^|]\+\ze|\d\+|'
+ sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName,CtrlPTagKind
+ en
+endf
+
+fu! s:chknearby(pat)
+ if match(getline('.'), a:pat) < 0
+ let [int, forw, maxl] = [1, 1, line('$')]
+ wh !search(a:pat, 'W'.( forw ? '' : 'b' ))
+ if !forw
+ if int > maxl | brea | en
+ let int += int
+ en
+ let forw = !forw
+ endw
+ en
+endf
" Public {{{1
fu! ctrlp#buffertag#init(fname)
- let fname = exists('s:bufname') ? s:bufname : a:fname
- let bufs = exists('s:btmode') && s:btmode ? ctrlp#allbufs() : [fname]
+ let bufs = exists('s:btmode') && s:btmode
+ \ ? filter(ctrlp#buffers(), 'filereadable(v:val)')
+ \ : [exists('s:bufname') ? s:bufname : a:fname]
let lines = []
for each in bufs
- let tftype = get(split(getbufvar(each, '&ft'), '\.'), 0, '')
- cal extend(lines, s:process(each, tftype))
+ let bname = fnamemodify(each, ':p')
+ let tftype = get(split(getbufvar('^'.bname.'$', '&ft'), '\.'), 0, '')
+ cal extend(lines, s:process(bname, tftype))
endfo
- sy match CtrlPTabExtra '\zs\t.*\ze$'
- hi link CtrlPTabExtra Comment
+ cal s:syntax()
retu lines
endf
fu! ctrlp#buffertag#accept(mode, str)
- let vals = matchlist(a:str, '\v^[^\t]+\t+[^\t|]+\|(\d+)\:[^\t|]+\|(\d+)\|')
- let [bufnm, linenr] = [fnamemodify(bufname(str2nr(vals[1])), ':p'), vals[2]]
- cal ctrlp#acceptfile(a:mode, bufnm, linenr)
+ let vals = matchlist(a:str,
+ \ '\v^[^\t]+\t+[^\t|]+\|(\d+)\:[^\t|]+\|(\d+)\|\s(.+)$')
+ let bufnr = str2nr(get(vals, 1))
+ if bufnr
+ cal ctrlp#acceptfile(a:mode, bufname(bufnr))
+ exe 'norm!' str2nr(get(vals, 2, line('.'))).'G'
+ cal s:chknearby('\V\C'.get(vals, 3, ''))
+ sil! norm! zvzz
+ en
endf
fu! ctrlp#buffertag#cmd(mode, ...)
Oops, something went wrong.

0 comments on commit af13e75

Please sign in to comment.