Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve g:ctrlp_working_path_mode #540

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 29 additions & 15 deletions autoload/ctrlp.vim
Expand Up @@ -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(...)
Expand Down Expand Up @@ -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')
Expand Down
15 changes: 8 additions & 7 deletions readme.md
Expand Up @@ -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
Expand All @@ -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`:
Expand Down