Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Splitting instead of hiding

When the active buffer has been modified, instead of using :hide, open a new
split for the new buffer if `confirm`, `hidden`, `autowrite` and `autowriteall`
are all off.
  • Loading branch information...
commit 44347fec88025c0f79b9c6b85e33134ad381bc7e 1 parent b50b5a6
@kien authored
View
44 autoload/ctrlp.vim
@@ -871,7 +871,8 @@ fu! ctrlp#acceptfile(mode, line, ...)
" Reset &switchbuf option
let [swb, &swb] = [&swb, '']
" Open new window/buffer
- let args = [cmd, useb ? bufnr : filpath, a:0 ? ' +'.a:1 : tail, useb, j2l]
+ let [fid, tail] = [( useb ? bufnr : filpath ), ( a:0 ? ' +'.a:1 : tail )]
+ let args = [cmd, fid, tail, 1, [useb, j2l]]
cal call('s:openfile', args)
let &swb = swb
en
@@ -950,7 +951,7 @@ fu! s:CreateNewFile(...)
\ s:newfop =~ '2\|h' || ( a:0 && a:1 == 'h' ) || md == 'h' ? 'new' :
\ s:newfop =~ '3\|v' || ( a:0 && a:1 == 'v' ) || md == 'v' ? 'vne' :
\ ctrlp#normcmd('e')
- cal s:openfile(cmd, filpath, tail)
+ cal s:openfile(cmd, filpath, tail, 1)
endf
" * OpenMulti() {{{1
fu! s:MarkToOpen()
@@ -1019,9 +1020,9 @@ fu! s:OpenMulti(...)
cal s:sanstail(join(s:prompt, ''))
cal s:PrtExit()
if nr == '0' || md == 'i'
- retu map(mkd, "s:openfile('bad', fnamemodify(v:val, ':.'), '')")
+ retu map(mkd, "s:openfile('bad', v:val, '', 0)")
en
- let [tail, fnesc] = [s:tail(), exists('*fnameescape') && v:version > 701]
+ let tail = s:tail()
let [emptytail, bufnr] = [empty(tail), bufnr('^'.mkd[0].'$')]
let useb = bufnr > 0 && buflisted(bufnr) && emptytail
" Move to a replaceable window
@@ -1048,19 +1049,16 @@ fu! s:OpenMulti(...)
let conds = [( nr != '' && nr > 1 && nr < ic ) || ( nr == '' && ic > 1 ),
\ nr != '' && nr < ic]
if conds[nopt]
- if bufnr <= 0 | if fnesc
- cal s:openfile('bad', fnamemodify(va, ':.'), '')
- el
- cal s:openfile(cmd, va, tail) | sil! hid clo!
- en | en
+ if !buflisted(bufnr) | cal s:openfile('bad', va, '', 0) | en
el
- cal s:openfile(cmd, useb ? bufnr : va, tail) | let ic += 1
- if jf | if ic == 2
+ cal s:openfile(cmd, useb ? bufnr : va, tail, ic == 1 ? 1 : 0)
+ if jf | if ic == 1
let crpos = [tabpagenr(), winnr()]
el
let crpos[0] += tabpagenr() <= crpos[0]
- let crpos[1] += winnr() == crpos[1]
+ let crpos[1] += winnr() <= crpos[1]
en | en
+ let ic += 1
en
endfo
if jf && exists('crpos') && ic > 2
@@ -1495,6 +1493,14 @@ fu! s:buftab(bufnr, md)
retu [0, 0]
endf
+fu! s:bufwins(bufnr)
+ let winns = 0
+ for tabnr in range(1, tabpagenr('$'))
+ let winns += count(tabpagebuflist(tabnr), a:bufnr)
+ endfo
+ retu winns
+endf
+
fu! ctrlp#normcmd(cmd, ...)
if a:0 < 2 && s:nosplit() | retu a:cmd | en
let norwins = filter(range(1, winnr('$')),
@@ -1515,6 +1521,11 @@ fu! ctrlp#normcmd(cmd, ...)
retu a:0 ? a:1 : 'bo vne'
endf
+fu! ctrlp#modfilecond()
+ retu &mod && !&hid && &bh != 'hide' && !&cf && !&awa
+ \ && s:bufwins(bufnr('%')) == 1
+endf
+
fu! s:nosplit()
retu !empty(s:nosplit) && match([bufname('%'), &l:ft, &l:bt], s:nosplit) >= 0
endf
@@ -1767,11 +1778,12 @@ fu! s:buffunc(e)
en
endf
-fu! s:openfile(cmd, fid, tail, ...)
- let cmd = a:cmd =~ '^[eb]$' && &modified ? 'hid '.a:cmd : a:cmd
+fu! s:openfile(cmd, fid, tail, chkmod, ...)
+ let cmd = a:chkmod && a:cmd =~ '^[eb]$' && ctrlp#modfilecond()
+ \ && !( a:cmd == 'b' && &aw ) ? ( a:cmd == 'b' ? 'sb' : 'sp' ) : a:cmd
let cmd = cmd =~ '^tab' ? ctrlp#tabcount().cmd : cmd
- let j2l = a:0 && a:1 ? a:2 : 0
- exe cmd.( a:0 && a:1 ? '' : a:tail ) ctrlp#fnesc(a:fid)
+ let j2l = a:0 && a:1[0] ? a:1[1] : 0
+ exe cmd.( a:0 && a:1[0] ? '' : a:tail ) ctrlp#fnesc(a:fid)
if j2l
exe j2l
en
View
2  autoload/ctrlp/quickfix.vim
@@ -47,7 +47,7 @@ fu! ctrlp#quickfix#accept(mode, str)
cal ctrlp#exit()
let cmd = md == 't' ? 'tabe' : md == 'h' ? 'new' : md == 'v' ? 'vne'
\ : ctrlp#normcmd('e')
- let cmd = cmd == 'e' && &modified ? 'hid e' : cmd
+ let cmd = cmd == 'e' && ctrlp#modfilecond() ? 'new' : cmd
exe cmd ctrlp#fnesc(filpath)
cal cursor(items[2], items[3])
sil! norm! zvzz
View
3  autoload/ctrlp/tag.vim
@@ -97,7 +97,8 @@ fu! ctrlp#tag#accept(mode, str)
\ 'e': ['', 'tj'],
\ }
let cmd = fnd[0] == 1 ? cmds[a:mode][0] : cmds[a:mode][1]
- let cmd = cmd == 'tj' && &mod ? 'hid '.cmd : cmd
+ let cmd = a:mode == 'e' && ctrlp#modfilecond() && !&aw
+ \ ? ( cmd == 'tj' ? 'stj' : 'sp' ) : cmd
let cmd = a:mode == 't' ? ctrlp#tabcount().cmd : cmd
if fnd[0] == 1
if cmd != ''

0 comments on commit 44347fe

Please sign in to comment.
Something went wrong with that request. Please try again.