Skip to content

Commit

Permalink
Update matchit plugin to 1.13.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
convissor committed Mar 3, 2014
1 parent 82df441 commit 5f831e5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 52 deletions.
32 changes: 17 additions & 15 deletions .vim/doc/matchit.txt
Expand Up @@ -4,7 +4,7 @@ For instructions on installing this file, type
:help matchit-install
inside Vim.

For Vim version 6.3. Last change: 2006 Feb 23
For Vim version 6.3. Last change: 2007 Aug 29


VIM REFERENCE MANUAL by Benji Fisher
Expand Down Expand Up @@ -34,7 +34,7 @@ in your |vimrc| file: >

*g%* *v_g%* *o_g%*
g% Cycle backwards through matching groups, as specified by
|b:match_words|. For example, go from "endif" to "else" to "if".
|b:match_words|. For example, go from "if" to "endif" to "else".

*[%* *v_[%* *o_[%*
[% Go to [count] previous unmatched group, as specified by
Expand Down Expand Up @@ -64,9 +64,9 @@ option. The matchit plugin extends this in several ways:
By default, words inside comments and strings are ignored, unless
the cursor is inside a comment or string when you type "%". If the
only thing you want to do is modify the behavior of "%" so that it
behaves this way, you can >
:let b:match_words = &matchpairs
<
behaves this way, you do not have to define |b:match_words|, since the
script uses the 'matchpairs' option as well as this variable.

See |matchit-details| for details on what the script does, and |b:match_words|
for how to specify matching patterns.

Expand All @@ -84,7 +84,7 @@ LANGUAGES: *matchit-languages*
Currently, the following languages are supported: Ada, ASP with VBS, Csh,
DTD, Entity, Essbase, Fortran, HTML, JSP (same as HTML), LaTeX, Lua, Pascal,
SGML, Shell, Tcsh, Vim, XML. Other languages may already have support via
|filetype-plugin|s.
the default |filetype-plugin|s in the standard vim distribution.

To support a new language, see |matchit-newlang| below.

Expand All @@ -109,7 +109,6 @@ The script follows these rules:
Prefer a match that includes the cursor position (that is, one that
starts on or before the cursor).
Prefer a match that starts as close to the cursor as possible.
Prefer a match in |b:match_words| to a match in 'matchpairs'.
If more than one pattern in |b:match_words| matches, choose the one
that is listed first.

Expand All @@ -131,9 +130,10 @@ Examples:
cursor starts on the "end " then "end if" is chosen. (You can avoid
this problem by using a more complicated pattern.)

If there is no match, the script falls back on the usual behavior of |%|. If
debugging is turned on, the matched bit of text is saved as |b:match_match|
and the cursor column of the start of the match is saved as |b:match_col|.
If there is no match, the cursor does not move. (Before version 1.13 of the
script, it would fall back on the usual behavior of |%|). If debugging is
turned on, the matched bit of text is saved as |b:match_match| and the cursor
column of the start of the match is saved as |b:match_col|.

Next, the script looks through |b:match_words| (original and parsed versions)
for the group and pattern that match. If debugging is turned on, the group is
Expand All @@ -160,11 +160,13 @@ or >
:runtime macros/matchit.vim
Either way, the script should start working the next time you start up Vim.

The script does nothing unless it finds a |buffer-variable| named
|b:match_words|. The script contains autocommands that set this variable for
various file types: see |matchit-languages| above. For a new language, you
can add autocommands to the script or to your vimrc file, but the recommended
method is to add a line such as >
(Earlier versions of the script did nothing unless a |buffer-variable| named
|b:match_words| was defined. Even earlier versions contained autocommands
that set this variable for various file types. Now, |b:match_words| is
defined in many of the default |filetype-plugin|s instead.)

For a new language, you can add autocommands to the script or to your vimrc
file, but the recommended method is to add a line such as >
let b:match_words = '\<foo\>:\<bar\>'
to the |filetype-plugin| for your language. See |b:match_words| below for how
this variable is interpreted.
Expand Down
76 changes: 39 additions & 37 deletions .vim/plugin/matchit.vim 100644 → 100755
@@ -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 <benji@member.AMS.org>
" 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:
Expand All @@ -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...
Expand All @@ -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
Expand Down Expand Up @@ -100,22 +100,21 @@ 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
" s:do_BR flag for whether there are backrefs
" 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
Expand All @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down
1 change: 1 addition & 0 deletions README.txt
Expand Up @@ -16,6 +16,7 @@ annotated in the sources using ":CONVISSOR:". My adjustments are:
* Include Karl Guertin's autoclose plugin.
* Include my ctags_for_svn plugin.
* Updated the taglist plugin to 4.6.
* Updated the matchit plugin to 1.13.2.

I've also included an install script, "setup.sh", to create the symlinks
from ~/.vim and ~/.vimrc to those elements in this repository.
Expand Down

0 comments on commit 5f831e5

Please sign in to comment.