Skip to content
Browse files

Save the current cursor position before jumping

Closes #272
  • Loading branch information...
1 parent af66338 commit 32ac8d27cb2809028384a4349e7ed59633b31897 @kien committed Sep 6, 2012
Showing with 30 additions and 19 deletions.
  1. +4 −4 autoload/ctrlp.vim
  2. +18 −4 autoload/ctrlp/buffertag.vim
  3. +8 −11 autoload/ctrlp/quickfix.vim
View
8 autoload/ctrlp.vim
@@ -851,7 +851,7 @@ fu! ctrlp#acceptfile(mode, line, ...)
let [md, filpath] = [a:mode, fnamemodify(a:line, ':p')]
cal s:PrtExit()
let [bufnr, tail] = [bufnr('^'.filpath.'$'), s:tail()]
- let j2l = a:0 ? a:1 : str2nr(matchstr(tail, '^ +\D*\zs\d\+\ze\D*'))
+ let j2l = a:0 ? a:1 : matchstr(tail, '^ +\zs\d\+$')
if ( s:jmptobuf =~ md || ( s:jmptobuf && md =~ '[et]' ) ) && bufnr > 0
\ && !( md == 'e' && bufnr == bufnr('%') )
let [jmpb, bufwinnr] = [1, bufwinnr(bufnr)]
@@ -1707,7 +1707,7 @@ fu! s:strwidth(str)
endf
fu! ctrlp#j2l(nr)
- exe a:nr
+ exe 'norm!' a:nr.'G'
sil! norm! zvzz
endf
@@ -1795,9 +1795,9 @@ fu! s:openfile(cmd, fid, tail, chkmod, ...)
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
+ cal ctrlp#j2l(j2l)
en
- if !empty(a:tail) || j2l
+ if !empty(a:tail)
sil! norm! zvzz
en
if cmd != 'bad'
View
22 autoload/ctrlp/buffertag.vim
@@ -185,8 +185,8 @@ fu! s:process(fname, ftype)
endf
fu! s:parseline(line)
- let eval = '\v^([^\t]+)\t(.+)\t[?/]\^?(.{-1,})\$?[?/]\;\"\t(.+)\tline(no)?\:(\d+)'
- let vals = matchlist(a:line, eval)
+ let vals = matchlist(a:line,
+ \ '\v^([^\t]+)\t(.+)\t[?/]\^?(.{-1,})\$?[?/]\;\"\t(.+)\tline(no)?\:(\d+)')
if vals == [] | retu '' | en
let [bufnr, bufname] = [bufnr('^'.vals[2].'$'), fnamemodify(vals[2], ':p:t')]
retu vals[1].' '.vals[4].'|'.bufnr.':'.bufname.'|'.vals[6].'| '.vals[3]
@@ -218,10 +218,24 @@ fu! ctrlp#buffertag#init(fname)
endf
fu! ctrlp#buffertag#accept(mode, str)
- let vals = matchlist(a:str, '\v^[^\t]+\t+[^\t|]+\|(\d+)\:[^\t|]+\|(\d+)\|')
+ let vals = matchlist(a:str,
+ \ '\v^[^\t]+\t+[^\t|]+\|(\d+)\:[^\t|]+\|(\d+)\|\s(.+)$')
let bufnr = str2nr(get(vals, 1))
if bufnr
- cal ctrlp#acceptfile(a:mode, bufname(bufnr), get(vals, 2))
+ cal ctrlp#acceptfile(a:mode, bufname(bufnr))
+ let pat = get(vals, 3, '')
+ exe 'norm!' str2nr(get(vals, 2, line('.'))).'G'
+ if match(getline('.'), pat) < 0
+ let [int, forw, maxl] = [1, 1, line('$')]
+ wh !search(pat, 'W'.( forw ? '' : 'b' ))
+ if !forw
+ if int > maxl | brea | en
+ let int += int
+ en
+ let forw = !forw
+ endw
+ en
+ sil! norm! zvzz
en
endf
View
19 autoload/ctrlp/quickfix.vim
@@ -40,18 +40,15 @@ fu! ctrlp#quickfix#init()
endf
fu! ctrlp#quickfix#accept(mode, str)
- let items = matchlist(a:str, '^\([^|]\+\ze\)|\(\d\+\):\(\d\+\)|')
- if items == [] | retu | en
- let [md, filpath] = [a:mode, fnamemodify(items[1], ':p')]
- if empty(filpath) | retu | en
- cal ctrlp#exit()
- let cmd = md == 't' ? 'tabe' : md == 'h' ? 'new' : md == 'v' ? 'vne'
- \ : ctrlp#normcmd('e')
- let cmd = cmd == 'e' && ctrlp#modfilecond(1) ? 'new' : cmd
- exe cmd ctrlp#fnesc(filpath)
- cal cursor(items[2], items[3])
+ let vals = matchlist(a:str, '^\([^|]\+\ze\)|\(\d\+\):\(\d\+\)|')
+ if vals == [] || vals[1] == '' | retu | en
+ cal ctrlp#acceptfile(a:mode, vals[1])
+ let cur_pos = getpos('.')[1:2]
+ if cur_pos != [1, 1] && cur_pos != map(vals[2:3], 'str2nr(v:val)')
+ mark '
+ en
+ cal cursor(vals[2], vals[3])
sil! norm! zvzz
- cal ctrlp#setlcdir()
endf
fu! ctrlp#quickfix#id()

0 comments on commit 32ac8d2

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