annotate runtime/macros/matchit.vim @ 4217:6ce32844727d v7.3.860

updated for version 7.3.860 Problem: When using --remote-expr try/catch does not work. (Andrey Radev) Solution: Set emsg_silent instead of emsg_off.
author Bram Moolenaar <bram@vim.org>
date Wed, 13 Mar 2013 20:23:22 +0100
parents 9eb0d30510f7
children 349e6c01f35d
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
1623
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
2 " Last Change: Fri Jan 25 10:00 AM 2008 EST
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Maintainer: Benji Fisher PhD <benji@member.AMS.org>
1623
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
4 " Version: 1.13.2, 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
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 800
diff changeset
18 " Collett, Stephen Wall, Dany St-Amant, Yuheng Xie, and Johannes Zellner.
7
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 = ""
1623
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
45 let s:last_words = ":"
7
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(".")
1623
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
103 " Use default behavior if called with a count.
7
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 end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 " First step: if not already done, set the script variables
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 " s:do_BR flag for whether there are backrefs
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 " s:pat parsed version of b:match_words
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112 " s:all regexp based on s:pat and the default groups
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 "
1623
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
114 if !exists("b:match_words") || b:match_words == ""
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
115 let match_words = ""
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
116 " Allow b:match_words = "GetVimMatchWords()" .
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
117 elseif b:match_words =~ ":"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 let match_words = b:match_words
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 execute "let match_words =" b:match_words
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 " Thanks to Preben "Peppe" Guldberg and Bram Moolenaar for this suggestion!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 if (match_words != s:last_words) || (&mps != s:last_mps) ||
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 \ exists("b:match_debug")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125 let s:last_words = match_words
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 let s:last_mps = &mps
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 " The next several lines were here before
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 " BF started messing with this script.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 " quote the special chars in 'matchpairs', replace [,:] with \| and then
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 " append the builtin pairs (/*, */, #if, #ifdef, #else, #elif, #endif)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 " let default = substitute(escape(&mps, '[$^.*~\\/?]'), '[,:]\+',
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 " \ '\\|', 'g').'\|\/\*\|\*\/\|#if\>\|#ifdef\>\|#else\>\|#elif\>\|#endif\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 let default = escape(&mps, '[$^.*~\\/?]') . (strlen(&mps) ? "," : "") .
4007
9eb0d30510f7 updated for version 7.3.758
Bram Moolenaar <bram@vim.org>
parents: 3445
diff changeset
134 \ '\/\*:\*\/,#\s*if\%(def\)\=:#\s*else\>:#\s*elif\>:#\s*endif\>'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 " s:all = pattern with all the keywords
1623
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
136 let match_words = match_words . (strlen(match_words) ? "," : "") . default
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
137 if match_words !~ s:notslash . '\\\d'
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
138 let s:do_BR = 0
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
139 let s:pat = match_words
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
140 else
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
141 let s:do_BR = 1
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
142 let s:pat = s:ParseWords(match_words)
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
143 endif
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
144 let s:all = substitute(s:pat, s:notslash . '\zs[,:]\+', '\\|', 'g')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 let s:all = '\%(' . s:all . '\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 " let s:all = '\%(' . substitute(s:all, '\\\ze[,:]', '', 'g') . '\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 if exists("b:match_debug")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 let b:match_pat = s:pat
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 " Second step: set the following local variables:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 " matchline = line on which the cursor started
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 " curcol = number of characters before match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 " prefix = regexp for start of line to start of match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 " suffix = regexp for end of match to end of line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 " Require match to end on or after the cursor and prefer it to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 " start on or before the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 let matchline = getline(startline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 if a:word != ''
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 " word given
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 if a:word !~ s:all
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 echohl WarningMsg|echo 'Missing rule for word:"'.a:word.'"'|echohl NONE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 return s:CleanUp(restore_options, a:mode, startline, startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 let matchline = a:word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 let curcol = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 let prefix = '^\%('
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 let suffix = '\)$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 " Now the case when "word" is not given
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 else " Find the match that ends on or after the cursor and set curcol.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 let regexp = s:Wholematch(matchline, s:all, startcol-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 let curcol = match(matchline, regexp)
1623
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
174 " If there is no match, give up.
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
175 if curcol == -1
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
176 return s:CleanUp(restore_options, a:mode, startline, startcol)
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
177 endif
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 800
diff changeset
178 let endcol = matchend(matchline, regexp)
96cd8222a819 updated for version 7.1a
vimboss
parents: 800
diff changeset
179 let suf = strlen(matchline) - endcol
96cd8222a819 updated for version 7.1a
vimboss
parents: 800
diff changeset
180 let prefix = (curcol ? '^.*\%' . (curcol + 1) . 'c\%(' : '^\%(')
96cd8222a819 updated for version 7.1a
vimboss
parents: 800
diff changeset
181 let suffix = (suf ? '\)\%' . (endcol + 1) . 'c.*$' : '\)$')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 if exists("b:match_debug")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 let b:match_match = matchstr(matchline, regexp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 let b:match_col = curcol+1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 " Third step: Find the group and single word that match, and the original
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 " (backref) versions of these. Then, resolve the backrefs.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 " Set the following local variable:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 " group = colon-separated list of patterns, one of which matches
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 " = ini:mid:fin or ini:fin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 " Reconstruct the version with unresolved backrefs.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 let patBR = substitute(match_words.',',
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 \ s:notslash.'\zs[,:]*,[,:]*', ',', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 let patBR = substitute(patBR, s:notslash.'\zs:\{2,}', ':', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 " Now, set group and groupBR to the matching group: 'if:endif' or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 " 'while:endwhile' or whatever. A bit of a kluge: s:Choose() returns
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 " group . "," . groupBR, and we pick it apart.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 let group = s:Choose(s:pat, matchline, ",", ":", prefix, suffix, patBR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 let i = matchend(group, s:notslash . ",")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 let groupBR = strpart(group, i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 let group = strpart(group, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 " Now, matchline =~ prefix . substitute(group,':','\|','g') . suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 if s:do_BR " Do the hard part: resolve those backrefs!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 let group = s:InsertRefs(groupBR, prefix, group, suffix, matchline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 if exists("b:match_debug")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 let b:match_wholeBR = groupBR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 let i = matchend(groupBR, s:notslash . ":")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 let b:match_iniBR = strpart(groupBR, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 " Fourth step: Set the arguments for searchpair().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 let i = matchend(group, s:notslash . ":")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217 let j = matchend(group, '.*' . s:notslash . ":")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 let ini = strpart(group, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 let mid = substitute(strpart(group, i,j-i-1), s:notslash.'\zs:', '\\|', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 let fin = strpart(group, j)
800
d8f905020502 updated for version 7.0b
vimboss
parents: 7
diff changeset
221 "Un-escape the remaining , and : characters.
d8f905020502 updated for version 7.0b
vimboss
parents: 7
diff changeset
222 let ini = substitute(ini, s:notslash . '\zs\\\(:\|,\)', '\1', 'g')
d8f905020502 updated for version 7.0b
vimboss
parents: 7
diff changeset
223 let mid = substitute(mid, s:notslash . '\zs\\\(:\|,\)', '\1', 'g')
d8f905020502 updated for version 7.0b
vimboss
parents: 7
diff changeset
224 let fin = substitute(fin, s:notslash . '\zs\\\(:\|,\)', '\1', 'g')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 " searchpair() requires that these patterns avoid \(\) groups.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 let ini = substitute(ini, s:notslash . '\zs\\(', '\\%(', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 let mid = substitute(mid, s:notslash . '\zs\\(', '\\%(', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 let fin = substitute(fin, s:notslash . '\zs\\(', '\\%(', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 " Set mid. This is optimized for readability, not micro-efficiency!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 if a:forward && matchline =~ prefix . fin . suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 \ || !a:forward && matchline =~ prefix . ini . suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 let mid = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 " Set flag. This is optimized for readability, not micro-efficiency!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 if a:forward && matchline =~ prefix . fin . suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 \ || !a:forward && matchline !~ prefix . ini . suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237 let flag = "bW"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 let flag = "W"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 " Set skip.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 if exists("b:match_skip")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 let skip = b:match_skip
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 elseif exists("b:match_comment") " backwards compatibility and testing!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 let skip = "r:" . b:match_comment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 let skip = 's:comment\|string'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 let skip = s:ParseSkip(skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 if exists("b:match_debug")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 let b:match_ini = ini
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 let b:match_tail = (strlen(mid) ? mid.'\|' : '') . fin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 " Fifth step: actually start moving the cursor and call searchpair().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 " Later, :execute restore_cursor to get to the original screen.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 let restore_cursor = virtcol(".") . "|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 normal! g0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 let restore_cursor = line(".") . "G" . virtcol(".") . "|zs" . restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 normal! H
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 execute restore_cursor
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 800
diff changeset
263 call cursor(0, curcol + 1)
96cd8222a819 updated for version 7.1a
vimboss
parents: 800
diff changeset
264 " normal! 0
96cd8222a819 updated for version 7.1a
vimboss
parents: 800
diff changeset
265 " if curcol
96cd8222a819 updated for version 7.1a
vimboss
parents: 800
diff changeset
266 " execute "normal!" . curcol . "l"
96cd8222a819 updated for version 7.1a
vimboss
parents: 800
diff changeset
267 " endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 if skip =~ 'synID' && !(has("syntax") && exists("g:syntax_on"))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 let skip = "0"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 execute "if " . skip . "| let skip = '0' | endif"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 let sp_return = searchpair(ini, mid, fin, flag, skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 let final_position = "call cursor(" . line(".") . "," . col(".") . ")"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 " Restore cursor position and original screen.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 execute restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 normal! m'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 if sp_return > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 execute final_position
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 return s:CleanUp(restore_options, a:mode, startline, startcol, mid.'\|'.fin)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 " Restore options and do some special handling for Operator-pending mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 " The optional argument is the tail of the matching group.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 fun! s:CleanUp(options, mode, startline, startcol, ...)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 execute "set" a:options
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 " Open folds, if appropriate.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 if a:mode != "o"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 if &foldopen =~ "percent"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 normal! zv
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293 " In Operator-pending mode, we want to include the whole match
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 " (for example, d%).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 " This is only a problem if we end up moving in the forward direction.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 elseif (a:startline < line(".")) ||
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 \ (a:startline == line(".") && a:startcol < col("."))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 if a:0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 " Check whether the match is a single character. If not, move to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 " end of the match.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 let matchline = getline(".")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 let currcol = col(".")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 let regexp = s:Wholematch(matchline, a:1, currcol-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 let endcol = matchend(matchline, regexp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 if endcol > currcol " This is NOT off by one!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 execute "normal!" . (endcol - currcol) . "l"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 endif " a:0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 endif " a:mode != "o" && etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 " Example (simplified HTML patterns): if
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 " a:groupBR = '<\(\k\+\)>:</\1>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 " a:prefix = '^.\{3}\('
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 " a:group = '<\(\k\+\)>:</\(\k\+\)>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 " a:suffix = '\).\{2}$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 " a:matchline = "123<tag>12" or "123</tag>12"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 " then extract "tag" from a:matchline and return "<tag>:</tag>" .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 fun! s:InsertRefs(groupBR, prefix, group, suffix, matchline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 if a:matchline !~ a:prefix .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 \ substitute(a:group, s:notslash . '\zs:', '\\|', 'g') . a:suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 return a:group
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325 let i = matchend(a:groupBR, s:notslash . ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 let ini = strpart(a:groupBR, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 let tailBR = strpart(a:groupBR, i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328 let word = s:Choose(a:group, a:matchline, ":", "", a:prefix, a:suffix,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 \ a:groupBR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 let i = matchend(word, s:notslash . ":")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 let wordBR = strpart(word, i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 let word = strpart(word, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 " Now, a:matchline =~ a:prefix . word . a:suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 if wordBR != ini
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 let table = s:Resolve(ini, wordBR, "table")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 " let table = "----------"
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 d = 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 while d < 10
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 if tailBR =~ s:notslash . '\\' . d
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 " let table[d] = d
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 let table = table . d
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 let table = table . "-"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 let d = d + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 let d = 9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 while d
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 if table[d] != "-"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 let backref = substitute(a:matchline, a:prefix.word.a:suffix,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 \ '\'.table[d], "")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 " Are there any other characters that should be escaped?
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 let backref = escape(backref, '*,:')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 execute s:Ref(ini, d, "start", "len")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 let ini = strpart(ini, 0, start) . backref . strpart(ini, start+len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 let tailBR = substitute(tailBR, s:notslash . '\zs\\' . d,
2034
7bc41231fbc7 Update runtime files.
Bram Moolenaar <bram@zimbu.org>
parents: 1623
diff changeset
360 \ escape(backref, '\\&'), 'g')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 let d = d-1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 if exists("b:match_debug")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 if s:do_BR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 let b:match_table = table
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
367 let b:match_word = word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 let b:match_table = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 let b:match_word = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373 return ini . ":" . tailBR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 " Input a comma-separated list of groups with backrefs, such as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 " a:groups = '\(foo\):end\1,\(bar\):end\1'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378 " and return a comma-separated list of groups with backrefs replaced:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 " return '\(foo\):end\(foo\),\(bar\):end\(bar\)'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 fun! s:ParseWords(groups)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 let groups = substitute(a:groups.",", s:notslash.'\zs[,:]*,[,:]*', ',', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382 let groups = substitute(groups, s:notslash . '\zs:\{2,}', ':', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 let parsed = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384 while groups =~ '[^,:]'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 let i = matchend(groups, s:notslash . ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386 let j = matchend(groups, s:notslash . ',')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 let ini = strpart(groups, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388 let tail = strpart(groups, i, j-i-1) . ":"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 let groups = strpart(groups, j)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
390 let parsed = parsed . ini
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391 let i = matchend(tail, s:notslash . ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 while i != -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 " In 'if:else:endif', ini='if' and word='else' and then word='endif'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394 let word = strpart(tail, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
395 let tail = strpart(tail, i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 let i = matchend(tail, s:notslash . ':')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 let parsed = parsed . ":" . s:Resolve(ini, word, "word")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398 endwhile " Now, tail has been used up.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 let parsed = parsed . ","
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 endwhile " groups =~ '[^,:]'
1623
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
401 let parsed = substitute(parsed, ',$', '', '')
7
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 . '\)'
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 800
diff changeset
418 let prefix = (a:start ? '\(^.*\%<' . (a:start + 2) . 'c\)\zs' : '^')
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 let len = strlen(a:string)
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 800
diff changeset
420 let suffix = (a:start+1 < len ? '\(\%>'.(a:start+1).'c.*$\)\@=' : '$')
7
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) ? "," : "") .
4007
9eb0d30510f7 updated for version 7.3.758
Bram Moolenaar <bram@vim.org>
parents: 3445
diff changeset
652 \ '\/\*:\*\/,#\s*if\%(def\)\=:#\s*else\>:#\s*elif\>:#\s*endif\>'
7
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
1623
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
683 let open = substitute(s:pat . cdefault,
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
684 \ s:notslash . '\zs:.\{-}' . s:notslash . ',', '\\),\\(', 'g')
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
685 let open = '\(' . substitute(open, s:notslash . '\zs:.*$', '\\)', '')
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
686 let close = substitute(s:pat . cdefault,
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
687 \ s:notslash . '\zs,.\{-}' . s:notslash . ':', '\\),\\(', 'g')
53938adac247 updated for version 7.2a
vimboss
parents: 1125
diff changeset
688 let close = substitute(close, '^.\{-}' . s:notslash . ':', '\\(', '') . '\)'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689 if exists("b:match_skip")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 let skip = b:match_skip
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 elseif exists("b:match_comment") " backwards compatibility and testing!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 let skip = "r:" . b:match_comment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 let skip = 's:comment\|string'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 let skip = s:ParseSkip(skip)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 " let restore_cursor = line(".") . "G" . virtcol(".") . "|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 " normal! H
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 " let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
700 let restore_cursor = virtcol(".") . "|"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701 normal! g0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 let restore_cursor = line(".") . "G" . virtcol(".") . "|zs" . restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 normal! H
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
704 let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
705 execute restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
706
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 " Third step: call searchpair().
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 " Replace '\('--but not '\\('--with '\%(' and ',' with '\|'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 let openpat = substitute(open, '\(\\\@<!\(\\\\\)*\)\@<=\\(', '\\%(', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 let openpat = substitute(openpat, ',', '\\|', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 let closepat = substitute(close, '\(\\\@<!\(\\\\\)*\)\@<=\\(', '\\%(', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
712 let closepat = substitute(closepat, ',', '\\|', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 if skip =~ 'synID' && !(has("syntax") && exists("g:syntax_on"))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 let skip = '0'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716 execute "if " . skip . "| let skip = '0' | endif"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 mark '
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 let level = v:count1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 while level
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 if searchpair(openpat, '', closepat, a:spflag, skip) < 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 call s:CleanUp(restore_options, a:mode, startline, startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 return ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 let level = level - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 " Restore options and return a string to restore the original position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 call s:CleanUp(restore_options, a:mode, startline, startcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 return restore_cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 " Search backwards for "if" or "while" or "<tag>" or ...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 " and return "endif" or "endwhile" or "</tag>" or ... .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 " For now, this uses b:match_words and the same script variables
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 " as s:Match_wrapper() . Later, it may get its own patterns,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 " either from a buffer variable or passed as arguments.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 " fun! s:Autocomplete()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 " echo "autocomplete not yet implemented :-("
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 " if !exists("b:match_words") || b:match_words == ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 " return ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 " end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 " let startpos = s:MultiMatch("bW")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 " if startpos == ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 " return ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747 " endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 " " - TODO: figure out whether 'if' or '<tag>' matched, and construct
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
749 " " - the appropriate closing.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 " let matchline = getline(".")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751 " let curcol = col(".") - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 " " - 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
753 " let regexp = s:Wholematch(matchline, s:all, curcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
754 " let suf = strlen(matchline) - matchend(matchline, regexp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 " let prefix = (curcol ? '^.\{' . curcol . '}\%(' : '^\%(')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 " let suffix = (suf ? '\).\{' . suf . '}$' : '\)$')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 " " Reconstruct the version with unresolved backrefs.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 " let patBR = substitute(b:match_words.',', '[,:]*,[,:]*', ',', 'g')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 " let patBR = substitute(patBR, ':\{2,}', ':', "g")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 " " Now, set group and groupBR to the matching group: 'if:endif' or
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 " " 'while:endwhile' or whatever.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 " let group = s:Choose(s:pat, matchline, ",", ":", prefix, suffix, patBR)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 " let i = matchend(group, s:notslash . ",")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 " let groupBR = strpart(group, i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 " let group = strpart(group, 0, i-1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 " " Now, matchline =~ prefix . substitute(group,':','\|','g') . suffix
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 " if s:do_BR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768 " let group = s:InsertRefs(groupBR, prefix, group, suffix, matchline)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 " endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 " " let g:group = group
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 " " - TODO: Construct the closing from group.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 " let fake = "end" . expand("<cword>")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 " execute startpos
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 " return fake
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 " endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 " Close all open structures. "Get the heck out of here!"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 " fun! s:Gthhoh()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 " let close = s:Autocomplete()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 " while strlen(close)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 " put=close
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
783 " let close = s:Autocomplete()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
784 " endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 " endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
787 " Parse special strings as typical skip arguments for searchpair():
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 " s:foo becomes (current syntax item) =~ foo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 " S:foo becomes (current syntax item) !~ foo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
790 " r:foo becomes (line before cursor) =~ foo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 " R:foo becomes (line before cursor) !~ foo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
792 fun! s:ParseSkip(str)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 let skip = a:str
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 if skip[1] == ":"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 if skip[0] == "s"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 let skip = "synIDattr(synID(line('.'),col('.'),1),'name') =~? '" .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 \ strpart(skip,2) . "'"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798 elseif skip[0] == "S"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 let skip = "synIDattr(synID(line('.'),col('.'),1),'name') !~? '" .
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 \ 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 elseif skip[0] == "R"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804 let skip = "strpart(getline('.'),0,col('.'))!~'" . strpart(skip,2). "'"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 return skip
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 let &cpo = s:save_cpo
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2034
diff changeset
811 unlet s:save_cpo
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
812
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 " vim:sts=2:sw=2: