Add a warning

`:e` cmd fails when buffer's been changed and user doesn't use `set autowriteall` or `set hidden`.
This commit is contained in:
Kien N 2011-10-20 17:54:39 +07:00
parent eefc3cd4e1
commit 8d99466502
2 changed files with 35 additions and 16 deletions

View File

@ -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 endif
if exists('opcmd') && !empty(opcmd)
cal s:insertcache(str) cal s:insertcache(str)
exe s:currwin.'winc w'
if s:newfop == 1
tabnew
endif
cal s:openfile(opcmd)
endif
endfunc "}}} endfunc "}}}
" * OpenMulti {{{ " * OpenMulti {{{
@ -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
@ -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[^\/]\+[\/]\?$', '', '')
@ -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
"}}} "}}}
@ -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
@ -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
@ -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])

View File

@ -266,7 +266,7 @@ Set to 0 to disable prompts 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, itll be used as the maximum number of windows to create when If bigger than 1, itll be used as the maximum number of windows to create when
opening the files (the rest will be hidden buffers). If is 1, itll open all opening the files (the rest will be hidden buffers). If is 1, itll open all