annotate runtime/macros/matchit.vim @ 837:6bb1fa855dc9 v7.0e03

updated for version 7.0e03
author vimboss
date Wed, 19 Apr 2006 21:23:36 +0000
parents d8f905020502
children 96cd8222a819
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " matchit.vim: (global plugin) Extended "%" matching
800
d8f905020502 updated for version 7.0b
vimboss
parents: 7
diff changeset
2 " Last Change: Sun Feb 26 10:00 AM 2006 EST
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Maintainer: Benji Fisher PhD <benji@member.AMS.org>
800
d8f905020502 updated for version 7.0b
vimboss
parents: 7
diff changeset
4 " Version: 1.10, for Vim 6.3
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 " URL: http://www.vim.org/script.php?script_id=39
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 " Documentation:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 " The documentation is in a separate file, matchit.txt .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 " Credits:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 " Vim editor by Bram Moolenaar (Thanks, Bram!)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 " Original script and design by Raul Segura Acevedo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 " Support for comments by Douglas Potts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 " Support for back references and other improvements by Benji Fisher
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 " Support for many languages by Johannes Zellner
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 " Suggestions for improvement, bug reports, and support for additional
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 " languages by Jordi-Albert Batalla, Neil Bird, Servatius Brandt, Mark
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 " Collett, Stephen Wall, Dany St-Amant, and Johannes Zellner.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 " Debugging:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 " If you'd like to try the built-in debugging commands...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 " :MatchDebug to activate debugging for the current buffer
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 " This saves the values of several key script variables as buffer-local
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 " variables. See the MatchDebug() function, below, for details.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 " TODO: I should think about multi-line patterns for b:match_words.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 " This would require an option: how many lines to scan (default 1).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 " This would be useful for Python, maybe also for *ML.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 " TODO: Maybe I should add a menu so that people will actually use some of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 " the features that I have implemented.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 " TODO: Eliminate the MultiMatch function. Add yet another argument to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 " Match_wrapper() instead.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 " TODO: Allow :let b:match_words = '\(\(foo\)\(bar\)\):\3\2:end\1'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 " TODO: Make backrefs safer by using '\V' (very no-magic).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 " TODO: Add a level of indirection, so that custom % scripts can use my
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 " work but extend it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 " allow user to prevent loading
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 " and prevent duplicate loading
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 if exists("loaded_matchit") || &cp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 let loaded_matchit = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 let s:last_mps = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 let s:last_words = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 let s:save_cpo = &cpo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 set cpo&vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 nnoremap <silent> % :<C-U>call <SID>Match_wrapper('',1,'n') <CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 nnoremap <silent> g% :<C-U>call <SID>Match_wrapper('',0,'n') <CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 vnoremap <silent> % :<C-U>call <SID>Match_wrapper('',1,'v') <CR>m'gv``
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 vnoremap <silent> g% :<C-U>call <SID>Match_wrapper('',0,'v') <CR>m'gv``
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 onoremap <silent> % v:<C-U>call <SID>Match_wrapper('',1,'o') <CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 onoremap <silent> g% v:<C-U>call <SID>Match_wrapper('',0,'o') <CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 " Analogues of [{ and ]} using matching patterns:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 nnoremap <silent> [% :<C-U>call <SID>MultiMatch("bW", "n") <CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 nnoremap <silent> ]% :<C-U>call <SID>MultiMatch("W", "n") <CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 vmap [% <Esc>[%m'gv``
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 vmap ]% <Esc>]%m'gv``
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 " vnoremap <silent> [% :<C-U>call <SID>MultiMatch("bW", "v") <CR>m'gv``
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 " vnoremap <silent> ]% :<C-U>call <SID>MultiMatch("W", "v") <CR>m'gv``
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 onoremap <silent> [% v:<C-U>call <SID>MultiMatch("bW", "o") <CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 onoremap <silent> ]% v:<C-U>call <SID>MultiMatch("W", "o") <CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 " text object:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 vmap a% <Esc>[%v]%
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 " Auto-complete mappings: (not yet "ready for prime time")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 " TODO Read :help write-plugin for the "right" way to let the user
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 " specify a key binding.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 " let g:match_auto = '<C-]>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 " let g:match_autoCR = '<C-CR>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 " if exists("g:match_auto")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 " execute "inoremap " . g:match_auto . ' x<Esc>"=<SID>Autocomplete()<CR>Pls'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 " endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 " if exists("g:match_autoCR")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 " execute "inoremap " . g:match_autoCR . ' <CR><C-R>=<SID>Autocomplete()<CR>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 " endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 " if exists("g:match_gthhoh")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 " execute "inoremap " . g:match_gthhoh . ' <C-O>:call <SID>Gthhoh()<CR>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 " endif " gthhoh = "Get the heck out of here!"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 let s:notslash = '\\\@<!\%(\\\\\)*'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 function! s:Match_wrapper(word, forward, mode) range
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 " In s:CleanUp(), :execute "set" restore_options .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 let restore_options = (&ic ? " " : " no") . "ignorecase"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 if exists("b:match_ignorecase")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 let &ignorecase = b:match_ignorecase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 let restore_options = " ve=" . &ve . restore_options
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 set ve=
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 " If this function was called from Visual mode, make sure that the cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 " is at the correct end of the Visual range:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 if a:mode == "v"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 execute "normal! gv\<Esc>"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 " In s:CleanUp(), we may need to check whether the cursor moved forward.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 let startline = line(".")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 let startcol = col(".")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 " Use default behavior if called with a count or if no patterns are defined.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 if v:count
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105 exe "normal! " . v:count . "%"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 return s:CleanUp(restore_options, a:mode, startline, startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 elseif !exists("b:match_words") || b:match_words == ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108 silent! normal! %
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 return s:CleanUp(restore_options, a:mode, startline, startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 " First step: if not already done, set the script variables
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 " s:do_BR flag for whether there are backrefs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 " s:pat parsed version of b:match_words
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115 " s:all regexp based on s:pat and the default groups
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 " Allow b:match_words = "GetVimMatchWords()" .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 if b:match_words =~ ":"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 let match_words = b:match_words
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 execute "let match_words =" b:match_words
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 " Thanks to Preben "Peppe" Guldberg and Bram Moolenaar for this suggestion!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 if (match_words != s:last_words) || (&mps != s:last_mps) ||
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 \ exists("b:match_debug")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 let s:last_words = match_words
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 let s:last_mps = &mps
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 if match_words !~ s:notslash . '\\\d'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 let s:do_BR = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 let s:pat = match_words
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 let s:do_BR = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 let s:pat = s:ParseWords(match_words)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 " The next several lines were here before
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 " BF started messing with this script.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 " quote the special chars in 'matchpairs', replace [,:] with \| and then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 " append the builtin pairs (/*, */, #if, #ifdef, #else, #elif, #endif)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 " let default = substitute(escape(&mps, '[$^.*~\\/?]'), '[,:]\+',
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 " \ '\\|', 'g').'\|\/\*\|\*\/\|#if\>\|#ifdef\>\|#else\>\|#elif\>\|#endif\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 let default = escape(&mps, '[$^.*~\\/?]') . (strlen(&mps) ? "," : "") .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 \ '\/\*:\*\/,#if\%(def\)\=:#else\>:#elif\>:#endif\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 " s:all = pattern with all the keywords
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 let s:all = s:pat . (strlen(s:pat) ? "," : "") . default
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 let s:all = substitute(s:all, s:notslash . '\zs[,:]\+', '\\|', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 let s:all = '\%(' . s:all . '\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 " let s:all = '\%(' . substitute(s:all, '\\\ze[,:]', '', 'g') . '\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 if exists("b:match_debug")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 let b:match_pat = s:pat
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 " Second step: set the following local variables:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 " matchline = line on which the cursor started
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 " curcol = number of characters before match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 " prefix = regexp for start of line to start of match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 " suffix = regexp for end of match to end of line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 " Require match to end on or after the cursor and prefer it to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 " start on or before the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 let matchline = getline(startline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 if a:word != ''
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 " word given
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 if a:word !~ s:all
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 echohl WarningMsg|echo 'Missing rule for word:"'.a:word.'"'|echohl NONE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 return s:CleanUp(restore_options, a:mode, startline, startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 let matchline = a:word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 let curcol = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 let prefix = '^\%('
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 let suffix = '\)$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 " Now the case when "word" is not given
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 else " Find the match that ends on or after the cursor and set curcol.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 let regexp = s:Wholematch(matchline, s:all, startcol-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 let curcol = match(matchline, regexp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 let suf = strlen(matchline) - matchend(matchline, regexp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 let prefix = (curcol ? '^.\{' . curcol . '}\%(' : '^\%(')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 let suffix = (suf ? '\).\{' . suf . '}$' : '\)$')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 " If the match comes from the defaults, bail out.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 if matchline !~ prefix .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 \ substitute(s:pat, s:notslash.'\zs[,:]\+', '\\|', 'g') . suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 silent! norm! %
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 return s:CleanUp(restore_options, a:mode, startline, startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 if exists("b:match_debug")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 let b:match_match = matchstr(matchline, regexp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 let b:match_col = curcol+1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 " Third step: Find the group and single word that match, and the original
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 " (backref) versions of these. Then, resolve the backrefs.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 " Set the following local variable:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 " group = colon-separated list of patterns, one of which matches
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 " = ini:mid:fin or ini:fin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 " Reconstruct the version with unresolved backrefs.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 let patBR = substitute(match_words.',',
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 \ s:notslash.'\zs[,:]*,[,:]*', ',', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 let patBR = substitute(patBR, s:notslash.'\zs:\{2,}', ':', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 " Now, set group and groupBR to the matching group: 'if:endif' or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 " 'while:endwhile' or whatever. A bit of a kluge: s:Choose() returns
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 " group . "," . groupBR, and we pick it apart.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 let group = s:Choose(s:pat, matchline, ",", ":", prefix, suffix, patBR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 let i = matchend(group, s:notslash . ",")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 let groupBR = strpart(group, i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 let group = strpart(group, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 " Now, matchline =~ prefix . substitute(group,':','\|','g') . suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 if s:do_BR " Do the hard part: resolve those backrefs!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 let group = s:InsertRefs(groupBR, prefix, group, suffix, matchline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 if exists("b:match_debug")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 let b:match_wholeBR = groupBR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 let i = matchend(groupBR, s:notslash . ":")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 let b:match_iniBR = strpart(groupBR, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 " Fourth step: Set the arguments for searchpair().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 let i = matchend(group, s:notslash . ":")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 let j = matchend(group, '.*' . s:notslash . ":")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 let ini = strpart(group, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 let mid = substitute(strpart(group, i,j-i-1), s:notslash.'\zs:', '\\|', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 let fin = strpart(group, j)
800
d8f905020502 updated for version 7.0b
vimboss
parents: 7
diff changeset
223 "Un-escape the remaining , and : characters.
d8f905020502 updated for version 7.0b
vimboss
parents: 7
diff changeset
224 let ini = substitute(ini, s:notslash . '\zs\\\(:\|,\)', '\1', 'g')
d8f905020502 updated for version 7.0b
vimboss
parents: 7
diff changeset
225 let mid = substitute(mid, s:notslash . '\zs\\\(:\|,\)', '\1', 'g')
d8f905020502 updated for version 7.0b
vimboss
parents: 7
diff changeset
226 let fin = substitute(fin, s:notslash . '\zs\\\(:\|,\)', '\1', 'g')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 " searchpair() requires that these patterns avoid \(\) groups.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 let ini = substitute(ini, s:notslash . '\zs\\(', '\\%(', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 let mid = substitute(mid, s:notslash . '\zs\\(', '\\%(', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 let fin = substitute(fin, s:notslash . '\zs\\(', '\\%(', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 " Set mid. This is optimized for readability, not micro-efficiency!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 if a:forward && matchline =~ prefix . fin . suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 \ || !a:forward && matchline =~ prefix . ini . suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 let mid = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 " Set flag. This is optimized for readability, not micro-efficiency!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 if a:forward && matchline =~ prefix . fin . suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 \ || !a:forward && matchline !~ prefix . ini . suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 let flag = "bW"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 let flag = "W"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 " Set skip.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 if exists("b:match_skip")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 let skip = b:match_skip
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 elseif exists("b:match_comment") " backwards compatibility and testing!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 let skip = "r:" . b:match_comment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 let skip = 's:comment\|string'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 let skip = s:ParseSkip(skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 if exists("b:match_debug")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 let b:match_ini = ini
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 let b:match_tail = (strlen(mid) ? mid.'\|' : '') . fin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 " Fifth step: actually start moving the cursor and call searchpair().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 " Later, :execute restore_cursor to get to the original screen.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 let restore_cursor = virtcol(".") . "|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 normal! g0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 let restore_cursor = line(".") . "G" . virtcol(".") . "|zs" . restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 normal! H
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 execute restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 normal! 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 if curcol
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 execute "normal!" . curcol . "l"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 if skip =~ 'synID' && !(has("syntax") && exists("g:syntax_on"))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 let skip = "0"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 execute "if " . skip . "| let skip = '0' | endif"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 let sp_return = searchpair(ini, mid, fin, flag, skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 let final_position = "call cursor(" . line(".") . "," . col(".") . ")"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 " Restore cursor position and original screen.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 execute restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 normal! m'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 if sp_return > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 execute final_position
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 return s:CleanUp(restore_options, a:mode, startline, startcol, mid.'\|'.fin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 " Restore options and do some special handling for Operator-pending mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 " The optional argument is the tail of the matching group.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 fun! s:CleanUp(options, mode, startline, startcol, ...)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 execute "set" a:options
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 " Open folds, if appropriate.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 if a:mode != "o"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 if &foldopen =~ "percent"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 normal! zv
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 " In Operator-pending mode, we want to include the whole match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 " (for example, d%).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 " This is only a problem if we end up moving in the forward direction.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 elseif (a:startline < line(".")) ||
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 \ (a:startline == line(".") && a:startcol < col("."))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 if a:0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 " Check whether the match is a single character. If not, move to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 " end of the match.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 let matchline = getline(".")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 let currcol = col(".")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 let regexp = s:Wholematch(matchline, a:1, currcol-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 let endcol = matchend(matchline, regexp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 if endcol > currcol " This is NOT off by one!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 execute "normal!" . (endcol - currcol) . "l"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 endif " a:0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 endif " a:mode != "o" && etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 " Example (simplified HTML patterns): if
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 " a:groupBR = '<\(\k\+\)>:</\1>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 " a:prefix = '^.\{3}\('
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 " a:group = '<\(\k\+\)>:</\(\k\+\)>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 " a:suffix = '\).\{2}$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 " a:matchline = "123<tag>12" or "123</tag>12"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 " then extract "tag" from a:matchline and return "<tag>:</tag>" .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 fun! s:InsertRefs(groupBR, prefix, group, suffix, matchline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 if a:matchline !~ a:prefix .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 \ substitute(a:group, s:notslash . '\zs:', '\\|', 'g') . a:suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 return a:group
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 let i = matchend(a:groupBR, s:notslash . ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 let ini = strpart(a:groupBR, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 let tailBR = strpart(a:groupBR, i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 let word = s:Choose(a:group, a:matchline, ":", "", a:prefix, a:suffix,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 \ a:groupBR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 let i = matchend(word, s:notslash . ":")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 let wordBR = strpart(word, i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 let word = strpart(word, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 " Now, a:matchline =~ a:prefix . word . a:suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 if wordBR != ini
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 let table = s:Resolve(ini, wordBR, "table")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 " let table = "----------"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 let table = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 let d = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 while d < 10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 if tailBR =~ s:notslash . '\\' . d
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 " let table[d] = d
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 let table = table . d
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 let table = table . "-"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 let d = d + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 let d = 9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 while d
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 if table[d] != "-"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 let backref = substitute(a:matchline, a:prefix.word.a:suffix,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 \ '\'.table[d], "")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 " Are there any other characters that should be escaped?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 let backref = escape(backref, '*,:')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 execute s:Ref(ini, d, "start", "len")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 let ini = strpart(ini, 0, start) . backref . strpart(ini, start+len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 let tailBR = substitute(tailBR, s:notslash . '\zs\\' . d,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 \ escape(backref, '\\'), 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 let d = d-1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 if exists("b:match_debug")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 if s:do_BR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 let b:match_table = table
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 let b:match_word = word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 let b:match_table = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 let b:match_word = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 return ini . ":" . tailBR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 " Input a comma-separated list of groups with backrefs, such as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 " a:groups = '\(foo\):end\1,\(bar\):end\1'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 " and return a comma-separated list of groups with backrefs replaced:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 " return '\(foo\):end\(foo\),\(bar\):end\(bar\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 fun! s:ParseWords(groups)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 let groups = substitute(a:groups.",", s:notslash.'\zs[,:]*,[,:]*', ',', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 let groups = substitute(groups, s:notslash . '\zs:\{2,}', ':', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 let parsed = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 while groups =~ '[^,:]'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 let i = matchend(groups, s:notslash . ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 let j = matchend(groups, s:notslash . ',')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 let ini = strpart(groups, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 let tail = strpart(groups, i, j-i-1) . ":"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 let groups = strpart(groups, j)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 let parsed = parsed . ini
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 let i = matchend(tail, s:notslash . ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 while i != -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 " In 'if:else:endif', ini='if' and word='else' and then word='endif'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 let word = strpart(tail, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 let tail = strpart(tail, i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 let i = matchend(tail, s:notslash . ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 let parsed = parsed . ":" . s:Resolve(ini, word, "word")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 endwhile " Now, tail has been used up.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 let parsed = parsed . ","
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401 endwhile " groups =~ '[^,:]'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 return parsed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 " TODO I think this can be simplified and/or made more efficient.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 " TODO What should I do if a:start is out of range?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
407 " Return a regexp that matches all of a:string, such that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 " matchstr(a:string, regexp) represents the match for a:pat that starts
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 " as close to a:start as possible, before being preferred to after, and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 " ends after a:start .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 " Usage:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 " let regexp = s:Wholematch(getline("."), 'foo\|bar', col(".")-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 " let i = match(getline("."), regexp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 " let j = matchend(getline("."), regexp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 " let match = matchstr(getline("."), regexp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 fun! s:Wholematch(string, pat, start)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 let group = '\%(' . a:pat . '\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 let prefix = (a:start ? '\(^.\{,' . a:start . '}\)\zs' : '^')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 let len = strlen(a:string)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 let suffix = (a:start+1 < len ? '\(.\{,'.(len-a:start-1).'}$\)\@=' : '$')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421 if a:string !~ prefix . group . suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 let prefix = ''
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 return prefix . group . suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 " No extra arguments: s:Ref(string, d) will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 " find the d'th occurrence of '\(' and return it, along with everything up
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429 " to and including the matching '\)'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 " One argument: s:Ref(string, d, "start") returns the index of the start
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 " of the d'th '\(' and any other argument returns the length of the group.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432 " Two arguments: s:Ref(string, d, "foo", "bar") returns a string to be
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 " executed, having the effect of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 " :let foo = s:Ref(string, d, "start")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 " :let bar = s:Ref(string, d, "len")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 fun! s:Ref(string, d, ...)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 let len = strlen(a:string)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438 if a:d == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 let start = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 let cnt = a:d
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 let match = a:string
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 while cnt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 let cnt = cnt - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 let index = matchend(match, s:notslash . '\\(')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 if index == -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 return ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 let match = strpart(match, index)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 let start = len - strlen(match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 if a:0 == 1 && a:1 == "start"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 return start - 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 let cnt = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 while cnt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 let index = matchend(match, s:notslash . '\\(\|\\)') - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 if index == -2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 return ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 " Increment if an open, decrement if a ')':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 let cnt = cnt + (match[index]=="(" ? 1 : -1) " ')'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 " let cnt = stridx('0(', match[index]) + cnt
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 let match = strpart(match, index+1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 let start = start - 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 let len = len - start - strlen(match)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 if a:0 == 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 return len
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 elseif a:0 == 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 return "let " . a:1 . "=" . start . "| let " . a:2 . "=" . len
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 return strpart(a:string, start, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 " Count the number of disjoint copies of pattern in string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 " If the pattern is a literal string and contains no '0' or '1' characters
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 " then s:Count(string, pattern, '0', '1') should be faster than
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 " s:Count(string, pattern).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 fun! s:Count(string, pattern, ...)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 let pat = escape(a:pattern, '\\')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 if a:0 > 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 let foo = substitute(a:string, '[^'.a:pattern.']', "a:1", "g")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 let foo = substitute(a:string, pat, a:2, "g")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 let foo = substitute(foo, '[^' . a:2 . ']', "", "g")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 return strlen(foo)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 let result = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 let foo = a:string
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 let index = matchend(foo, pat)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 while index != -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 let result = result + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 let foo = strpart(foo, index)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 let index = matchend(foo, pat)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 return result
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 " s:Resolve('\(a\)\(b\)', '\(c\)\2\1\1\2') should return table.word, where
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 " word = '\(c\)\(b\)\(a\)\3\2' and table = '-32-------'. That is, the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 " '\1' in target is replaced by '\(a\)' in word, table[1] = 3, and this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 " indicates that all other instances of '\1' in target are to be replaced
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505 " by '\3'. The hard part is dealing with nesting...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 " Note that ":" is an illegal character for source and target,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 " unless it is preceded by "\".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508 fun! s:Resolve(source, target, output)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 let word = a:target
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 let i = matchend(word, s:notslash . '\\\d') - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 let table = "----------"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 while i != -2 " There are back references to be replaced.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513 let d = word[i]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 let backref = s:Ref(a:source, d)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 " The idea is to replace '\d' with backref. Before we do this,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
516 " replace any \(\) groups in backref with :1, :2, ... if they
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 " correspond to the first, second, ... group already inserted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518 " into backref. Later, replace :1 with \1 and so on. The group
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 " number w+b within backref corresponds to the group number
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 " s within a:source.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 " w = number of '\(' in word before the current one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 let w = s:Count(
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 \ substitute(strpart(word, 0, i-1), '\\\\', '', 'g'), '\(', '1')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 let b = 1 " number of the current '\(' in backref
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 let s = d " number of the current '\(' in a:source
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 while b <= s:Count(substitute(backref, '\\\\', '', 'g'), '\(', '1')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 \ && s < 10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 if table[s] == "-"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 if w + b < 10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 " let table[s] = w + b
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 let table = strpart(table, 0, s) . (w+b) . strpart(table, s+1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 let b = b + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 let s = s + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
536 execute s:Ref(backref, b, "start", "len")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 let ref = strpart(backref, start, len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
538 let backref = strpart(backref, 0, start) . ":". table[s]
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
539 \ . strpart(backref, start+len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
540 let s = s + s:Count(substitute(ref, '\\\\', '', 'g'), '\(', '1')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
541 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 let word = strpart(word, 0, i-1) . backref . strpart(word, i+1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544 let i = matchend(word, s:notslash . '\\\d') - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
545 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 let word = substitute(word, s:notslash . '\zs:', '\\', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 if a:output == "table"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548 return table
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
549 elseif a:output == "word"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 return word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552 return table . word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556 " Assume a:comma = ",". Then the format for a:patterns and a:1 is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 " a:patterns = "<pat1>,<pat2>,..."
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 " a:1 = "<alt1>,<alt2>,..."
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559 " If <patn> is the first pattern that matches a:string then return <patn>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 " if no optional arguments are given; return <patn>,<altn> if a:1 is given.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 fun! s:Choose(patterns, string, comma, branch, prefix, suffix, ...)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 let tail = (a:patterns =~ a:comma."$" ? a:patterns : a:patterns . a:comma)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563 let i = matchend(tail, s:notslash . a:comma)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 if a:0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 let alttail = (a:1 =~ a:comma."$" ? a:1 : a:1 . a:comma)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 let j = matchend(alttail, s:notslash . a:comma)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
567 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 let current = strpart(tail, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 if a:branch == ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 let currpat = current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 else
800
d8f905020502 updated for version 7.0b
vimboss
parents: 7
diff changeset
572 let currpat = substitute(current, s:notslash . a:branch, '\\|', 'g')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 while a:string !~ a:prefix . currpat . a:suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 let tail = strpart(tail, i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
576 let i = matchend(tail, s:notslash . a:comma)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577 if i == -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 return -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 let current = strpart(tail, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 if a:branch == ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 let currpat = current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 else
800
d8f905020502 updated for version 7.0b
vimboss
parents: 7
diff changeset
584 let currpat = substitute(current, s:notslash . a:branch, '\\|', 'g')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 if a:0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 let alttail = strpart(alttail, j)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 let j = matchend(alttail, s:notslash . a:comma)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 if a:0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 let current = current . a:comma . strpart(alttail, 0, j-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 return current
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 " Call this function to turn on debugging information. Every time the main
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 " script is run, buffer variables will be saved. These can be used directly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
599 " or viewed using the menu items below.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 if !exists(":MatchDebug")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 command! -nargs=0 MatchDebug call s:Match_debug()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 fun! s:Match_debug()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 let b:match_debug = 1 " Save debugging information.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 " pat = all of b:match_words with backrefs parsed
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 amenu &Matchit.&pat :echo b:match_pat<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 " match = bit of text that is recognized as a match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 amenu &Matchit.&match :echo b:match_match<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 " curcol = cursor column of the start of the matching text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 amenu &Matchit.&curcol :echo b:match_col<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 " wholeBR = matching group, original version
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 amenu &Matchit.wh&oleBR :echo b:match_wholeBR<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 " iniBR = 'if' piece, original version
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 amenu &Matchit.ini&BR :echo b:match_iniBR<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 " ini = 'if' piece, with all backrefs resolved from match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 amenu &Matchit.&ini :echo b:match_ini<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 " tail = 'else\|endif' piece, with all backrefs resolved from match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 amenu &Matchit.&tail :echo b:match_tail<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 " fin = 'endif' piece, with all backrefs resolved from match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 amenu &Matchit.&word :echo b:match_word<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 " '\'.d in ini refers to the same thing as '\'.table[d] in word.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 amenu &Matchit.t&able :echo '0:' . b:match_table . ':9'<CR>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 " Jump to the nearest unmatched "(" or "if" or "<tag>" if a:spflag == "bW"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 " or the nearest unmatched "</tag>" or "endif" or ")" if a:spflag == "W".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 " Return a "mark" for the original position, so that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 " let m = MultiMatch("bW", "n") ... execute m
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 " will return to the original position. If there is a problem, do not
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 " move the cursor and return "", unless a count is given, in which case
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 " go up or down as many levels as possible and again return "".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 " TODO This relies on the same patterns as % matching. It might be a good
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 " idea to give it its own matching patterns.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 fun! s:MultiMatch(spflag, mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 if !exists("b:match_words") || b:match_words == ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637 return ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 let restore_options = (&ic ? "" : "no") . "ignorecase"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
640 if exists("b:match_ignorecase")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 let &ignorecase = b:match_ignorecase
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 let startline = line(".")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 let startcol = col(".")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 " First step: if not already done, set the script variables
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 " s:do_BR flag for whether there are backrefs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 " s:pat parsed version of b:match_words
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 " s:all regexp based on s:pat and the default groups
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 " This part is copied and slightly modified from s:Match_wrapper().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 let default = escape(&mps, '[$^.*~\\/?]') . (strlen(&mps) ? "," : "") .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652 \ '\/\*:\*\/,#if\%(def\)\=:$else\>:#elif\>:#endif\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 " Allow b:match_words = "GetVimMatchWords()" .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 if b:match_words =~ ":"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 let match_words = b:match_words
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 execute "let match_words =" b:match_words
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
659 if (match_words != s:last_words) || (&mps != s:last_mps) ||
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 \ exists("b:match_debug")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 let s:last_words = match_words
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 let s:last_mps = &mps
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 if match_words !~ s:notslash . '\\\d'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 let s:do_BR = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 let s:pat = match_words
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 let s:do_BR = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 let s:pat = s:ParseWords(match_words)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 let s:all = '\%(' . substitute(s:pat . (strlen(s:pat)?",":"") . default,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
671 \ '[,:]\+','\\|','g') . '\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
672 if exists("b:match_debug")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
673 let b:match_pat = s:pat
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
674 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 " Second step: figure out the patterns for searchpair()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 " and save the screen, cursor position, and 'ignorecase'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679 " - TODO: A lot of this is copied from s:Match_wrapper().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 " - maybe even more functionality should be split off
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 " - into separate functions!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
682 let cdefault = (s:pat =~ '[^,]$' ? "," : "") . default
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
683 let open = substitute(s:pat . cdefault, ':[^,]*,', '\\),\\(', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
684 let open = '\(' . substitute(open, ':[^,]*$', '\\)', '')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 let close = substitute(s:pat . cdefault, ',[^,]*:', '\\),\\(', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 let close = substitute(close, '[^,]*:', '\\(', '') . '\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 if exists("b:match_skip")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 let skip = b:match_skip
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 elseif exists("b:match_comment") " backwards compatibility and testing!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 let skip = "r:" . b:match_comment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 let skip = 's:comment\|string'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 let skip = s:ParseSkip(skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 " let restore_cursor = line(".") . "G" . virtcol(".") . "|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 " normal! H
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 " let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 let restore_cursor = virtcol(".") . "|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 normal! g0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 let restore_cursor = line(".") . "G" . virtcol(".") . "|zs" . restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 normal! H
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 execute restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705 " Third step: call searchpair().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706 " Replace '\('--but not '\\('--with '\%(' and ',' with '\|'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 let openpat = substitute(open, '\(\\\@<!\(\\\\\)*\)\@<=\\(', '\\%(', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 let openpat = substitute(openpat, ',', '\\|', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 let closepat = substitute(close, '\(\\\@<!\(\\\\\)*\)\@<=\\(', '\\%(', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 let closepat = substitute(closepat, ',', '\\|', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 if skip =~ 'synID' && !(has("syntax") && exists("g:syntax_on"))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 let skip = '0'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 execute "if " . skip . "| let skip = '0' | endif"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 mark '
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 let level = v:count1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 while level
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 if searchpair(openpat, '', closepat, a:spflag, skip) < 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 call s:CleanUp(restore_options, a:mode, startline, startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 return ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 let level = level - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 " Restore options and return a string to restore the original position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 call s:CleanUp(restore_options, a:mode, startline, startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 return restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 " Search backwards for "if" or "while" or "<tag>" or ...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 " and return "endif" or "endwhile" or "</tag>" or ... .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 " For now, this uses b:match_words and the same script variables
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 " as s:Match_wrapper() . Later, it may get its own patterns,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 " either from a buffer variable or passed as arguments.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 " fun! s:Autocomplete()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 " echo "autocomplete not yet implemented :-("
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 " if !exists("b:match_words") || b:match_words == ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 " return ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 " end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 " let startpos = s:MultiMatch("bW")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 " if startpos == ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 " return ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 " endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 " " - TODO: figure out whether 'if' or '<tag>' matched, and construct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747 " " - the appropriate closing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 " let matchline = getline(".")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 " let curcol = col(".") - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 " " - TODO: Change the s:all argument if there is a new set of match pats.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751 " let regexp = s:Wholematch(matchline, s:all, curcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 " let suf = strlen(matchline) - matchend(matchline, regexp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
753 " let prefix = (curcol ? '^.\{' . curcol . '}\%(' : '^\%(')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 " let suffix = (suf ? '\).\{' . suf . '}$' : '\)$')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 " " Reconstruct the version with unresolved backrefs.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 " let patBR = substitute(b:match_words.',', '[,:]*,[,:]*', ',', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 " let patBR = substitute(patBR, ':\{2,}', ':', "g")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 " " Now, set group and groupBR to the matching group: 'if:endif' or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 " " 'while:endwhile' or whatever.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 " let group = s:Choose(s:pat, matchline, ",", ":", prefix, suffix, patBR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 " let i = matchend(group, s:notslash . ",")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 " let groupBR = strpart(group, i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 " let group = strpart(group, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 " " Now, matchline =~ prefix . substitute(group,':','\|','g') . suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 " if s:do_BR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 " let group = s:InsertRefs(groupBR, prefix, group, suffix, matchline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 " endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 " " let g:group = group
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 " " - TODO: Construct the closing from group.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 " let fake = "end" . expand("<cword>")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 " execute startpos
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 " return fake
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 " endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 " Close all open structures. "Get the heck out of here!"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 " fun! s:Gthhoh()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 " let close = s:Autocomplete()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 " while strlen(close)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 " put=close
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 " let close = s:Autocomplete()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 " endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 " endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 " Parse special strings as typical skip arguments for searchpair():
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 " s:foo becomes (current syntax item) =~ foo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 " S:foo becomes (current syntax item) !~ foo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 " r:foo becomes (line before cursor) =~ foo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 " R:foo becomes (line before cursor) !~ foo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 fun! s:ParseSkip(str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 let skip = a:str
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 if skip[1] == ":"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 if skip[0] == "s"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 let skip = "synIDattr(synID(line('.'),col('.'),1),'name') =~? '" .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 \ strpart(skip,2) . "'"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 elseif skip[0] == "S"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 let skip = "synIDattr(synID(line('.'),col('.'),1),'name') !~? '" .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 \ strpart(skip,2) . "'"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 elseif skip[0] == "r"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 let skip = "strpart(getline('.'),0,col('.'))=~'" . strpart(skip,2). "'"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 elseif skip[0] == "R"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 let skip = "strpart(getline('.'),0,col('.'))!~'" . strpart(skip,2). "'"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 return skip
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 let &cpo = s:save_cpo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 " vim:sts=2:sw=2: