Skip to content

Commit

Permalink
Add a warning
Browse files Browse the repository at this point in the history
`:e` cmd fails when buffer's been changed and user doesn't use `set autowriteall` or `set hidden`.
  • Loading branch information
kien committed Oct 20, 2011
1 parent eefc3cd commit 8d99466
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
49 changes: 34 additions & 15 deletions autoload/ctrlp.vim
Expand Up @@ -439,27 +439,31 @@ func! s:CreateNewFile() "{{{
let str = prt[0] . prt[1] . prt[2] let str = prt[0] . prt[1] . prt[2]
if empty(str) | retu | endif if empty(str) | retu | endif
let arr = split(str, '[\/]') let arr = split(str, '[\/]')
cal map(arr, 'escape(v:val, "%#")')
let fname = remove(arr, -1) let fname = remove(arr, -1)
exe s:currwin.'winc w' if s:newfop <= 1 " In new tab or current window
if s:newfop == 1 " In new tab
tabnew
let cmd = 'e' let cmd = 'e'
elseif s:newfop == 2 " In new hor split elseif s:newfop == 2 " In new hor split
let cmd = 'new' let cmd = 'new'
elseif s:newfop == 3 " In new ver split elseif s:newfop == 3 " In new ver split
let cmd = 'vne' let cmd = 'vne'
elseif !s:newfop " In current window
let cmd = 'e'
endif endif
if len(arr) if len(arr)
if isdirectory(s:createparentdirs(arr)) if isdirectory(s:createparentdirs(arr))
sil! exe 'bo '.cmd.' '.str let filpath = escape(getcwd().s:lash.str, '%#')
let opcmd = 'bo '.cmd.' '.filpath
endif endif
else else
sil! exe 'bo '.cmd.' '.fname let filpath = escape(getcwd().s:lash.fname, '%#')
let opcmd = 'bo '.cmd.' '.filpath
endif
if exists('opcmd') && !empty(opcmd)
cal s:insertcache(str)
exe s:currwin.'winc w'
if s:newfop == 1
tabnew
endif
cal s:openfile(opcmd)
endif endif
cal s:insertcache(str)
endfunc "}}} endfunc "}}}


" * OpenMulti {{{ " * OpenMulti {{{
Expand Down Expand Up @@ -523,7 +527,7 @@ func! s:OpenMulti()
let wnr = exists('wnr') ? wnr : 1 let wnr = exists('wnr') ? wnr : 1
exe wnr.'winc w' exe wnr.'winc w'
for key in keys(marked) for key in keys(marked)
let filpath = marked[key] let filpath = escape(marked[key], '%#')
let cmd = ic == 1 ? 'e ' : 'vne ' let cmd = ic == 1 ? 'e ' : 'vne '
sil! exe cmd.filpath sil! exe cmd.filpath
if s:opmul > 1 && s:opmul < ic if s:opmul > 1 && s:opmul < ic
Expand Down Expand Up @@ -806,13 +810,14 @@ endfunc
" * SetWorkingPath {{{ " * SetWorkingPath {{{
func! s:FindRoot(curr, mark, depth, type) func! s:FindRoot(curr, mark, depth, type)
let depth = a:depth + 1 let depth = a:depth + 1
let notfound = empty(globpath(a:curr, a:mark)) let notfound = empty(globpath(a:curr, a:mark, 1))
if !notfound || depth > s:maxdepth if !notfound || depth > s:maxdepth
if notfound | retu | endif if notfound | retu 0 | endif
if a:type if a:type
let s:vcsroot = depth <= s:maxdepth ? a:curr : '' let s:vcsroot = depth <= s:maxdepth ? a:curr : ''
else else
sil! exe 'chd!' a:curr sil! exe 'chd!' a:curr
retu 1
endif endif
else else
let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/]\?$', '', '') let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/]\?$', '', '')
Expand Down Expand Up @@ -850,8 +855,8 @@ func! ctrlp#SetWorkingPath(...)
cal extend(markers, s:rmarkers, 0) cal extend(markers, s:rmarkers, 0)
endif endif
for marker in markers for marker in markers
cal s:FindRoot(getcwd(), marker, 0, 0) let found = s:FindRoot(getcwd(), marker, 0, 0)
if getcwd() != expand('%:p:h') | break | endif if getcwd() != expand('%:p:h') || found | break | endif
endfor endfor
endfunc endfunc
"}}} "}}}
Expand Down Expand Up @@ -943,7 +948,8 @@ func! s:AcceptSelection(mode,...) "{{{
endif endif
endif endif
" Open new window/buffer " Open new window/buffer
sil! exe 'bo '.cmd.tail.' '.filpath let opcmd = 'bo '.cmd.tail.' '.filpath
cal s:openfile(opcmd)
endif endif
if !empty('tail') if !empty('tail')
sil! norm! zOzz sil! norm! zOzz
Expand Down Expand Up @@ -1239,6 +1245,18 @@ endfunc
"}}} "}}}


" Misc {{{ " Misc {{{
func! s:openfile(cmd)
try
exe a:cmd
retu 1
catch
echoh Error
echon 'Operation can''t be completed. Make sure filename is valid.'
echoh None
retu 0
endtry
endfunc

func! s:walker(max, pos, dir, ...) func! s:walker(max, pos, dir, ...)
if a:dir == 1 if a:dir == 1
let pos = a:pos < a:max ? a:pos + 1 : 0 let pos = a:pos < a:max ? a:pos + 1 : 0
Expand All @@ -1264,6 +1282,7 @@ func! s:insertcache(str)
let cache_file = ctrlp#utils#cachefile() let cache_file = ctrlp#utils#cachefile()
if filereadable(cache_file) if filereadable(cache_file)
let data = readfile(cache_file) let data = readfile(cache_file)
if index(data, a:str) >= 0 | retu | endif
if strlen(a:str) <= strlen(data[0]) if strlen(a:str) <= strlen(data[0])
let pos = 0 let pos = 0
elseif strlen(a:str) >= strlen(data[-1]) elseif strlen(a:str) >= strlen(data[-1])
Expand Down
2 changes: 1 addition & 1 deletion doc/ctrlp.txt
Expand Up @@ -266,7 +266,7 @@ Set to 0 to disable prompt’s history.


*'g:ctrlp_open_multi'* *'g:ctrlp_open_multi'*
If non-zero this will enable opening multiple files with <c-z> and <c-o>: > If non-zero this will enable opening multiple files with <c-z> and <c-o>: >
let g:ctrlp_open_multi = 0 let g:ctrlp_open_multi = 1
< <
If bigger than 1, it’ll be used as the maximum number of windows to create when If bigger than 1, it’ll be used as the maximum number of windows to create when
opening the files (the rest will be hidden buffers). If is 1, it’ll open all opening the files (the rest will be hidden buffers). If is 1, it’ll open all
Expand Down

0 comments on commit 8d99466

Please sign in to comment.