Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Improve g:ctrlp_working_path_mode #540

Open
wants to merge 1 commit into from

2 participants

@trisk

Support ordered processing of multiple g:ctrlp_working_path_mode specifications
Clarify g:ctrlp_working_path_mode semantics in readme.md

@trisk trisk Improve g:ctrlp_working_path_mode
Support ordered processing of multiple g:ctrlp_working_path_mode specifications
Clarify g:ctrlp_working_path_mode semantics in readme.md
27c9e50
@d11wtq d11wtq referenced this pull request in ctrlpvim/ctrlp.vim
Closed

Improve g:ctrlp_working_path_mode #8

@d11wtq

Moved to: ctrlpvim#8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 6, 2014
  1. @trisk

    Improve g:ctrlp_working_path_mode

    trisk authored
    Support ordered processing of multiple g:ctrlp_working_path_mode specifications
    Clarify g:ctrlp_working_path_mode semantics in readme.md
This page is out of date. Refresh to see the latest.
Showing with 37 additions and 22 deletions.
  1. +29 −15 autoload/ctrlp.vim
  2. +8 −7 readme.md
View
44 autoload/ctrlp.vim
@@ -959,23 +959,20 @@ fu! s:SetWD(args)
if has_key(a:args, 'dir') && a:args['dir'] != ''
cal ctrlp#setdir(a:args['dir']) | retu
en
- let pmode = has_key(a:args, 'mode') ? a:args['mode'] : s:pathmode
+ let pmodes = has_key(a:args, 'mode') ? a:args['mode'] : s:pathmode
let [s:crfilerel, s:dyncwd] = [fnamemodify(s:crfile, ':.'), getcwd()]
if s:crfile =~ '^.\+://' | retu | en
- if pmode =~ 'c' || ( pmode =~ 'a' && stridx(s:crfpath, s:cwd) < 0 )
- \ || ( !type(pmode) && pmode )
- if exists('+acd') | let [s:glb_acd, &acd] = [&acd, 0] | en
- cal ctrlp#setdir(s:crfpath)
- en
- if pmode =~ 'r' || pmode == 2
- let markers = ['.git', '.hg', '.svn', '.bzr', '_darcs']
- let spath = pmode =~ 'd' ? s:dyncwd : pmode =~ 'w' ? s:cwd : s:crfpath
- if type(s:rmarkers) == 3 && !empty(s:rmarkers)
- if s:findroot(spath, s:rmarkers, 0, 0) != [] | retu | en
- cal filter(markers, 'index(s:rmarkers, v:val) < 0')
- en
- cal s:findroot(spath, markers, 0, 0)
- en
+ if (!type(pmodes))
+ let pmodes =
+ \ pmodes == 0 ? '' :
+ \ pmodes == 1 ? 'a' :
+ \ pmodes == 2 ? 'r' :
+ \ 'c'
+ en
+ let spath = pmodes =~ 'd' ? s:dyncwd : pmodes =~ 'w' ? s:cwd : s:crfpath
+ for pmode in split(pmodes, '\zs')
+ if ctrlp#setpathmode(pmode, spath) | retu | en
+ endfo
endf
" * AcceptSelection() {{{1
fu! ctrlp#acceptfile(...)
@@ -1586,6 +1583,23 @@ fu! s:findroot(curr, mark, depth, type)
retu []
endf
+fu! ctrlp#setpathmode(pmode, ...)
+ if a:pmode == 'c' || ( a:pmode == 'a' && stridx(s:crfpath, s:cwd) < 0 )
+ if exists('+acd') | let [s:glb_acd, &acd] = [&acd, 0] | en
+ cal ctrlp#setdir(s:crfpath)
+ retu 1
+ elsei a:pmode == 'r'
+ let spath = a:0 ? a:1 : s:crfpath
+ let markers = ['.git', '.hg', '.svn', '.bzr', '_darcs']
+ if type(s:rmarkers) == 3 && !empty(s:rmarkers)
+ if s:findroot(spath, s:rmarkers, 0, 0) != [] | retu 1 | en
+ cal filter(markers, 'index(s:rmarkers, v:val) < 0')
+ en
+ if s:findroot(spath, markers, 0, 0) != [] | retu 1 | en
+ en
+ retu 0
+endf
+
fu! ctrlp#setdir(path, ...)
let cmd = a:0 ? a:1 : 'lc!'
sil! exe cmd s:fnesc(a:path, 'c')
View
15 readme.md
@@ -32,8 +32,8 @@ Check `:help ctrlp-commands` and `:help ctrlp-extensions` for other commands.
Run `:help ctrlp-mappings` or submit `?` in CtrlP for more mapping help.
* Submit two or more dots `..` to go up the directory tree by one or multiple levels.
-* End the input string with a colon `:` followed by a command to execute it on the opening file(s):
-Use `:25` to jump to line 25.
+* End the input string with a colon `:` followed by a command to execute it on the opening file(s):
+Use `:25` to jump to line 25.
Use `:diffthis` when opening multiple files to run `:diffthis` on the first 4 files.
## Basic Options
@@ -44,17 +44,18 @@ Use `:diffthis` when opening multiple files to run `:diffthis` on the first 4 fi
let g:ctrlp_cmd = 'CtrlP'
```
-* When invoked, unless a starting directory is specified, CtrlP will set its local working directory according to this variable:
+* When invoked without an explicit starting directory, CtrlP will set its local working directory according to this variable:
```vim
let g:ctrlp_working_path_mode = 'ra'
```
- `'c'` - the directory of the current file.
- `'r'` - the nearest ancestor that contains one of these directories or files: `.git` `.hg` `.svn` `.bzr` `_darcs`
- `'a'` - like c, but only if the current working directory outside of CtrlP is not a direct ancestor of the directory of the current file.
- `0` or `''` (empty string) - disable this feature.
+ `'c'` - use the parent directory of the current file.
+ `'a'` - use the parent directory of the current file if it is not a descendant of the current working directory outside of CtrlP.
+ `'r'` - use the nearest ancestor of the current file that contains one of these markers: `.git` `.hg` `.svn` `.bzr` `_darcs`
+ `0` or `''` (empty string) - use the current working directory outside of CtrlP.
+ If more than one mode is specified, they will be tried in order until a directory is located.
Define additional root markers with the `g:ctrlp_root_markers` option.
* Exclude files and directories using Vim's `wildignore` and CtrlP's own `g:ctrlp_custom_ignore`:
Something went wrong with that request. Please try again.