matchit.vim: preserve jumplist (#5124)

This commit is contained in:
Tommy Allen 2016-07-30 12:48:40 -04:00 committed by Justin M. Keyes
parent 9b210c1fa9
commit faca814116

View File

@ -1,7 +1,8 @@
" matchit.vim: (global plugin) Extended "%" matching " matchit.vim: (global plugin) Extended "%" matching
" Last Change: Fri Jan 25 10:00 AM 2008 EST " Last Change: Fri Jul 29 01:20 AM 2016 EST
" Maintainer: Benji Fisher PhD <benji@member.AMS.org> " Maintainer: Benji Fisher PhD <benji@member.AMS.org>
" Version: 1.13.2, for Vim 6.3+ " Version: 1.13.2, for Vim 6.3+
" Fix from Tommy Allen included.
" URL: http://www.vim.org/script.php?script_id=39 " URL: http://www.vim.org/script.php?script_id=39
" Documentation: " Documentation:
@ -254,12 +255,7 @@ function! s:Match_wrapper(word, forward, mode) range
" Fifth step: actually start moving the cursor and call searchpair(). " Fifth step: actually start moving the cursor and call searchpair().
" Later, :execute restore_cursor to get to the original screen. " Later, :execute restore_cursor to get to the original screen.
let restore_cursor = virtcol(".") . "|" let view = winsaveview()
normal! g0
let restore_cursor = line(".") . "G" . virtcol(".") . "|zs" . restore_cursor
normal! H
let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor
execute restore_cursor
call cursor(0, curcol + 1) call cursor(0, curcol + 1)
" normal! 0 " normal! 0
" if curcol " if curcol
@ -273,7 +269,7 @@ function! s:Match_wrapper(word, forward, mode) range
let sp_return = searchpair(ini, mid, fin, flag, skip) let sp_return = searchpair(ini, mid, fin, flag, skip)
let final_position = "call cursor(" . line(".") . "," . col(".") . ")" let final_position = "call cursor(" . line(".") . "," . col(".") . ")"
" Restore cursor position and original screen. " Restore cursor position and original screen.
execute restore_cursor call winrestview(view)
normal! m' normal! m'
if sp_return > 0 if sp_return > 0
execute final_position execute final_position
@ -634,7 +630,7 @@ endfun
" idea to give it its own matching patterns. " idea to give it its own matching patterns.
fun! s:MultiMatch(spflag, mode) fun! s:MultiMatch(spflag, mode)
if !exists("b:match_words") || b:match_words == "" if !exists("b:match_words") || b:match_words == ""
return "" return {}
end end
let restore_options = (&ic ? "" : "no") . "ignorecase" let restore_options = (&ic ? "" : "no") . "ignorecase"
if exists("b:match_ignorecase") if exists("b:match_ignorecase")
@ -694,15 +690,7 @@ fun! s:MultiMatch(spflag, mode)
let skip = 's:comment\|string' let skip = 's:comment\|string'
endif endif
let skip = s:ParseSkip(skip) let skip = s:ParseSkip(skip)
" let restore_cursor = line(".") . "G" . virtcol(".") . "|" let view = winsaveview()
" normal! H
" let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor
let restore_cursor = virtcol(".") . "|"
normal! g0
let restore_cursor = line(".") . "G" . virtcol(".") . "|zs" . restore_cursor
normal! H
let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor
execute restore_cursor
" Third step: call searchpair(). " Third step: call searchpair().
" Replace '\('--but not '\\('--with '\%(' and ',' with '\|'. " Replace '\('--but not '\\('--with '\%(' and ',' with '\|'.
@ -720,14 +708,14 @@ fun! s:MultiMatch(spflag, mode)
while level while level
if searchpair(openpat, '', closepat, a:spflag, skip) < 1 if searchpair(openpat, '', closepat, a:spflag, skip) < 1
call s:CleanUp(restore_options, a:mode, startline, startcol) call s:CleanUp(restore_options, a:mode, startline, startcol)
return "" return {}
endif endif
let level = level - 1 let level = level - 1
endwhile endwhile
" Restore options and return a string to restore the original position. " Restore options and return view dict to restore the original position.
call s:CleanUp(restore_options, a:mode, startline, startcol) call s:CleanUp(restore_options, a:mode, startline, startcol)
return restore_cursor return view
endfun endfun
" Search backwards for "if" or "while" or "<tag>" or ... " Search backwards for "if" or "while" or "<tag>" or ...