From cdea7b1b0d871d92b9fe30dcb8a5004f2734a1b8 Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Tue, 20 Dec 2011 18:51:55 -0600 Subject: [PATCH] .vim: matchit.vim v1.13.2 --- .vim/plugin/matchit.vim | 78 +++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/.vim/plugin/matchit.vim b/.vim/plugin/matchit.vim index a2f2050..549c26c 100644 --- a/.vim/plugin/matchit.vim +++ b/.vim/plugin/matchit.vim @@ -1,7 +1,7 @@ " matchit.vim: (global plugin) Extended "%" matching -" Last Change: Sun Feb 26 10:00 AM 2006 EST +" Last Change: Fri Jan 25 10:00 AM 2008 EST " Maintainer: Benji Fisher PhD -" Version: 1.10, for Vim 6.3 +" Version: 1.13.2, for Vim 6.3+ " URL: http://www.vim.org/script.php?script_id=39 " Documentation: @@ -15,7 +15,7 @@ " Support for many languages by Johannes Zellner " Suggestions for improvement, bug reports, and support for additional " languages by Jordi-Albert Batalla, Neil Bird, Servatius Brandt, Mark -" Collett, Stephen Wall, Dany St-Amant, and Johannes Zellner. +" Collett, Stephen Wall, Dany St-Amant, Yuheng Xie, and Johannes Zellner. " Debugging: " If you'd like to try the built-in debugging commands... @@ -42,7 +42,7 @@ if exists("loaded_matchit") || &cp endif let loaded_matchit = 1 let s:last_mps = "" -let s:last_words = "" +let s:last_words = ":" let s:save_cpo = &cpo set cpo&vim @@ -100,13 +100,10 @@ function! s:Match_wrapper(word, forward, mode) range " In s:CleanUp(), we may need to check whether the cursor moved forward. let startline = line(".") let startcol = col(".") - " Use default behavior if called with a count or if no patterns are defined. + " Use default behavior if called with a count. if v:count exe "normal! " . v:count . "%" return s:CleanUp(restore_options, a:mode, startline, startcol) - elseif !exists("b:match_words") || b:match_words == "" - silent! normal! % - return s:CleanUp(restore_options, a:mode, startline, startcol) end " First step: if not already done, set the script variables @@ -114,8 +111,10 @@ function! s:Match_wrapper(word, forward, mode) range " s:pat parsed version of b:match_words " s:all regexp based on s:pat and the default groups " - " Allow b:match_words = "GetVimMatchWords()" . - if b:match_words =~ ":" + if !exists("b:match_words") || b:match_words == "" + let match_words = "" + " Allow b:match_words = "GetVimMatchWords()" . + elseif b:match_words =~ ":" let match_words = b:match_words else execute "let match_words =" b:match_words @@ -125,13 +124,6 @@ function! s:Match_wrapper(word, forward, mode) range \ exists("b:match_debug") let s:last_words = match_words let s:last_mps = &mps - if match_words !~ s:notslash . '\\\d' - let s:do_BR = 0 - let s:pat = match_words - else - let s:do_BR = 1 - let s:pat = s:ParseWords(match_words) - endif " The next several lines were here before " BF started messing with this script. " quote the special chars in 'matchpairs', replace [,:] with \| and then @@ -141,8 +133,15 @@ function! s:Match_wrapper(word, forward, mode) range let default = escape(&mps, '[$^.*~\\/?]') . (strlen(&mps) ? "," : "") . \ '\/\*:\*\/,#if\%(def\)\=:#else\>:#elif\>:#endif\>' " s:all = pattern with all the keywords - let s:all = s:pat . (strlen(s:pat) ? "," : "") . default - let s:all = substitute(s:all, s:notslash . '\zs[,:]\+', '\\|', 'g') + let match_words = match_words . (strlen(match_words) ? "," : "") . default + if match_words !~ s:notslash . '\\\d' + let s:do_BR = 0 + let s:pat = match_words + else + let s:do_BR = 1 + let s:pat = s:ParseWords(match_words) + endif + let s:all = substitute(s:pat, s:notslash . '\zs[,:]\+', '\\|', 'g') let s:all = '\%(' . s:all . '\)' " let s:all = '\%(' . substitute(s:all, '\\\ze[,:]', '', 'g') . '\)' if exists("b:match_debug") @@ -172,15 +171,14 @@ function! s:Match_wrapper(word, forward, mode) range else " Find the match that ends on or after the cursor and set curcol. let regexp = s:Wholematch(matchline, s:all, startcol-1) let curcol = match(matchline, regexp) - let suf = strlen(matchline) - matchend(matchline, regexp) - let prefix = (curcol ? '^.\{' . curcol . '}\%(' : '^\%(') - let suffix = (suf ? '\).\{' . suf . '}$' : '\)$') - " If the match comes from the defaults, bail out. - if matchline !~ prefix . - \ substitute(s:pat, s:notslash.'\zs[,:]\+', '\\|', 'g') . suffix - silent! norm! % + " If there is no match, give up. + if curcol == -1 return s:CleanUp(restore_options, a:mode, startline, startcol) endif + let endcol = matchend(matchline, regexp) + let suf = strlen(matchline) - endcol + let prefix = (curcol ? '^.*\%' . (curcol + 1) . 'c\%(' : '^\%(') + let suffix = (suf ? '\)\%' . (endcol + 1) . 'c.*$' : '\)$') endif if exists("b:match_debug") let b:match_match = matchstr(matchline, regexp) @@ -262,10 +260,11 @@ function! s:Match_wrapper(word, forward, mode) range normal! H let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor execute restore_cursor - normal! 0 - if curcol - execute "normal!" . curcol . "l" - endif + call cursor(0, curcol + 1) + " normal! 0 + " if curcol + " execute "normal!" . curcol . "l" + " endif if skip =~ 'synID' && !(has("syntax") && exists("g:syntax_on")) let skip = "0" else @@ -358,7 +357,7 @@ fun! s:InsertRefs(groupBR, prefix, group, suffix, matchline) execute s:Ref(ini, d, "start", "len") let ini = strpart(ini, 0, start) . backref . strpart(ini, start+len) let tailBR = substitute(tailBR, s:notslash . '\zs\\' . d, - \ escape(backref, '\\'), 'g') + \ escape(backref, '\\&'), 'g') endif let d = d-1 endwhile @@ -399,6 +398,7 @@ fun! s:ParseWords(groups) endwhile " Now, tail has been used up. let parsed = parsed . "," endwhile " groups =~ '[^,:]' + let parsed = substitute(parsed, ',$', '', '') return parsed endfun @@ -415,9 +415,9 @@ endfun " let match = matchstr(getline("."), regexp) fun! s:Wholematch(string, pat, start) let group = '\%(' . a:pat . '\)' - let prefix = (a:start ? '\(^.\{,' . a:start . '}\)\zs' : '^') + let prefix = (a:start ? '\(^.*\%<' . (a:start + 2) . 'c\)\zs' : '^') let len = strlen(a:string) - let suffix = (a:start+1 < len ? '\(.\{,'.(len-a:start-1).'}$\)\@=' : '$') + let suffix = (a:start+1 < len ? '\(\%>'.(a:start+1).'c.*$\)\@=' : '$') if a:string !~ prefix . group . suffix let prefix = '' endif @@ -649,7 +649,7 @@ fun! s:MultiMatch(spflag, mode) " s:all regexp based on s:pat and the default groups " This part is copied and slightly modified from s:Match_wrapper(). let default = escape(&mps, '[$^.*~\\/?]') . (strlen(&mps) ? "," : "") . - \ '\/\*:\*\/,#if\%(def\)\=:$else\>:#elif\>:#endif\>' + \ '\/\*:\*\/,#if\%(def\)\=:#else\>:#elif\>:#endif\>' " Allow b:match_words = "GetVimMatchWords()" . if b:match_words =~ ":" let match_words = b:match_words @@ -680,10 +680,12 @@ fun! s:MultiMatch(spflag, mode) " - maybe even more functionality should be split off " - into separate functions! let cdefault = (s:pat =~ '[^,]$' ? "," : "") . default - let open = substitute(s:pat . cdefault, ':[^,]*,', '\\),\\(', 'g') - let open = '\(' . substitute(open, ':[^,]*$', '\\)', '') - let close = substitute(s:pat . cdefault, ',[^,]*:', '\\),\\(', 'g') - let close = substitute(close, '[^,]*:', '\\(', '') . '\)' + let open = substitute(s:pat . cdefault, + \ s:notslash . '\zs:.\{-}' . s:notslash . ',', '\\),\\(', 'g') + let open = '\(' . substitute(open, s:notslash . '\zs:.*$', '\\)', '') + let close = substitute(s:pat . cdefault, + \ s:notslash . '\zs,.\{-}' . s:notslash . ':', '\\),\\(', 'g') + let close = substitute(close, '^.\{-}' . s:notslash . ':', '\\(', '') . '\)' if exists("b:match_skip") let skip = b:match_skip elseif exists("b:match_comment") " backwards compatibility and testing! -- 2.43.0