1. kien
  2. ctrlp.vim

Commits

kien  committed 90aebb0

Expand default input if is string...

Don't sort 1, 2 if prompt's empty
Get lines from buffers first
Insert filename under the cursor (like gf)
Tweak MRE buffer sorting

  • Participants
  • Parent commits 6d126fe
  • Branches default

Comments (0)

Files changed (4)

File autoload/ctrlp.vim

View file
 		\ 'PrtInsert("s")':       ['<F3>'],
 		\ 'PrtInsert("v")':       ['<F4>'],
 		\ 'PrtInsert("+")':       ['<F6>', '<MiddleMouse>'],
+		\ 'PrtInsert("gf")':      ['<c-\>'],
 		\ 'PrtCurStart()':        ['<c-a>'],
 		\ 'PrtCurEnd()':          ['<c-e>'],
 		\ 'PrtCurLeft()':         ['<c-h>', '<left>', '<c-^>'],
 	\ 'PrtInsert("s")',
 	\ 'PrtInsert("v")',
 	\ 'PrtInsert("+")',
+	\ 'PrtInsert("gf")',
 	\ ]
 
 " Keypad
 endf
 " - Buffers {{{1
 fu! ctrlp#buffers(...)
-	let ids = filter(range(1, bufnr('$')), 'empty(getbufvar(v:val, "&bt"))'
-		\ .' && getbufvar(v:val, "&bl") && strlen(bufname(v:val))')
+	let ids = sort(filter(range(1, bufnr('$')), 'empty(getbufvar(v:val, "&bt"))'
+		\ .' && getbufvar(v:val, "&bl") && strlen(bufname(v:val))'), 's:compmreb')
 	retu a:0 && a:1 == 'id' ? ids : map(ids, 'fnamemodify(bufname(v:val), ":.")')
 endf
 " * MatchedItems() {{{1
 		if s:dohighlight() | cal clearmatches() | en
 		retu
 	en
+	let s:matched = copy(lines)
 	" Sorting
-	if s:dosort()
+	if !s:nosort()
 		let s:compat = a:pat
 		cal sort(lines, 's:mixedsort')
 		unl s:compat
 	en
-	let s:matched = copy(lines)
 	if s:mwreverse | cal reverse(lines) | en
 	let s:lines = copy(lines)
 	cal map(lines, 's:formatline(v:val)')
 		let txt = txt && !stridx(s:crfpath, s:dyncwd)
 			\ ? ctrlp#rmbasedir([s:crfpath])[0] : ''
 		let txt = txt != '' ? txt.s:lash(s:crfpath) : ''
+	el
+		let txt = expand(txt, 1)
 	en
 	let s:prompt[0] = txt
 endf
 	let s:prompt[0] .= a:type == 'w' ? s:crword
 		\ : a:type == 's' ? getreg('/')
 		\ : a:type == 'v' ? s:crvisual
-		\ : a:type == '+' ? substitute(getreg('+'), '\n', '\\n', 'g') : s:prompt[0]
+		\ : a:type == '+' ? substitute(getreg('+'), '\n', '\\n', 'g')
+		\ : a:type == 'gf' ? s:crgfile : s:prompt[0]
 	cal s:BuildPrompt(1)
 	unl s:act_add
 endf
 endf
 
 fu! s:compmreb(...)
-	" By last entered time (buffer)
-	if !exists('s:mrbs')
-		let s:mrbs = ctrlp#mrufiles#bufs()
-	en
-	let id1 = index(s:mrbs, fnamemodify(a:1, ':p'))
-	let id2 = index(s:mrbs, fnamemodify(a:2, ':p'))
+	" By last entered time (bufnr)
+	let [id1, id2] = [index(s:mrbs, a:1), index(s:mrbs, a:2)]
 	retu id1 == id2 ? 0 : id1 > id2 ? 1 : -1
 endf
 
 fu! s:compmref(...)
 	" By last entered time (MRU)
-	let id1 = index(g:ctrlp_lines, a:1)
-	let id2 = index(g:ctrlp_lines, a:2)
+	let [id1, id2] = [index(g:ctrlp_lines, a:1), index(g:ctrlp_lines, a:2)]
 	retu id1 == id2 ? 0 : id1 > id2 ? 1 : -1
 endf
 
 fu! s:comparent(...)
 	" By same parent dir
-	if match(s:crfpath, escape(s:dyncwd, '.^$*\')) >= 0
+	if !stridx(s:crfpath, s:dyncwd)
 		let [as1, as2] = [s:dyncwd.s:lash().a:1, s:dyncwd.s:lash().a:2]
 		let [loc1, loc2] = [s:getparent(as1), s:getparent(as2)]
 		if loc1 == s:crfpath && loc2 != s:crfpath | retu -1 | en
 
 fu! s:mixedsort(...)
 	let [cln, cml] = [ctrlp#complen(a:1, a:2), s:compmatlen(a:1, a:2)]
-	if s:ispath && s:height < 51
+	if s:ispath
 		let ms = []
 		if s:height < 21
 			if s:itemtype !~ '\v^(1|2)$' | let ms += [s:comptime(a:1, a:2)] | en
-			let ms += [s:compfnlen(a:1, a:2), s:comparent(a:1, a:2)]
+			let ms += s:compfnlen(a:1, a:2)
+			if !s:itemtype | let ms += [s:comparent(a:1, a:2)] | en
 		en
-		let time = s:itemtype == 1 ? [s:compmreb(a:1, a:2)]
-			\ : s:itemtype == 2 ? [s:compmref(a:1, a:2)] : []
-		let ms += time + [cml] + [0, 0, 0, 0]
+		if s:itemtype =~ '\v^(1|2)$' | let ms += [s:compmref(a:1, a:2)] | en
+		let ms += [cml, 0, 0, 0]
 		let mp = call('s:multipliers', ms[:3])
 		retu cln + ms[0] * mp[0] + ms[1] * mp[1] + ms[2] * mp[2] + ms[3] * mp[3]
 	en
 	let s:dosort = s:getextvar('sort')
 endf
 
-fu! s:dosort()
-	retu s:matcher == {} && ( ( s:itemtype != 2 && s:nolim != 1 )
-		\ || s:prompt != ['', '', ''] ) && !( s:itemtype == 2 && s:mrudef )
-		\ && s:dosort
+fu! s:nosort()
+	retu s:matcher != {} || s:nolim == 1 || ( s:itemtype == 2 && s:mrudef )
+		\ || ( s:itemtype =~ '\v^(1|2)$' && s:prompt == ['', '', ''] ) || !s:dosort
 endf
 
 fu! s:narrowable()
 fu! s:getenv()
 	let [s:cwd, s:winres] = [getcwd(), [winrestcmd(), &lines, winnr('$')]]
 	let [s:crfile, s:crfpath] = [expand('%:p', 1), expand('%:p:h', 1)]
-	let [s:crword, s:crline] = [expand('<cword>'), getline('.')]
+	let [s:crword, s:crline] = [expand('<cword>', 1), getline('.')]
 	let [s:winh, s:crcursor] = [min([s:mxheight, &lines]), getpos('.')]
 	let [s:crbufnr, s:crvisual] = [bufnr('%'), s:lastvisual()]
 	let s:currwin = s:mwbottom ? winnr() : winnr() + has('autocmd')
 	let s:wpmode = exists('b:ctrlp_working_path_mode')
 		\ ? b:ctrlp_working_path_mode : s:pathmode
+	let [s:mrbs, s:crgfile] = [ctrlp#mrufiles#bufs(), expand('<cfile>', 1)]
 endf
 
 fu! s:lastvisual()

File autoload/ctrlp/line.vim

View file
 endf
 " Public {{{1
 fu! ctrlp#line#init()
-	let [bufs, lines] = [filter(ctrlp#buffers(), 'filereadable(v:val)'), []]
-	for each in bufs
-		let [fnamet, ff] = [fnamemodify(each, ':t'), readfile(each)]
-		let bname = fnamemodify(each, ':p')
-		cal map(ff, 'tr(v:val, ''	'', '' '')')
-		let [id, len_ff, bufnr] = [1, len(ff), bufnr('^'.bname.'$')]
-		wh id <= len_ff
-			let ff[id-1] .= '	|'.fnamet.'|'.bufnr.':'.id.'|'
-			let id += 1
+	let [bufs, lines] = [ctrlp#buffers('id'), []]
+	for bufnr in bufs
+		let [lfb, bufn] = [getbufline(bufnr, 1, '$'), bufname(bufnr)]
+		let lfb = lfb == [] ? ctrlp#utils#readfile(fnamemodify(bufn, ':p')) : lfb
+		cal map(lfb, 'tr(v:val, ''	'', '' '')')
+		let [linenr, len_lfb, buft] = [1, len(lfb), fnamemodify(bufn, ':t')]
+		wh linenr <= len_lfb
+			let lfb[linenr - 1] .= '	|'.buft.'|'.bufnr.':'.linenr.'|'
+			let linenr += 1
 		endw
-		cal extend(lines, filter(ff, 'v:val !~ ''^\s*\t|[^|]\+|\d\+:\d\+|$'''))
+		cal extend(lines, filter(lfb, 'v:val !~ ''^\s*\t|[^|]\+|\d\+:\d\+|$'''))
 	endfo
 	cal s:syntax()
 	retu lines

File autoload/ctrlp/mrufiles.vim

View file
 	if empty(bufname) | retu | en
 	let fn = fnamemodify(bufname, ':p')
 	let fn = exists('+ssl') ? tr(fn, '/', '\') : fn
-	cal filter(s:mrbs, 'v:val !='.s:csen.' fn')
-	cal insert(s:mrbs, fn)
+	cal filter(s:mrbs, 'v:val != bufnr')
+	cal insert(s:mrbs, bufnr)
 	if ( !empty(s:in) && fn !~# s:in ) || ( !empty(s:ex) && fn =~# s:ex )
 		\ || !empty(&bt) || !filereadable(fn) | retu
 	en
 	let s:locked = 0
 	aug CtrlPMRUF
 		au!
-		au BufAdd,BufEnter,BufUnload * cal s:record(expand('<abuf>', 1))
+		au BufAdd,BufEnter,BufLeave,BufUnload * cal s:record(expand('<abuf>', 1))
 		au QuickFixCmdPre  *vimgrep* let s:locked = 1
 		au QuickFixCmdPost *vimgrep* let s:locked = 0
 		au VimLeavePre * cal s:savetofile(s:mergelists())

File doc/ctrlp.txt

View file
     \ 'PrtInsert("s")':       ['<F3>'],
     \ 'PrtInsert("v")':       ['<F4>'],
     \ 'PrtInsert("+")':       ['<F6>', '<MiddleMouse>'],
+    \ 'PrtInsert("gf")':      ['<c-\>'],
     \ 'PrtCurStart()':        ['<c-a>'],
     \ 'PrtCurEnd()':          ['<c-e>'],
     \ 'PrtCurLeft()':         ['<c-h>', '<left>', '<c-^>'],