From a9262720c133a001368323c68671baa0cc58cb26 Mon Sep 17 00:00:00 2001 From: Kien N Date: Thu, 10 May 2012 08:04:05 +0700 Subject: [PATCH] Use @cd like :cd --- autoload/ctrlp.vim | 49 +++++++++++++++++++++++++++++++++++----------- doc/ctrlp.txt | 15 ++++++++++---- 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index e94f0d6..a6110f2 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -596,17 +596,22 @@ fu! s:PrtInsert(...) endf fu! s:PrtExpandDir() - let prt = s:prompt - if prt[0] == '' | retu | en + let str = s:prompt[0] + if str =~ '\v^\@(cd|lc[hd]?|chd)\s.+' && s:spi + let hasat = split(str, '\v^\@(cd|lc[hd]?|chd)\s*\zs') + let str = get(hasat, 1, '') + en + if str == '' | retu | en unl! s:hstgot let s:act_add = 1 - let [base, seed] = s:headntail(prt[0]) + let [base, seed] = s:headntail(str) let dirs = s:dircompl(base, seed) if len(dirs) == 1 - let prt[0] = dirs[0] + let str = dirs[0] elsei len(dirs) > 1 - let prt[0] .= s:findcommon(dirs, prt[0]) + let str .= s:findcommon(dirs, str) en + let s:prompt[0] = exists('hasat') ? hasat[0].str : str cal s:BuildPrompt(1) unl s:act_add endf @@ -858,17 +863,18 @@ fu! ctrlp#acceptfile(mode, line, ...) endf fu! s:SpecInputs(str) - let spi = !s:itemtype || s:getextvar('specinput') > 0 - if a:str == '..' && spi + if a:str == '..' && s:spi cal s:parentdir(s:dyncwd) cal ctrlp#setlines() cal s:PrtClear() retu 1 - elsei a:str == s:lash && spi + elsei a:str == s:lash && s:spi cal s:SetWD(2, 0) cal ctrlp#setlines() cal s:PrtClear() retu 1 + elsei a:str =~ '^@.\+' && s:spi + retu s:at(a:str) elsei a:str == '?' cal s:PrtExit() let hlpwin = &columns > 159 ? '| vert res 80' : '' @@ -883,8 +889,8 @@ fu! s:AcceptSelection(mode) if a:mode == 'e' | if s:SpecInputs(str) | retu | en | en " Get the selected line let line = !empty(s:lines) ? s:lines[line('.') - 1] : '' - if a:mode != 'e' && s:itemtype < 3 && line == '' - \ && str !~ '\v^(\.\.|/|\\|\?)$' + if a:mode != 'e' && !s:itemtype && line == '' + \ && str !~ '\v^(\.\.|/|\\|\?|\@.+)$' cal s:CreateNewFile(a:mode) | retu en if empty(line) | retu | en @@ -1455,6 +1461,25 @@ fu! s:iscmdwin() retu ermsg =~ '^E11:' endf " Arguments {{{2 +fu! s:at(str) + if a:str =~ '\v^\@(cd|lc[hd]?|chd).*' + let str = substitute(a:str, '\v^\@(cd|lc[hd]?|chd)\s*', '', '') + if str == '' | retu 1 | en + let str = str =~ '^%:.\+' ? fnamemodify(s:crfile, str[1:]) : str + let path = fnamemodify(expand(str, 1), ':p') + if isdirectory(path) + if path != s:dyncwd + cal ctrlp#setdir(path) + cal ctrlp#setlines() + en + cal ctrlp#recordhist() + cal s:PrtClear() + en + retu 1 + en + retu 0 +endf + fu! s:tail() if exists('s:optail') && !empty('s:optail') let tailpref = match(s:optail, '^\s*+') < 0 ? ' +' : ' ' @@ -1464,7 +1489,8 @@ fu! s:tail() endf fu! s:sanstail(str) - let [str, pat] = [substitute(a:str, '\\\\', '\', 'g'), '\([^:]\|\\:\)*$'] + let str = s:spi ? substitute(a:str, '^\(@.*$\|\\\\\ze@\)', '', 'g') : a:str + let [str, pat] = [substitute(str, '\\\\', '\', 'g'), '\([^:]\|\\:\)*$'] unl! s:optail if match(str, '\\\@= 0 let s:optail = matchstr(str, '\\\@ 0 endf fu! s:nosort() diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index b55b158..0eba914 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -150,7 +150,7 @@ When starting up, CtrlP sets its local working directory according to this variable: > let g:ctrlp_working_path_mode = 2 < - 1 - the parent directory of the current file. + 1 - the directory of the current file. 2 - the nearest ancestor that contains one of these directories or files: .git/ .hg/ .svn/ .bzr/ _darcs/ 0 - don't manage working directory. @@ -749,9 +749,14 @@ c) End the string with a colon ':' followed by a Vim command to execute that d) Submit two dots '..' to go backward the directory tree by 1 level. If the parent directory is large and uncached, this can be slow. -e) Similarly, submit '/' or '\' to find and go to the project's root. If the - project is large, using a VCS listing command to look for files might help - speeding up the intial scan (see |g:ctrlp_user_command| for more details). + You can also use '@cd path/' to change CtrlP's local working directory. + Use '@cd %:h' to change to the directory of the current file. + +e) Similarly, submit '/' or '\' to find and go to the project's root. + + If the project is large, using a VCS listing command to look for files + might help speeding up the intial scan (see |g:ctrlp_user_command| for more + details). Note: e) and d) only work in file, directory and mixed modes. @@ -1002,6 +1007,8 @@ Special thanks:~ =============================================================================== CHANGELOG *ctrlp-changelog* + + New input format: '@cd' (|ctrlp-input-formats| (d)) + Before 2012/04/30~ + New option: |g:ctrlp_mruf_default_order|