Add a flag to jump to the first opened tab or window

This commit is contained in:
Kien N 2012-05-31 15:17:15 +07:00
parent 3e36061fbd
commit fcda2e4d59
2 changed files with 17 additions and 7 deletions

View File

@ -974,10 +974,10 @@ endf
fu! s:OpenMulti(...) fu! s:OpenMulti(...)
if !exists('s:marked') || s:opmul == '0' || !s:ispath | retu -1 | en if !exists('s:marked') || s:opmul == '0' || !s:ispath | retu -1 | en
" Get the options " Get the options
let opts = matchlist(s:opmul, '\v^(\d+)=(\w)=(\w)=$') let [nr, md] = [matchstr(s:opmul, '\d\+'), matchstr(s:opmul, '[thvi]')]
let [ur, jf] = [matchstr(s:opmul, 'r') == 'r', matchstr(s:opmul, 'j') == 'j']
let md = a:0 ? a:1 : ( md == '' ? 'v' : md )
let nopt = exists('g:ctrlp_open_multiple_files') let nopt = exists('g:ctrlp_open_multiple_files')
let [nr, md, ucr] = [get(opts, 1, nopt ? '' : '1'),
\ a:0 ? a:1 : get(opts, 2, 'v'), get(opts, 3, '')]
if s:argmap && !a:0 if s:argmap && !a:0
let md = s:argmaps(md) let md = s:argmaps(md)
if md == 'cancel' | retu | en if md == 'cancel' | retu | en
@ -994,7 +994,7 @@ fu! s:OpenMulti(...)
let useb = bufnr > 0 && buflisted(bufnr) && emptytail let useb = bufnr > 0 && buflisted(bufnr) && emptytail
" Move to a replaceable window " Move to a replaceable window
let ncmd = ( useb ? ['b', 'bo vert sb'] : ['e', 'bo vne'] ) let ncmd = ( useb ? ['b', 'bo vert sb'] : ['e', 'bo vne'] )
\ + ( ucr == 'r' ? [] : ['ignruw'] ) \ + ( ur ? [] : ['ignruw'] )
let fst = call('ctrlp#normcmd', ncmd) let fst = call('ctrlp#normcmd', ncmd)
" Check if the current window has a replaceable buffer " Check if the current window has a replaceable buffer
let repabl = empty(bufname('%')) && empty(&l:ft) let repabl = empty(bufname('%')) && empty(&l:ft)
@ -1009,8 +1009,7 @@ fu! s:OpenMulti(...)
let useb = bufnr > 0 && buflisted(bufnr) && emptytail let useb = bufnr > 0 && buflisted(bufnr) && emptytail
let snd = md != '' && has_key(cmds, md) ? let snd = md != '' && has_key(cmds, md) ?
\ ( useb ? cmds[md][0] : cmds[md][1] ) : ( useb ? 'vert sb' : 'vne' ) \ ( useb ? cmds[md][0] : cmds[md][1] ) : ( useb ? 'vert sb' : 'vne' )
let cmd = ic == 1 && ( !( ucr != 'r' && fst =~ '^[eb]$' ) || repabl ) let cmd = ic == 1 && ( !( !ur && fst =~ '^[eb]$' ) || repabl ) ? fst : snd
\ ? fst : snd
let conds = [( nr != '' && nr > 1 && nr < ic ) || ( nr == '' && ic > 1 ), let conds = [( nr != '' && nr > 1 && nr < ic ) || ( nr == '' && ic > 1 ),
\ nr != '' && nr < ic] \ nr != '' && nr < ic]
if conds[nopt] if conds[nopt]
@ -1021,8 +1020,17 @@ fu! s:OpenMulti(...)
en | en en | en
el el
cal s:openfile(cmd, useb ? bufnr : va, tail) | let ic += 1 cal s:openfile(cmd, useb ? bufnr : va, tail) | let ic += 1
if jf | if ic == 2
let crpos = [tabpagenr(), winnr()]
el
let crpos[0] += tabpagenr() == crpos[0]
let crpos[1] += winnr() == crpos[1]
en | en
en en
endfo endfo
if jf && exists('crpos') && ic > 2
exe ( md == 't' ? 'tabn '.crpos[0] : crpos[1].'winc w' )
en
let &swb = swb let &swb = swb
endf endf
" ** Helper functions {{{1 " ** Helper functions {{{1

View File

@ -286,7 +286,7 @@ If non-zero, this will enable opening multiple files with <c-z> and <c-o>: >
let g:ctrlp_open_multiple_files = 'v' let g:ctrlp_open_multiple_files = 'v'
< <
Example: > Example: >
let g:ctrlp_open_multiple_files = '2vr' let g:ctrlp_open_multiple_files = '2vjr'
< <
For the number: For the number:
- If given, it'll be used as the maximum number of windows or tabs to create - If given, it'll be used as the maximum number of windows or tabs to create
@ -297,6 +297,7 @@ For the letters:
h - each file in a new horizontal split. h - each file in a new horizontal split.
v - each file in a new vertical split. v - each file in a new vertical split.
i - all files as hidden buffers. i - all files as hidden buffers.
j - after opening, jump to the first opened tab or window.
Reuse the current window: Reuse the current window:
tr, tr,
hr, hr,
@ -1025,6 +1026,7 @@ Special thanks:~
=============================================================================== ===============================================================================
CHANGELOG *ctrlp-changelog* CHANGELOG *ctrlp-changelog*
+ New value for |g:ctrlp_open_multiple_files|: 'j'.
+ Allow using <c-t>, <c-x>, <c-v> to open files marked by <c-z>. + Allow using <c-t>, <c-x>, <c-v> to open files marked by <c-z>.
Before 2012/05/15~ Before 2012/05/15~