From af22f30e39018f85b60691ea3b0f4df591cfc048 Mon Sep 17 00:00:00 2001 From: Kien N Date: Sat, 3 Dec 2011 10:54:18 +0700 Subject: [PATCH] Restore unnamed register * Close #44 * Add help tags for extension's commands. Issue #43. * Folding tweak. --- autoload/ctrlp.vim | 125 ++++++++++++++++-------------------- autoload/ctrlp/dir.vim | 10 ++- autoload/ctrlp/mrufiles.vim | 14 ++-- autoload/ctrlp/quickfix.vim | 7 +- autoload/ctrlp/tag.vim | 13 ++-- autoload/ctrlp/utils.vim | 9 ++- doc/ctrlp.txt | 15 +++-- 7 files changed, 87 insertions(+), 106 deletions(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index faa68d7..ab0a24f 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -5,7 +5,7 @@ " Version: 1.6.3 " ============================================================================= -" Static variables {{{ +" Static variables {{{1 fu! s:opts() let hst = exists('+hi') ? &hi : 20 let opts = { @@ -62,8 +62,7 @@ en " Limiters let [s:compare_lim, s:nocache_lim, s:mltipats_lim] = [3000, 4000, 2000] -"}}} -" * Open & Close {{{ +" * Open & Close {{{1 fu! s:Open() let [s:cwd, s:winres] = [getcwd(), winrestcmd()] let [s:crfile, s:crfpath] = [expand('%:p', 1), expand('%:p:h', 1)] @@ -102,8 +101,7 @@ fu! s:Close() cal ctrlp#recordhist() ec endf -"}}} -" * Clear caches {{{ +" * Clear caches {{{1 fu! ctrlp#clr(...) exe 'let g:ctrlp_new'.( exists('a:1') ? a:1 : 'cache' ).' = 1' endf @@ -113,8 +111,8 @@ fu! ctrlp#clra(...) \ confirm("Delete all cache files?", "&OK\n&Cancel") != 1 | retu | en let cache_dir = ctrlp#utils#cachedir() if isdirectory(cache_dir) - let cache_files = split(s:glbpath(cache_dir, '*.txt', 1), "\n") - cal filter(cache_files, '!isdirectory(v:val)') + let cache_files = split(s:glbpath(cache_dir, '**', 1), "\n") + cal filter(cache_files, '!isdirectory(v:val) && v:val !~ ''\ 0 && executable('cmigemo') let dict = s:glbpath(&rtp, printf("dict/%s/migemo-dict", &encoding), 1) @@ -275,8 +270,8 @@ fu! s:SplitPattern(str, ...) "{{{ endfo en retu newpats -endf "}}} -" * BuildPrompt() {{{ +endf +" * BuildPrompt() {{{1 fu! s:Render(lines, pat) let lines = a:lines " Setup the match window @@ -360,9 +355,8 @@ fu! s:BuildPrompt(upd, ...) exe 'echoh' hibase '| echon "_" | echoh None' en endf -"}}} -" ** Prt Actions {{{ -" Editing {{{ +" ** Prt Actions {{{1 +" Editing {{{2 fu! s:PrtClear() unl! s:hstgot let [s:prompt, s:matches] = [['', '', ''], 1] @@ -410,8 +404,7 @@ fu! s:PrtInsert(type) \ : a:type == '+' ? substitute(getreg('+'), '\n', '\\n', 'g') : s:prompt[0] cal s:BuildPrompt(1) endf -"}}} -" Movement {{{ +" Movement {{{2 fu! s:PrtCurLeft() if !empty(s:prompt[0]) let prt = s:prompt @@ -472,8 +465,7 @@ fu! s:PrtSelectJump(char, ...) if line('$') > winheight(0) | cal s:BuildPrompt(0, s:Focus()) | en en endf -"}}} -" Misc {{{ +" Misc {{{2 fu! s:PrtClearCache() if s:itemtype == 1 | retu | en if s:itemtype == 0 @@ -518,9 +510,8 @@ fu! s:PrtHistory(...) cal s:BuildPrompt(1) unl s:force endf -"}}} -"}}} -" * MapKeys() {{{ +"}}}1 +" * MapKeys() {{{1 fu! s:MapKeys(...) " Normal keys let pfunc = exists('a:1') && !a:1 ? 'PrtSelectJump' : 'PrtAdd' @@ -604,8 +595,7 @@ fu! s:MapSpecs(...) endfo | endfo en endf -"}}} -" * Toggling {{{ +" * Toggling {{{1 fu! s:Focus() retu !exists('s:focus') ? 1 : s:focus endf @@ -650,8 +640,7 @@ fu! s:PrtSwitcher() cal s:BuildPrompt(1, s:Focus()) unl s:force endf -"}}} -fu! s:SetWD(...) "{{{ +fu! s:SetWD(...) "{{{1 let pathmode = s:pathmode if exists('a:1') && len(a:1) == 1 && !type(a:1) let pathmode = a:1 @@ -673,8 +662,8 @@ fu! s:SetWD(...) "{{{ if exists('s:foundroot') | brea | en endfo unl! s:foundroot -endf "}}} -" * AcceptSelection() {{{ +endf +" * AcceptSelection() {{{1 fu! ctrlp#acceptfile(mode, matchstr) let [md, matchstr] = [a:mode, a:matchstr] " Get the full path @@ -711,8 +700,7 @@ fu! s:AcceptSelection(mode) \ : g:ctrlp_ext_vars[s:itemtype - ( g:ctrlp_builtins + 1 )][1] cal call(actfunc, [a:mode, matchstr]) endf -"}}} -fu! s:CreateNewFile() "{{{ +fu! s:CreateNewFile() "{{{1 let str = join(s:prompt, '') if empty(str) | retu | en let str = s:sanstail(str) @@ -732,8 +720,8 @@ fu! s:CreateNewFile() "{{{ \ : s:newfop == 3 ? 'vne' : ctrlp#normcmd('e') cal s:openfile(cmd, filpath) en -endf "}}} -" * OpenMulti() {{{ +endf +" * OpenMulti() {{{1 fu! s:MarkToOpen() if s:bufnr <= 0 || !s:opmul || s:itemtype > g:ctrlp_builtins | retu | en let matchstr = matchstr(getline('.'), '^> \zs.\+\ze\t*$') @@ -794,9 +782,8 @@ fu! s:OpenMulti() if nr > 1 && nr < ic | clo! | el | let ic += 1 | en endfo endf -"}}} -" ** Helper functions {{{ -" Sorting {{{ +" ** Helper functions {{{1 +" Sorting {{{2 fu! ctrlp#complen(s1, s2) " By length let [len1, len2] = [strlen(a:s1), strlen(a:s2)] @@ -856,8 +843,7 @@ fu! s:mixedsort(s1, s2) en retu 2 * cml + cln endf -"}}} -" Statusline {{{ +" Statusline {{{2 fu! ctrlp#statusline(...) if !exists('s:statypes') let s:statypes = [ @@ -896,8 +882,7 @@ fu! ctrlp#progress(len) let &l:stl = '%#Function# '.a:len.' %* %=%<%#LineNr# '.getcwd().' %*' redr endf -"}}} -" Paths {{{ +" Paths {{{2 fu! ctrlp#dirfilter(val) retu isdirectory(a:val) && match(a:val, '[\/]\.\{,2}$') < 0 ? 1 : 0 endf @@ -969,7 +954,7 @@ fu! s:findroot(curr, mark, depth, type) endf fu! s:glbpath(...) - retu call('globpath', v:version > 701 ? [a:1, a:2, a:3] : [a:1, a:2]) + retu call('globpath', v:version > 701 ? a:000 : a:000[:1]) endf fu! ctrlp#fnesc(path) @@ -984,8 +969,7 @@ fu! ctrlp#setdir(path, ...) cal ctrlp#msg("Can't change working dir. Directory not exists.") endt endf -"}}} -" Highlighting {{{ +" Highlighting {{{2 fu! s:syntax() sy match CtrlPNoEntries '^ == NO ENTRIES ==$' sy match CtrlPLineMarker '^>' @@ -1012,8 +996,7 @@ fu! s:dohighlight() retu type(s:mathi) == 3 && len(s:mathi) == 2 && s:mathi[0] \ && exists('*clearmatches') endf -"}}} -" Prompt history {{{ +" Prompt history {{{2 fu! s:gethistloc() let cache_dir = ctrlp#utils#cachedir().s:lash.'hist' retu [cache_dir, cache_dir.s:lash.'cache.txt'] @@ -1031,8 +1014,7 @@ fu! ctrlp#recordhist() cal extend(hst, [str], 1) if len(hst) > s:maxhst | cal remove(hst, s:maxhst, -1) | en endf -"}}} -" Signs {{{ +" Signs {{{2 fu! s:unmarksigns() if !s:dosigns() | retu | en for key in keys(s:marked) @@ -1055,8 +1037,7 @@ endf fu! s:dosigns() retu exists('s:marked') && s:bufnr > 0 && s:opmul && has('signs') endf -"}}} -" Dictionaries {{{ +" Dictionaries {{{2 fu! s:dictindex(dict, expr) for key in keys(a:dict) if a:dict[key] == a:expr | retu key | en @@ -1067,8 +1048,7 @@ endf fu! s:vacantdict(dict) retu filter(range(1, max(keys(a:dict))), '!has_key(a:dict, v:val)') endf -"}}} -" Buffers {{{ +" Buffers {{{2 fu! s:buftab(bufnum) for nr in range(1, tabpagenr('$')) let buflist = tabpagebuflist(nr) @@ -1121,7 +1101,10 @@ fu! s:setupblank() endf fu! s:leavepre() - if s:clrex | cal ctrlp#clra(1) | en + if s:clrex && ( !has('clientserver') || + \ ( has('clientserver') && len(split(serverlist(), "\n")) == 1 ) ) + cal ctrlp#clra(1) + en cal ctrlp#utils#writecache(s:hstry, s:gethistloc()[0], s:gethistloc()[1]) endf @@ -1131,8 +1114,7 @@ fu! s:checkbuf() exe s:bufnr.'bw!' en endf -"}}} -" Arguments {{{ +" Arguments {{{2 fu! s:tail() if exists('s:optail') && !empty('s:optail') let tailpref = match(s:optail, '^\s*+') < 0 ? ' +' : ' ' @@ -1151,8 +1133,7 @@ fu! s:sanstail(str) en retu str endf -"}}} -" Misc {{{ +" Misc {{{2 fu! s:specinputs() let str = join(s:prompt, '') let type = s:itemtype > 2 ? @@ -1177,10 +1158,13 @@ fu! s:specinputs() endf fu! s:lastvisual() - let [cview, oreg, oreg_type] = [winsaveview(), getreg('v'), getregtype('v')] + let cview = winsaveview() + let [ovreg, ovtype] = [getreg('v'), getregtype('v')] + let [oureg, outype] = [getreg('"'), getregtype('"')] sil! norm! gv"vy let selected = substitute(getreg('v'), '\n', '\\n', 'g') - cal setreg('v', oreg, oreg_type) + cal setreg('v', ovreg, ovtype) + cal setreg('"', oureg, outype) cal winrestview(cview) retu selected endf @@ -1274,8 +1258,7 @@ fu! s:lscommand() retu cmd[1] en endf -"}}} -" Extensions {{{ +" Extensions {{{2 fu! s:tagfiles() retu filter(map(tagfiles(), 'fnamemodify(v:val, ":p")'), 'filereadable(v:val)') endf @@ -1291,9 +1274,8 @@ endf fu! ctrlp#setlines(type) cal s:SetLines(a:type) endf -"}}} -"}}} -" * Initialization {{{ +"}}}1 +" * Initialization {{{1 fu! s:SetLines(type) let s:itemtype = a:type let types = [ @@ -1315,10 +1297,11 @@ fu! ctrlp#init(type, ...) cal s:MapKeys() cal s:SetLines(a:type) cal s:BuildPrompt(1) - if has('syntax') && exists('g:syntax_on') | cal s:syntax() | en + if has('syntax') && exists('g:syntax_on') + cal s:syntax() + en endf -"}}} -if has('autocmd') "{{{ +if has('autocmd') "{{{1 aug CtrlPAug au! au BufEnter ControlP cal s:checkbuf() @@ -1330,4 +1313,4 @@ if has('autocmd') "{{{ aug END en "}}} -" vim:fen:fdl=0:fdc=1:ts=2:sw=2:sts=2 +" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 diff --git a/autoload/ctrlp/dir.vim b/autoload/ctrlp/dir.vim index 420ddaf..0245a16 100644 --- a/autoload/ctrlp/dir.vim +++ b/autoload/ctrlp/dir.vim @@ -4,7 +4,7 @@ " Author: Kien Nguyen " ============================================================================= -" Init {{{ +" Init {{{1 if exists('g:loaded_ctrlp_dir') && g:loaded_ctrlp_dir fini en @@ -26,8 +26,7 @@ let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) \ ? add(g:ctrlp_ext_vars, s:dir_var) : [s:dir_var] let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) -"}}} -" Utilities {{{ +" Utilities {{{1 fu! s:globdirs(dirs, depth) let entries = split(globpath(a:dirs, s:glob), "\n") if !s:folsym @@ -47,8 +46,7 @@ endf fu! s:max(len, max) retu a:max && a:len > a:max ? 1 : 0 endf -"}}} -" Public {{{ +" Public {{{1 fu! ctrlp#dir#init(...) let s:cwd = getcwd() for each in range(len(s:ars)) @@ -94,4 +92,4 @@ fu! ctrlp#dir#id() endf "}}} -" vim:fen:fdl=0:ts=2:sw=2:sts=2 +" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 diff --git a/autoload/ctrlp/mrufiles.vim b/autoload/ctrlp/mrufiles.vim index 1f85d5e..fa3a67f 100644 --- a/autoload/ctrlp/mrufiles.vim +++ b/autoload/ctrlp/mrufiles.vim @@ -4,7 +4,7 @@ " Author: Kien Nguyen " ============================================================================= -" Static variables {{{ +" Static variables {{{1 fu! ctrlp#mrufiles#opts() let opts = { \ 'g:ctrlp_mruf_max': ['s:max', 250], @@ -17,8 +17,7 @@ fu! ctrlp#mrufiles#opts() endfo endf cal ctrlp#mrufiles#opts() -"}}} -fu! ctrlp#mrufiles#list(bufnr, ...) "{{{ +fu! ctrlp#mrufiles#list(bufnr, ...) "{{{1 if s:locked | retu | en " Get the list let cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru' @@ -53,8 +52,8 @@ fu! s:rmdeleted(mrufs, cadir, cafile) "{{{ cal filter(a:mrufs, '!empty(ctrlp#utils#glob(v:val, 1))') cal ctrlp#utils#writecache(a:mrufs, a:cadir, a:cafile) retu a:mrufs -endf "}}} -fu! ctrlp#mrufiles#init() "{{{ +endf +fu! ctrlp#mrufiles#init() "{{{1 let s:locked = 0 aug CtrlPMRUF au! @@ -63,6 +62,7 @@ fu! ctrlp#mrufiles#init() "{{{ au QuickFixCmdPre *vimgrep* let s:locked = 1 au QuickFixCmdPost *vimgrep* let s:locked = 0 aug END -endf "}}} +endf +"}}} -" vim:fen:fdl=0:fdc=1:ts=2:sw=2:sts=2 +" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 diff --git a/autoload/ctrlp/quickfix.vim b/autoload/ctrlp/quickfix.vim index ae3006f..0013481 100644 --- a/autoload/ctrlp/quickfix.vim +++ b/autoload/ctrlp/quickfix.vim @@ -4,7 +4,7 @@ " Author: Kien Nguyen " ============================================================================= -" Init {{{ +" Init {{{1 if exists('g:loaded_ctrlp_quickfix') && g:loaded_ctrlp_quickfix fini en @@ -22,8 +22,7 @@ fu! s:lineout(dict) retu printf('%s|%d:%d| %s', bufname(a:dict['bufnr']), a:dict['lnum'], \ a:dict['col'], matchstr(a:dict['text'], '\s*\zs.*\S')) endf -"}}} -" Public {{{ +" Public {{{1 fu! ctrlp#quickfix#init() let g:ctrlp_nolimit = 1 sy match CtrlPqfLineCol '|\zs\d\+:\d\+\ze|' @@ -53,4 +52,4 @@ fu! ctrlp#quickfix#id() endf "}}} -" vim:fen:fdl=0:ts=2:sw=2:sts=2 +" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 diff --git a/autoload/ctrlp/tag.vim b/autoload/ctrlp/tag.vim index 67aac06..bf68a2f 100644 --- a/autoload/ctrlp/tag.vim +++ b/autoload/ctrlp/tag.vim @@ -4,7 +4,7 @@ " Author: Kien Nguyen " ============================================================================= -" Init {{{ +" Init {{{1 if exists('g:loaded_ctrlp_tag') && g:loaded_ctrlp_tag fini en @@ -17,8 +17,7 @@ let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) \ ? add(g:ctrlp_ext_vars, s:tag_var) : [s:tag_var] let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) -"}}} -" Utilities {{{ +" Utilities {{{1 fu! s:nodup(items) let dict = {} for each in a:items @@ -31,7 +30,7 @@ fu! s:findcount(str) let [tg, fname] = split(a:str, '\t\+\ze[^\t]\+$') let [&l:tags, fname] = [s:ltags, expand(fname, 1)] let tgs = taglist('^'.tg.'$') - if empty(tgs) | retu [0, 0] | en + if empty(tgs) | retu [1, 1] | en let [fnd, ct, pos] = [0, 0, 0] for each in tgs let ct += 1 @@ -45,8 +44,7 @@ fu! s:findcount(str) endfo retu [fnd, pos] endf -"}}} -" Public {{{ +" Public {{{1 fu! ctrlp#tag#init(tagfiles) if empty(a:tagfiles) | retu [] | en let tagfiles = sort(s:nodup(a:tagfiles)) @@ -78,7 +76,6 @@ fu! ctrlp#tag#accept(mode, str) if fnd[0] == 1 exe cmd let &l:tags = s:ltags - let tg = tg =~ '^!' ? substitute(tg, '!\(.*\)$', '/^!\1$', '') : tg exe fnd[1].'ta' tg el exe cmd.' '.tg @@ -93,4 +90,4 @@ fu! ctrlp#tag#id() endf "}}} -" vim:fen:fdl=0:ts=2:sw=2:sts=2 +" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 diff --git a/autoload/ctrlp/utils.vim b/autoload/ctrlp/utils.vim index c6ecd94..2f1517a 100644 --- a/autoload/ctrlp/utils.vim +++ b/autoload/ctrlp/utils.vim @@ -4,7 +4,7 @@ " Author: Kien Nguyen " ============================================================================= -" Static variables {{{ +" Static variables {{{1 fu! ctrlp#utils#lash() retu &ssl || !exists('+ssl') ? '/' : '\' endf @@ -20,8 +20,7 @@ fu! ctrlp#utils#opts() en endf cal ctrlp#utils#opts() -"}}} -" Files and Directories {{{ +" Files and Directories {{{1 fu! ctrlp#utils#cachedir() retu s:cache_dir endf @@ -62,8 +61,8 @@ fu! ctrlp#utils#writecache(lines, ...) endf fu! ctrlp#utils#glob(...) - retu call('glob', v:version > 701 ? [a:1, a:2] : [a:1]) + retu call('glob', v:version > 701 ? a:000 : a:1) endf "}}} -" vim:fen:fdl=0:fdc=1:ts=2:sw=2:sts=2 +" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index 39cfa1b..de4e616 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -496,16 +496,18 @@ f) Type the name of a non-existent file and press to create it. g) Submit ? to open this help file. =============================================================================== -6. Extensions *ctrlp-extensions* +6. Extensions *g:ctrlp-extensions* Extensions are optional. To enable an extension, add its name to the variable g:ctrlp_extensions: > - let g:ctrlp_extensions = ['tag', 'quickfix', 'dir'] + let g:ctrlp_extensions = ['tag', 'quickfix', 'buffertag', 'dir'] < +The order of the items will be the order they appear on the statusline and when +using , . Available extensions:~ - *ctrlp-tag-mode* + *:CtrlPTag* * Tag mode:~ - Name: 'tag' - Command: ':CtrlPTag' @@ -513,13 +515,13 @@ Available extensions:~ definition. Use the Vim’s option |'tags'| to specify the names and the locations of the tags file(s). Example: `set tags+=tags/help,doc/tags` - *ctrlp-quickfix-mode* + *:CtrlPQuickfix* * Quickfix mode:~ - Name: 'quickfix' - Command: ':CtrlPQuickfix' - Search for an entry in the current quickfix errors and jump to it. - *ctrlp-dir-mode* + *:CtrlPDir* * Directory mode:~ - Name: 'dir' - Command: ':CtrlPDir' @@ -581,7 +583,10 @@ Special thanks:~ =============================================================================== CHANGELOG *ctrlp-changelog* +Before 2011/11/30~ + + New features: Tag, Quickfix and Directory extensions. + + New commands: |:CtrlPTag|, |:CtrlPQuickfix|, |:CtrlPDir|. + New options: |g:ctrlp_use_migemo|, |g:ctrlp_lazy_update|, |g:ctrlp_follow_symlinks|