Permalink
Browse files

Improve directory mode

* More mappings for different types of :cd
  + <cr> change the local working directory inside ctrlp.
  + <c-t> change the global working directory. (exit ctrlp)
  + <c-v> change the local working directory for the current window. (exit ctrlp)
  + <c-x> change the global working directory to |CtrlP|�s current local working
    directory (exit).
* Some clean up.
  • Loading branch information...
1 parent 7821160 commit b1a8c3d21e69b972032c65bf89e72ec7758f852a @kien committed Dec 1, 2011
Showing with 54 additions and 41 deletions.
  1. +16 −11 autoload/ctrlp.vim
  2. +12 −8 autoload/ctrlp/dir.vim
  3. +0 −12 autoload/ctrlp/tag.vim
  4. +10 −3 autoload/ctrlp/utils.vim
  5. +16 −7 doc/ctrlp.txt
View
@@ -2,7 +2,7 @@
" File: autoload/ctrlp.vim
" Description: Fuzzy file, buffer and MRU file finder.
" Author: Kien Nguyen <github.com/kien>
-" Version: 1.6.2
+" Version: 1.6.3
" =============================================================================
" Static variables {{{
@@ -174,9 +174,7 @@ fu! s:Files()
try | cal s:UserCommand(cwd, lscmd) | cat | retu [] | endt
en
" Remove base directory
- let path = &ssl || !exists('+ssl') ? getcwd().'/' :
- \ substitute(getcwd(), '\\', '\\\\', 'g').'\\'
- cal map(g:ctrlp_allfiles, 'substitute(v:val, path, "", "g")')
+ cal ctrlp#rmbasedir(g:ctrlp_allfiles)
let read_cache = 0
el
let g:ctrlp_allfiles = ctrlp#utils#readfile(cache_file)
@@ -912,6 +910,12 @@ fu! s:ispathitem()
retu 0
endf
+fu! ctrlp#rmbasedir(items)
+ let path = &ssl || !exists('+ssl') ? getcwd().'/' :
+ \ substitute(getcwd(), '\\', '\\\\', 'g').'\\'
+ retu map(a:items, 'substitute(v:val, path, "", "g")')
+endf
+
fu! s:parentdir(curr)
let parent = s:getparent(a:curr)
if parent != a:curr | cal ctrlp#setdir(parent) | en
@@ -972,9 +976,10 @@ fu! ctrlp#fnesc(path)
retu exists('*fnameescape') ? fnameescape(a:path) : escape(a:path, " %#*?|<\"\n")
endf
-fu! ctrlp#setdir(path)
+fu! ctrlp#setdir(path, ...)
+ let cmd = exists('a:1') ? a:1 : 'lc!'
try
- exe 'lc!' ctrlp#fnesc(a:path)
+ exe cmd.' '.ctrlp#fnesc(a:path)
cat
cal ctrlp#msg("Can't change working dir. Directory not exists.")
endt
@@ -1269,6 +1274,11 @@ fu! s:lscommand()
retu cmd[1]
en
endf
+"}}}
+" Extensions {{{
+fu! s:tagfiles()
+ retu filter(map(tagfiles(), 'fnamemodify(v:val, ":p")'), 'filereadable(v:val)')
+endf
fu! ctrlp#exit()
cal s:PrtExit()
@@ -1282,11 +1292,6 @@ fu! ctrlp#setlines(type)
cal s:SetLines(a:type)
endf
"}}}
-" Extensions {{{
-fu! s:tagfiles()
- retu filter(map(tagfiles(), 'fnamemodify(v:val, ":p")'), 'filereadable(v:val)')
-endf
-"}}}
"}}}
" * Initialization {{{
fu! s:SetLines(type)
@@ -59,9 +59,7 @@ fu! ctrlp#dir#init(...)
if g:ctrlp_newdir || !filereadable(cafile)
let g:ctrlp_alldirs = []
cal s:globdirs(s:cwd, 0)
- let path = &ssl || !exists('+ssl') ? getcwd().'/' :
- \ substitute(getcwd(), '\\', '\\\\', 'g').'\\'
- cal map(g:ctrlp_alldirs, 'substitute(v:val, path, "", "g")')
+ cal ctrlp#rmbasedir(g:ctrlp_alldirs)
let read_cache = 0
el
let g:ctrlp_alldirs = ctrlp#utils#readfile(cafile)
@@ -78,11 +76,17 @@ fu! ctrlp#dir#init(...)
endf
fu! ctrlp#dir#accept(mode, str)
- cal ctrlp#setdir(s:cwd.ctrlp#utils#lash().a:str)
- sil! cal ctrlp#statusline()
- cal ctrlp#setlines(s:id)
- cal ctrlp#recordhist()
- cal ctrlp#prtclear()
+ let path = a:mode == 'h' ? getcwd() : s:cwd.ctrlp#utils#lash().a:str
+ if a:mode =~ 't\|v\|h'
+ cal ctrlp#exit()
+ en
+ cal ctrlp#setdir(path, a:mode =~ 't\|h' ? 'chd!' : 'lc!')
+ if a:mode == 'e'
+ sil! cal ctrlp#statusline()
+ cal ctrlp#setlines(s:id)
+ cal ctrlp#recordhist()
+ cal ctrlp#prtclear()
+ en
endf
fu! ctrlp#dir#id()
@@ -19,10 +19,6 @@ let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
"}}}
" Utilities {{{
-fu! s:times(tagfiles)
- retu map(copy(a:tagfiles), 'getftime(v:val)')
-endf
-
fu! s:nodup(items)
let dict = {}
for each in a:items
@@ -31,14 +27,6 @@ fu! s:nodup(items)
retu keys(dict)
endf
-fu! s:concat(lists)
- let lists = []
- for each in a:lists
- cal extend(lists, each)
- endfo
- retu lists
-endf
-
fu! s:findcount(str)
let [tg, fname] = split(a:str, '\t\+\ze[^\t]\+$')
let [&l:tags, fname] = [s:ltags, expand(fname, 1)]
@@ -35,22 +35,29 @@ endf
fu! ctrlp#utils#readfile(file)
if filereadable(a:file)
let data = readfile(a:file)
- if empty(data) || type(data) != 3 | unl data | let data = [] | en
+ if empty(data) || type(data) != 3
+ unl data
+ let data = []
+ en
retu data
en
retu []
endf
fu! ctrlp#utils#mkdir(dir)
- if exists('*mkdir') && !isdirectory(a:dir) | sil! cal mkdir(a:dir) | en
+ if exists('*mkdir') && !isdirectory(a:dir)
+ sil! cal mkdir(a:dir)
+ en
endf
fu! ctrlp#utils#writecache(lines, ...)
let cache_dir = exists('a:1') ? a:1 : s:cache_dir
cal ctrlp#utils#mkdir(cache_dir)
if isdirectory(cache_dir)
sil! cal writefile(a:lines, exists('a:2') ? a:2 : ctrlp#utils#cachefile())
- if !exists('a:1') | let g:ctrlp_newcache = 0 | en
+ if !exists('a:1')
+ let g:ctrlp_newcache = 0
+ en
en
endf
View
@@ -1,4 +1,4 @@
-*ctrlp.txt* Fuzzy file, buffer and MRU file finder. v1.6.2
+*ctrlp.txt* Fuzzy file, buffer and MRU file finder. v1.6.3
*CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'*
===============================================================================
# #
@@ -297,7 +297,7 @@ If is 1, update after 250ms. If bigger than 1, the number will be used as the
delay time in milliseconds.
*'g:ctrlp_use_migemo'*
-Set this to 1 to use Migemo Pattern for Japanese filenames. Migemo Search
+Set this to 1 to use Migemo Pattern for Japanese filenames. Migemo Search only
works in |regexp| mode. To split the pattern, separate words with space: >
let g:ctrlp_use_migemo = 0
<
@@ -500,27 +500,36 @@ g) Submit ? to open this help file.
Extensions are optional. To enable an extension, add its name to the variable
g:ctrlp_extensions: >
- let g:ctrlp_extensions = ['tag', 'qfx']
+ let g:ctrlp_extensions = ['tag', 'quickfix', 'dir']
<
Available extensions:~
+ *ctrlp-tag-mode*
* Tag mode:~
- - Shortname: 'tag'
+ - Name: 'tag'
- Command: ':CtrlPTag'
- Search for a tag within a generated central tags file, and jump to the
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*
* Quickfix mode:~
- - Shortname: 'qfx'
+ - Name: 'quickfix'
- Command: ':CtrlPQuickfix'
- Search for an entry in the current quickfix errors and jump to it.
+ *ctrlp-dir-mode*
* Directory mode:~
- - Shortname: 'dir'
+ - Name: 'dir'
- Command: ':CtrlPDir'
- - Search for a directory and change the local working directory to it.
+ - Search for a directory and change the working directory to it.
+ - Mappings:
+ + <cr> change the local working directory for |CtrlP| and keep it open.
+ + <c-t> change the global working directory (exit).
+ + <c-v> change the local working directory for the current window (exit).
+ + <c-x> change the global working directory to |CtrlP|’s current local
+ working directory (exit).
===============================================================================
EXTENDING *ctrlp-extending*

0 comments on commit b1a8c3d

Please sign in to comment.