Commits

kien  committed 3b891bc Draft

Option to change the new tabpage's position

  • Participants
  • Parent commits ec5f272

Comments (0)

Files changed (3)

File autoload/ctrlp.vim

 	\ 'root_markers':          ['s:rmarkers', []],
 	\ 'split_window':          ['s:splitwin', 0],
 	\ 'status_func':           ['s:status', {}],
+	\ 'tabpage_position':      ['s:tabpage', 'ac'],
 	\ 'use_caching':           ['s:caching', 1],
 	\ 'use_migemo':            ['s:migemo', 0],
 	\ 'user_command':          ['s:usrcmd', ''],
 		\ + ( ur ? [] : ['ignruw'] )
 	let fst = call('ctrlp#normcmd', ncmd)
 	" Check if the current window has a replaceable buffer
-	let repabl = empty(bufname('%')) && empty(&l:ft)
+	let repabl = !( md == 't' && !ur ) && empty(bufname('%')) && empty(&l:ft)
 	" Commands for the rest of the files
 	let [ic, cmds] = [1, { 'v': ['vert sb', 'vne'], 'h': ['sb', 'new'],
 		\ 't': ['tab sb', 'tabe'] }]
 	let [swb, &swb] = [&swb, '']
+	if md == 't' && ctrlp#tabcount() < tabpagenr()
+		let s:tabct = ctrlp#tabcount()
+	en
 	" Open the files
 	for va in mkd
 		let bufnr = bufnr('^'.va.'$')
 			if jf | if ic == 2
 				let crpos = [tabpagenr(), winnr()]
 			el
-				let crpos[0] += tabpagenr() == crpos[0]
+				let crpos[0] += tabpagenr() <= crpos[0]
 				let crpos[1] += winnr() == crpos[1]
 			en | en
 		en
 		exe ( md == 't' ? 'tabn '.crpos[0] : crpos[1].'winc w' )
 	en
 	let &swb = swb
+	unl! s:tabct
 endf
 " ** Helper functions {{{1
 " Sorting {{{2
 	let roh = [
 		\ ['OpenMulti', '/h[i]dden/[c]lear', ['i', 'c']],
 		\ ['CreateNewFile', '/[r]eplace', ['r']],
-		\ ['OpenSeleted', '/[r]eplace/h[i]dden', ['r', 'i']],
+		\ ['OpenSelected', '/[r]eplace/h[i]dden', ['r', 'i']],
 		\ ]
 	let str = roh[a:i][0].': [t]ab/[v]ertical/[h]orizontal'.roh[a:i][1].'? '
 	retu s:choices(str, ['t', 'v', 'h'] + roh[a:i][2], 's:argmaps', [a:md, a:i])
 
 fu! s:openfile(cmd, fid, tail, ...)
 	let cmd = a:cmd =~ '^[eb]$' && &modified ? 'hid '.a:cmd : a:cmd
-	let cmd = cmd =~ '^tab' ? tabpagenr('$').cmd : 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)
 	if j2l
 	en
 endf
 
+fu! ctrlp#tabcount()
+	if exists('s:tabct')
+		let tabct = s:tabct
+		let s:tabct += 1
+	elsei !type(s:tabpage)
+		let tabct = s:tabpage
+	elsei type(s:tabpage) == 1
+		let tabpos =
+			\ s:tabpage =~ 'c' ? tabpagenr() :
+			\ s:tabpage =~ 'f' ? 1 :
+			\ s:tabpage =~ 'l' ? tabpagenr('$') :
+			\ tabpagenr()
+		let tabct =
+			\ s:tabpage =~ 'a' ? tabpos :
+			\ s:tabpage =~ 'b' ? tabpos - 1 :
+			\ tabpos
+	en
+	retu tabct < 0 ? 0 : tabct
+endf
+
 fu! s:settype(type)
 	retu a:type < 0 ? exists('s:itemtype') ? s:itemtype : 0 : a:type
 endf

File autoload/ctrlp/tag.vim

 		\ }
 	let cmd = fnd[0] == 1 ? cmds[a:mode][0] : cmds[a:mode][1]
 	let cmd = cmd == 'tj' && &modified ? 'hid '.cmd : cmd
-	let cmd = cmd =~ '^tab' ? tabpagenr('$').cmd : cmd
+	let cmd = cmd =~ '^tab' ? ctrlp#tabcount().cmd : cmd
 	if fnd[0] == 1
 		if cmd != ''
 			exe cmd

File doc/ctrlp.txt

   |ctrlp_max_height|            Max height of the match window.
   |ctrlp_switch_buffer|         Jump to an open buffer if already opened.
   |ctrlp_reuse_window|          Reuse special windows (help, quickfix, etc).
+  |ctrlp_tabpage_position|      Where to put the new tab page.
   |ctrlp_working_path_mode|     How to set CtrlP's local working directory.
   |ctrlp_root_markers|          Additional, high priority root markers.
   |ctrlp_use_caching|           Use per-session caching or not.
   let g:ctrlp_reuse_window = 'netrw\|help\|quickfix'
 <
 
+                                                   *'g:ctrlp_tabpage_position'*
+Where to put the new tab page when opening one: >
+  let g:ctrlp_tabpage_position = 'ac'
+<
+  a - after.
+  b - before.
+  c - the current tab page.
+  l - the last tab page.
+  f - the first tab page.
+
                                                   *'g:ctrlp_working_path_mode'*
 When starting up, CtrlP sets its local working directory according to this
 variable: >
     Open the selected file in the 'current' window if possible.
 
   <c-t>
-    Open the selected file in a new 'tab' after the last tabpage.
+    Open the selected file in a new 'tab'.
 
   <c-v>
     Open the selected file in a 'vertical' split.
 ===============================================================================
 CHANGELOG                                                     *ctrlp-changelog*
 
+    + New option: |g:ctrlp_tabpage_position|.
+
 Before 2012/06/15~
 
     + New value for |g:ctrlp_follow_symlinks|: 2.