-" Find backwards the closest open parenthesis/bracket/brace.
-function! s:SearchParensPair()
- let line = line('.')
- let col = col('.')
-
- " Skip strings and comments and don't look too far
- let skip = "line('.') < " . (line - s:maxoff) . " ? dummy :" .
- \ 'synIDattr(synID(line("."), col("."), 0), "name") =~? ' .
- \ '"string\\|comment"'
-
- " Search for parentheses
- call cursor(line, col)
- let parlnum = searchpair('(', '', ')', 'bW', skip)
- let parcol = col('.')
-
- " Search for brackets
- call cursor(line, col)
- let par2lnum = searchpair('\[', '', '\]', 'bW', skip)
- let par2col = col('.')
-
- " Search for braces
- call cursor(line, col)
- let par3lnum = searchpair('{', '', '}', 'bW', skip)
- let par3col = col('.')
-
- " Get the closest match
- if par2lnum > parlnum || (par2lnum == parlnum && par2col > parcol)
- let parlnum = par2lnum
- let parcol = par2col
- endif
- if par3lnum > parlnum || (par3lnum == parlnum && par3col > parcol)
- let parlnum = par3lnum
- let parcol = par3col
+" Skip strings and comments
+let s:skip_special_chars = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
+ \ '=~? "string\\|comment"'
+
+let s:skip_search = 'synIDattr(synID(line("."), col("."), 0), "name") ' .
+ \ '=~? "comment"'
+
+" compatibility with vim patch 7.3.629: 'sw' can be set to -1 to follow 'ts'
+if exists('*shiftwidth')
+ function! s:sw()
+ return shiftwidth()
+ endfunction
+else
+ function! s:sw()
+ return &sw
+ endfunction
+endif
+
+function! s:pair_sort(x, y)
+ if a:x[0] == a:y[0]
+ return a:x[1] == a:y[1] ? 0 : a:x[1] > a:y[1] ? 1 : -1
+ else
+ return a:x[0] > a:y[0] ? 1 : -1