add vim conf files
[arrow.git] / conf_slk120 / vim / _vim / plugin / VimRegEx.vim
bloba6ebaaafec9825f51017a4f0274b337b72fb9798
1 " Vim plugin for Vim Regular Expression Development
2 " Language:    vim script
3 " Maintainer:  Dave Silvia <dsilvia@mchsi.com>
4 " Date:        9/27/2004
6 " Version 1.1
7 " Date:        10/12/2004
8 "  Fixed:
9 "   - Problem with UNIX type
10 "     systems and have a single
11 "     quote in the filename for
12 "     the usage file.  Removed
13 "     the single quotes.
15 " Version 1.0
16 " Initial Release
17 " Date:        10/10/2004
18 " Beta 7
19 " Date:        10/7/2004
20 "  New:
21 "   - Added 'lookaround' anchor
22 "     highlighting per suggestion
23 "     by Jon Merz
24 "  Fixed:
25 "   - Couldn't use pattern beginning
26 "     with double quote because of
27 "     comment allowance.  Now prompts.
28 "     pointed out by Jon Merz
29 "   - Only highlights one pattern in
30 "     top window even if it is a sub
31 "     pattern of another pattern in the
32 "     window.
34 " Beta 6
35 " Date:        10/4/2004
36 "  Possible final beta release
38 " Beta 5
39 " Date:        10/2/2004
40 " Beta 5b
41 " Date:        10/2/2004
42 "  New:
43 "   -  Added expanded usage message
44 "      in a scrollable window
45 " Beta 5c
46 " Date:        10/2/2004
47 "  New:
48 "   -  Added highlight to current
49 "      selected pattern in top
50 "      window
52 "arrow commend it, bcs, now has not VSUTIL
53 finish
55 let s:thisScript=expand("<sfile>:p")
56 let s:myName=fnamemodify(s:thisScript,":t")
58 if !exists('g:VSUTIL') || g:VSUTILMAJ < 1 || g:VSUTILMIN < 4
59         silent! runtime plugin/vsutil.vim
60         if !exists('g:VSUTIL') || g:VSUTILMAJ < 1 || g:VSUTILMIN < 4
61                 echohl Errormsg
62                 echomsg s:myName.": Requires Version 1.4 or higher of vsutil.vim"
63                 echomsg "Go to http://www.vim.org/account/profile.php?user_id=5397 for link to vsutil.vim"
64                 echohl None
65                 finish
66         endif
67 endif
69 if exists('g:VimrexDebug')
70         command! -nargs=1 VimrexDBG :if g:VimrexDebug | call append(line('$'),<args>) | endif
71 else
72         command! -nargs=1 VimrexDBG :
73 endif
75 function! s:doGlobals()
76 if !exists("g:VimrexBrowseDir")
77         let RTdirs=expand(&runtimepath)
78         if !exists("*StrListTok")
79                 runtime plugin/vsutil.vim
80         endif
81         let RTdir=StrListTok(RTdirs,'b:rtdirs')
82         while RTdir != ''
83                 if glob(RTdir) != ''
84                         let g:VimrexBrowseDir=RTdir
85                         break
86                 endif
87                 let RTdir=StrListTok('','b:rtdirs')
88         endwhile
89         while RTdir != ''
90                 let RTdir=StrListTok('','b:rtdirs')
91         endwhile
92         unlet b:rtdirs
93         unlet! RTdir RTdirs
94 endif
95 if !exists("g:VimrexFileDir")
96         let g:VimrexFileDir=fnamemodify(expand("~"),":p:h")
97 endif
98 if !exists("g:VimrexFile")
99         let g:VimrexFile=fnamemodify(expand(g:VimrexFileDir."/.Vim Regular Expression Specification"),":p")
100 endif
101 if !exists("g:VimrexRsltFile")
102         let g:VimrexRsltFile=fnamemodify(expand(g:VimrexFileDir."/.Vim Regular Expression Result"),":p")
103 endif
104 if !exists("g:VimrexSrcFile")
105         let g:VimrexSrcFile=fnamemodify(expand(g:VimrexFileDir."/.Vim Regular Expression Search Source"),":p")
106 endif
107 if !exists("g:VimrexUsageFile")
108         let g:VimrexUsageFile=fnamemodify(expand(g:VimrexFileDir."/.Vim Regular Expression The Fine Manual"),":p")
109 endif
110 if !exists("g:VimrexExec")
111         let g:VimrexExec="ze"
112 endif
113 if !exists("g:VimrexAnlz")
114         let g:VimrexAnlz="za"
115 endif
116 if !exists("g:VimrexTop")
117         let g:VimrexTop="gt"
118 endif
119 if !exists("g:VimrexBtm")
120         let g:VimrexBtm="gb"
121 endif
122 if !exists("g:VimrexCtr")
123         let g:VimrexCtr="gc"
124 endif
125 if !exists("g:VimrexDSrc")
126         let g:VimrexDSrc="zs"
127 endif
128 if !exists("g:VimrexDRslt")
129         let g:VimrexDRslt="zr"
130 endif
131 if !exists("g:VimrexCLS")
132         let g:VimrexCLS="zv"
133 endif
134 if !exists("g:VimrexRdSrc")
135         let g:VimrexRdSrc="zS"
136 endif
137 if !exists("g:VimrexRdRex")
138         let g:VimrexRdRex="zR"
139 endif
140 if !exists("g:VimrexExit")
141         let g:VimrexExit="zx"
142 endif
143 if !exists("g:VimrexQQ")
144         let g:VimrexQQ='z?'
145 endif
146 if !exists("g:VimrexQC")
147         let g:VimrexQC='zc'
148 endif
149 if !exists("g:VimrexQP")
150         let g:VimrexQP='zp'
151 endif
152 if !exists("g:VimrexQL")
153         let g:VimrexQL='zl'
154 endif
155 if !exists("g:VimrexZHV")
156         let g:VimrexZHV='zhv'
157 endif
158 if !exists("g:VimrexZHS")
159         let g:VimrexZHS='zhs'
160 endif
161 if !exists("g:VimrexZHU")
162         let g:VimrexZHU='zhu'
163 endif
164 if !exists("g:VimrexZHR")
165         let g:VimrexZHR='zhr'
166 endif
167 if !exists("g:VimrexZHA")
168         let g:VimrexZHA='zha'
169 endif
170 if !exists("g:VimrexZTV")
171         let g:VimrexZTV='ztv'
172 endif
173 if !exists("g:VimrexZTS")
174         let g:VimrexZTS='zts'
175 endif
176 if !exists("g:VimrexZTU")
177         let g:VimrexZTU='ztu'
178 endif
179 if !exists("g:VimrexZTR")
180         let g:VimrexZTR='ztr'
181 endif
182 if !exists("g:VimrexZTA")
183         let g:VimrexZTA='zta'
184 endif
186 if !exists("g:VimrexSrchPatLnk")
187         if !exists("g:VimrexSrchPatCFG")
188                 let g:VimrexSrchPatCFG='black'
189         endif
190         if !exists("g:VimrexSrchPatCBG")
191                 let g:VimrexSrchPatCBG='DarkMagenta'
192         endif
193         if !exists("g:VimrexSrchPatGFG")
194                 let g:VimrexSrchPatGFG='black'
195         endif
196         if !exists("g:VimrexSrchPatGBG")
197                 let g:VimrexSrchPatGBG='DarkMagenta'
198         endif
199 endif
201 if !exists("g:VimrexSrchAncLnk")
202         if !exists("g:VimrexSrchAncCFG")
203                 let g:VimrexSrchAncCFG='DarkRed'
204         endif
205         if !exists("g:VimrexSrchAncCBG")
206                 let g:VimrexSrchAncCBG='gray'
207         endif
208         if !exists("g:VimrexSrchAncGFG")
209                 let g:VimrexSrchAncGFG='DarkRed'
210         endif
211         if !exists("g:VimrexSrchAncGBG")
212                 let g:VimrexSrchAncGBG='gray'
213         endif
214 endif
216 if !exists("g:VimrexSrchTokLnk")
217         if !exists("g:VimrexSrchTokCBG")
218                 let g:VimrexSrchTokCBG='LightCyan'
219         endif
220         if !exists("g:VimrexSrchTokCFG")
221                 let g:VimrexSrchTokCFG='black'
222         endif
223         if !exists("g:VimrexSrchTokGBG")
224                 let g:VimrexSrchTokGBG='LightCyan'
225         endif
226         if !exists("g:VimrexSrchTokGFG")
227                 let g:VimrexSrchTokGFG='black'
228         endif
229 endif
231 if !exists("g:VimrexSrchCgpLnk")
232         if !exists("g:VimrexSrchCgpCFG")
233                 let g:VimrexSrchCgpCFG='blue'
234         endif
235         if !exists("g:VimrexSrchCgpCBG")
236                 let g:VimrexSrchCgpCBG='red'
237         endif
238         if !exists("g:VimrexSrchCgpGFG")
239                 let g:VimrexSrchCgpGFG='blue'
240         endif
241         if !exists("g:VimrexSrchCgpGBG")
242                 let g:VimrexSrchCgpGBG='red'
243         endif
244 endif
246 if !exists("g:VimrexSrchGrpLnk")
247         if !exists("g:VimrexSrchGrpCFG")
248                 let g:VimrexSrchGrpCFG='red'
249         endif
250         if !exists("g:VimrexSrchGrpCBG")
251                 let g:VimrexSrchGrpCBG='blue'
252         endif
253         if !exists("g:VimrexSrchGrpGFG")
254                 let g:VimrexSrchGrpGFG='red'
255         endif
256         if !exists("g:VimrexSrchGrpGBG")
257                 let g:VimrexSrchGrpGBG='blue'
258         endif
259 endif
261 if !exists("g:VimrexSrchChcLnk")
262         if !exists("g:VimrexSrchChcCFG")
263                 let g:VimrexSrchChcCFG='black'
264         endif
265         if !exists("g:VimrexSrchChcCBG")
266                 let g:VimrexSrchChcCBG='LightBlue'
267         endif
268         if !exists("g:VimrexSrchChcGFG")
269                 let g:VimrexSrchChcGFG='black'
270         endif
271         if !exists("g:VimrexSrchChcGBG")
272                 let g:VimrexSrchChcGBG='LightBlue'
273         endif
274 endif
276 if !exists("g:VimrexSrchExpLnk")
277         if !exists("g:VimrexSrchExpCFG")
278                 let g:VimrexSrchExpCFG='black'
279         endif
280         if !exists("g:VimrexSrchExpCBG")
281                 let g:VimrexSrchExpCBG='LightGreen'
282         endif
283         if !exists("g:VimrexSrchExpGFG")
284                 let g:VimrexSrchExpGFG='black'
285         endif
286         if !exists("g:VimrexSrchExpGBG")
287                 let g:VimrexSrchExpGBG='LightGreen'
288         endif
289 endif
291 if !exists("g:VimrexFilePatLnk")
292         if !exists("g:VimrexFilePatCFG")
293                 let g:VimrexFilePatCFG='cyan'
294         endif
295         if !exists("g:VimrexFilePatCBG")
296                 let g:VimrexFilePatCBG='brown'
297         endif
298         if !exists("g:VimrexFilePatGFG")
299                 let g:VimrexFilePatGFG='cyan'
300         endif
301         if !exists("g:VimrexFilePatGBG")
302                 let g:VimrexFilePatGBG='brown'
303         endif
304 endif
305 endfunction " s:doGlobals()
307 function! s:undoGlobals()
308         unlet! g:VimrexBrowseDir g:VimrexFileDir g:VimrexFile g:VimrexRsltFile g:VimrexSrcFile g:VimrexUsageFile
309         unlet! g:VimrexExec g:VimrexAnlz g:VimrexTop g:VimrexBtm g:VimrexCtr g:VimrexDSrc g:VimrexDRslt g:VimrexCLS
310         unlet! g:VimrexRdSrc g:VimrexRdRex g:VimrexExit g:VimrexQQ g:VimrexQC g:VimrexQP g:VimrexQL g:VimrexZHV
311         unlet! g:VimrexZHS g:VimrexZHU g:VimrexZHR g:VimrexZHA g:VimrexZTV g:VimrexZTS g:VimrexZTU g:VimrexZTR
312         unlet! g:VimrexZTA g:VimrexSrchPatLnk g:VimrexSrchPatCFG g:VimrexSrchPatCBG g:VimrexSrchPatGFG
313         unlet! g:VimrexSrchPatGBG g:VimrexSrchAncLnk g:VimrexSrchAncCFG g:VimrexSrchAncCBG g:VimrexSrchAncGFG
314         unlet! g:VimrexSrchAncGBG g:VimrexSrchTokLnk g:VimrexSrchTokCBG g:VimrexSrchTokCFG g:VimrexSrchTokGBG
315         unlet! g:VimrexSrchTokGFG g:VimrexSrchCgpLnk g:VimrexSrchCgpCFG g:VimrexSrchCgpCBG g:VimrexSrchCgpGFG
316         unlet! g:VimrexSrchCgpGBG g:VimrexSrchGrpLnk g:VimrexSrchGrpCFG g:VimrexSrchGrpCBG g:VimrexSrchGrpGFG
317         unlet! g:VimrexSrchGrpGBG g:VimrexSrchChcLnk g:VimrexSrchChcCFG g:VimrexSrchChcCBG g:VimrexSrchChcGFG
318         unlet! g:VimrexSrchChcGBG g:VimrexSrchExpLnk g:VimrexSrchExpCFG g:VimrexSrchExpCBG g:VimrexSrchExpGFG
319         unlet! g:VimrexSrchExpGBG g:VimrexFilePatLnk g:VimrexFilePatCFG g:VimrexFilePatCBG g:VimrexFilePatGFG
320         unlet! g:VimrexFilePatGBG
321 endfunction " s:undoGlobals()
323 function! s:gotoWin(which)
324         execute bufwinnr(a:which).'wincmd w'
325 endfunction
327 function! s:browser(which)
328         if has("gui_running") && has("browse")
329                 let fullname=browse(0,'Read File Into '.a:which,g:VimrexBrowseDir,'')
330         else
331                 let fname=input("File name: ")
332                 let fullname=glob(fname)
333                 if fullname == ''
334                         let fullname=g:VimrexBrowseDir.'/'.fname
335                         if glob(fullname) == ''
336                                 echohl Errormsg
337                                 echomsg "Cannot find ".fname
338                                 edhohl None
339                         endif
340                 endif
341         endif
342         if fullname == ''
343                 return
344         endif
345         call s:saveCurrent()
346         execute bufwinnr(a:which).'wincmd w'
347         let lnr=line('.')
348         if lnr == 1
349                 let ans=input("This is the buffer's first line, insert Above or Below? : ","A")
350                 if tolower(ans[0]) == 'a'
351                         let lnr=0
352                 endif
353         endif
354         execute ':'.lnr.'r '.fullname
355         set nomodified
356         call s:restoreCurrent()
357 endfunction
359 function! s:generate(which,type)
360         if a:which == 'ALLBUTUSAGE'
361                 call s:saveCurrent()
362                 call s:generate(g:VimrexFile,a:type)
363                 call s:generate(g:VimrexRsltFile,a:type)
364                 call s:generate(g:VimrexSrcFile,a:type)
365                 let tmpFile=fnamemodify(expand(g:VimrexFileDir.'/.Vim Regular Expression All'),":p")
366                 new
367                 if a:type == 'HTML'
368                         execute 'silent! edit! '.g:VimrexFile.'.html'
369                         execute line('$').'r '.g:VimrexRsltFile.'.html'
370                         execute line('$').'r '.g:VimrexSrcFile.'.html'
371                         execute 'silent! :w! '.tmpFile.'.html'
372                 else
373                         execute 'silent! edit! '.g:VimrexFile.'.txt'
374                         execute line('$').'r '.g:VimrexRsltFile.'.txt'
375                         call append(line('$'),' ')
376                         execute line('$').'r '.g:VimrexSrcFile.'.txt'
377                         execute 'silent! :w! '.tmpFile.'.txt'
378                 endif
379                 bd
380                 call s:restoreCurrent()
381                 return
382         endif
383         let whichBufNr=bufwinnr(a:which)
384         if whichBufNr == -1
385                 echohl Errormsg
386                 echomsg "No open window for ".a:which
387                 echohl None
388                 return
389         endif
390         call s:saveCurrent()
391         execute whichBufNr.'wincmd w'
392         if a:type == 'HTML'
393                 runtime syntax/2html.vim
394                 silent! :w!
395                 bd
396         else
397                 silent! :w! %.txt
398         endif
399         call s:restoreCurrent()
400 endfunction
402 function! s:adjustWin(which,how)
403         let whichBufNr=bufwinnr(a:which)
404         if whichBufNr == -1
405                 return
406         endif
407         if a:how == 'p'
408                 execute whichBufNr.'wincmd w'
409                 execute 'resize '.&lines
410                 return
411         endif
412         let usageBuf=bufwinnr(g:VimrexUsageFile)
413         let tot=&lines-&ch
414         let winNr=1
415         execute 'let winexists=winwidth('.winNr.')'
416         while winexists != -1
417                 let winNr=winNr+1
418                 execute 'let winexists=winwidth('.winNr.')'
419         endwhile
420         let winNr=winNr-1
421         let tot=tot-winNr
422         if usageBuf != -1
423                 let tot=tot-2
424                 let fullWins=winNr-2
425                 let thisWin=2
426         else
427                 let tot=tot-1
428                 let fullWins=winNr-1
429                 let thisWin=1
430         endif
431         let size=tot/fullWins
432         wincmd =
433         if usageBuf != -1
434                 1wincmd w
435                 resize 1
436         endif
437         while thisWin < winNr
438                 execute thisWin.'wincmd w'
439                 execute 'resize '.size
440                 let thisWin=thisWin+1
441         endwhile
442         execute winNr.'wincmd w'
443         resize 1
444 endfunction
446 function! s:closeUsage()
447         let usageBuf=bufwinnr(g:VimrexUsageFile)
448         if usageBuf != -1
449                 execute usageBuf."wincmd w"
450                 close
451         endif
452 endfunction
454 let s:inlegend=0
456 function! s:legend()
457         if s:inlegend
458                 return
459         else
460                 let s:inlegend=1
461         endif
462         call s:saveCurrent()
463         let legendWinNr=bufwinnr('Legend')
464         if legendWinNr == -1
465                 new
466                 edit Legend
467                 set noreadonly modifiable
468                 call append(0,"plain search  capture  non-capture  choice  expansion  lookaround  non-current")
469                 syntax match VimrexSearchCgp "capture"
470                 syntax match VimrexSearchGrp "non-capture"
471                 syntax match VimrexSearchChc "choice"
472                 syntax match VimrexSearchExp "expansion"
473                 syntax match VimrexSearchAnchor "lookaround"
474                 syntax match VimrexSearchToken "plain search"
475                 syntax match VimrexSearchPattern "non-current"
476                 normal dd
477         endif
478         let winNr=1
479         execute 'let winExists=winheight('.winNr.') != -1'
480         while winExists
481                 let winNr=winNr+1
482                 execute 'let winExists=winheight('.winNr.') != -1'
483         endwhile
484         let winNr=winNr-1
485         if winNr == legendWinNr && winheight(legendWinNr) == 1
486                 let s:inlegend=0
487                 return
488         endif
489         execute legendWinNr.'wincmd w'
490         wincmd J
491         call s:adjustWin('Legend','c')
492         set nomodified noswapfile nonumber readonly modifiable
493         call s:restoreCurrent()
494         let s:inlegend=0
495 endfunction
497 function! s:doGvimMenu()
498         execute 'amenu <silent> &Vimrex.&Execute\ Regular\ Expression<TAB>'.g:VimrexExec.' :call <SID>execRegex()<CR>'
499         execute 'amenu <silent> &Vimrex.&Analyze\ Regular\ Expression<TAB>'.g:VimrexAnlz.' :call TranslateRegex()<CR>'
500         execute 'amenu <silent> &Vimrex.&Window.Goto.(&Top)\ Regular\ Expression\ Specification\ Window<TAB>'.g:VimrexTop.' :call <SID>gotoWin(g:VimrexFile)<CR>'
501         execute 'amenu <silent> &Vimrex.&Window.Goto.(&Bottom)\ Regular\ Expression\ Search\ Source\ Window<TAB>'.g:VimrexBtm.' :call <SID>gotoWin(g:VimrexSrcFile)<CR>'
502         execute 'amenu <silent> &Vimrex.&Window.Goto.(&Center)\ Regular\ Expression\ Result\ Window<TAB>'.g:VimrexCtr.' :call <SID>gotoWin(g:VimrexRsltFile)<CR>'
503         execute 'amenu <silent> &Vimrex.&Window.&Clear.\.&Vim\ Regular\ Expression\ Specification\ Window<TAB>'.g:VimrexCLS.' :call <SID>cls(g:VimrexFile)<CR>' 
504         execute 'amenu <silent> &Vimrex.&Window.&Clear.\.Vim\ Regular\ Expression\ &Result\ Window<TAB>'.g:VimrexDRslt.' :call <SID>cls(g:VimrexRsltFile)<CR>' 
505         execute 'amenu <silent> &Vimrex.&Window.&Clear.\.Vim\ Regular\ Expression\ Search\ &Source\ Window<TAB>'.g:VimrexDSrc.' :call <SID>cls(g:VimrexSrcFile)<CR>' 
506         if has("browse")
507                 execute 'amenu <silent> &Vimrex.&Window.&Read\ File\ Into.\.Vim\ Regular\ Expression\ Search\ &Source\ Window<TAB>'.g:VimrexRdSrc.' :call <SID>browser(g:VimrexSrcFile)<CR>'
508                 execute 'amenu <silent> &Vimrex.&Window.&Read\ File\ Into.\.Vim\ &Regular\ Expression\ Specification\ Window<TAB>'.g:VimrexRdRex.' :call <SID>browser(g:VimrexFile)<CR>'
509         endif
510         execute 'amenu <silent> &Vimrex.&Usage.&Open<TAB>'.g:VimrexQQ.' :call <SID>usage()<CR>'
511         execute 'amenu <silent> &Vimrex.&Usage.C&lose<TAB>'.g:VimrexQL.' :call <SID>closeUsage()<CR>'
512         execute 'amenu <silent> &Vimrex.&Usage.&Collapse<TAB>'.g:VimrexQC.' :call <SID>adjustWin(g:VimrexUsageFile,"c")<CR>'
513         execute 'amenu <silent> &Vimrex.&Usage.Ex&pand<TAB>'.g:VimrexQP.' :call <SID>adjustWin(g:VimrexUsageFile,"p")<CR>'
514         execute 'amenu <silent> &Vimrex.&Generate\ File.&HTML.&Regular\ Expressions<TAB>'.g:VimrexZHV.' :call <SID>generate(g:VimrexFile,"HTML")<CR>'
515         execute 'amenu <silent> &Vimrex.&Generate\ File.&HTML.&Search\ Source<TAB>'.g:VimrexZHS.' :call <SID>generate(g:VimrexSrcFile,"HTML")<CR>'
516         execute 'amenu <silent> &Vimrex.&Generate\ File.&HTML.&Usage<TAB>'.g:VimrexZHU.' :call <SID>generate(g:VimrexUsageFile,"HTML")<CR>'
517         execute 'amenu <silent> &Vimrex.&Generate\ File.&HTML.&Results<TAB>'.g:VimrexZHR.' :call <SID>generate(g:VimrexRsltFile,"HTML")<CR>'
518         execute 'amenu <silent> &Vimrex.&Generate\ File.&HTML.&All\ But\ Usage<TAB>'.g:VimrexZHA.' :call <SID>generate("ALLBUTUSAGE","HTML")<CR>'
519         execute 'amenu <silent> &Vimrex.&Generate\ File.&TEXT.&Regular\ Expressions<TAB>'.g:VimrexZTV.' :call <SID>generate(g:VimrexFile,"TEXT")<CR>'
520         execute 'amenu <silent> &Vimrex.&Generate\ File.&TEXT.&Search\ Source<TAB>'.g:VimrexZTS.' :call <SID>generate(g:VimrexSrcFile,"TEXT")<CR>'
521         execute 'amenu <silent> &Vimrex.&Generate\ File.&TEXT.&Usage<TAB>'.g:VimrexZTU.' :call <SID>generate(g:VimrexUsageFile,"TEXT")<CR>'
522         execute 'amenu <silent> &Vimrex.&Generate\ File.&TEXT.&Results<TAB>'.g:VimrexZTR.' :call <SID>generate(g:VimrexRsltFile,"TEXT")<CR>'
523         execute 'amenu <silent> &Vimrex.&Generate\ File.&TEXT.&All\ But\ Usage<TAB>'.g:VimrexZTA.' :call <SID>generate("ALLBUTUSAGE","TEXT")<CR>'
524         execute 'amenu <silent> &Vimrex.E&xit<TAB>'.g:VimrexExit.' :call <SID>isVimrexRunning(g:VimRexUserCalled)<CR>'
525 endfunction
527 function! s:doMap(name,val)
528         let sname='s:prev'.a:name
529         let siname='s:iprev'.a:name
530         let gname='g:Vimrex'.a:name
531         let {sname}=maparg({gname})
532         let {siname}=maparg({gname},'i')
533         execute 'map <silent> '.{gname}.' '.a:val.'<CR>'
534         execute 'imap <silent> '.{gname}.' <Esc>'.a:val.'<CR>'
535 endfunction
537 function! s:doUnMap(name)
538         let sname='s:prev'.a:name
539         let siname='s:iprev'.a:name
540         let gname='g:Vimrex'.a:name
541         execute 'unmap '.{gname}
542         execute 'iunmap '.{gname}
543         if {sname} != ''
544                 let {sname}=substitute({sname},'|','\x16|','g')
545                 execute 'map '.{gname}.' '.{sname}
546         endif
547         if {siname} != ''
548                 let {siname}=substitute({siname},'|','\x16|','g')
549                 execute 'imap '.{gname}.' '.{siname}
550         endif
551 endfunction
553 function! s:isVimrexRunning(file)
554         if !exists("g:VimrexRunning")
555                 return
556         endif
557         if a:file != g:VimrexFile && a:file != g:VimrexRsltFile && a:file != g:VimrexSrcFile && a:file != g:VimRexUserCalled
558                 return
559         endif
560         unlet g:VimrexRunning g:VimRexUserCalled
561 augroup Vimrex
562         autocmd!
563 augroup END
564         if has("gui_running")
565                 aunmenu &Vimrex
566         endif
567         let winNr=bufwinnr(g:VimrexFile)
568         execute winNr.'wincmd w'
569         silent! :w
570         execute 'bwipeout '.bufnr(g:VimrexFile)
571         let winNr=bufwinnr(g:VimrexRsltFile)
572         execute winNr.'wincmd w'
573         set nomodified
574         execute 'bwipeout '.bufnr(g:VimrexRsltFile)
575         call s:delFile(g:VimrexRsltFile)
576         let winNr=bufwinnr(g:VimrexSrcFile)
577         execute winNr.'wincmd w'
578         silent! :w
579         execute 'bwipeout '.bufnr(g:VimrexSrcFile)
580         let winNr=bufwinnr(g:VimrexUsageFile)
581         if winNr != -1
582                 execute winNr.'wincmd w'
583                 set nomodified
584                 execute 'bwipeout '.bufnr(g:VimrexUsageFile)
585                 call s:delFile(g:VimrexUsageFile)
586         endif
587         let winNr=bufwinnr('Legend')
588         execute winNr.'wincmd w'
589         set nomodified
590         execute 'bwipeout '.bufnr('Legend')
591         let @/=s:pattern
592         let &hlsearch=s:saveHLS
593         let &ch=s:saveCH
594         let &syntax=s:saveSyn
595         let &cpoptions=s:saveCPO
596         call s:doUnMap('DRslt')
597         call s:doUnMap('DSrc')
598         call s:doUnMap('CLS')
599         call s:doUnMap('QQ')
600         call s:doUnMap('QC')
601         call s:doUnMap('QP')
602         call s:doUnMap('QL')
603         call s:doUnMap('ZHV')
604         call s:doUnMap('ZHS')
605         call s:doUnMap('ZHU')
606         call s:doUnMap('ZHR')
607         call s:doUnMap('ZHA')
608         call s:doUnMap('ZTV')
609         call s:doUnMap('ZTS')
610         call s:doUnMap('ZTU')
611         call s:doUnMap('ZTR')
612         call s:doUnMap('ZTA')
613         call s:doUnMap('Exec')
614         call s:doUnMap('Anlz')
615         call s:doUnMap('Top')
616         call s:doUnMap('Btm')
617         call s:doUnMap('Ctr')
618         call s:doUnMap('RdSrc')
619         call s:doUnMap('RdRex')
620         call s:doUnMap('Exit')
621         highlight clear VimrexSearchAnchor
622         highlight clear VimrexSearchPattern
623         highlight clear VimrexSearchToken
624         highlight clear VimrexFilePattern
625         syntax clear VimrexSearchAnchor
626         syntax clear VimrexSearchPattern
627         syntax clear VimrexSearchToken
628         if exists("g:VimRegEx")
629                 call s:undoGlobals()
630                 :qa!
631         endif
632         call s:undoGlobals()
633 endfunction
635 command! -nargs=0 Vimrex call s:Vimrex()
636 command! -nargs=0 VimRegEx  if has("gui_running") | execute ':silent! :!gvim -c "let g:VimRegEx=1" -c Vimrex' | else | execute ':silent! :!vim -c "let g:VimRegEx=1" -c Vimrex' | endif
638 " Vimrex initialization function
639 function! s:Vimrex()
640         call s:doGlobals()
641 augroup Vimrex
642         autocmd!
643         autocmd VimLeavePre,VimLeave,BufDelete * call s:isVimrexRunning(expand("<afile>"))
644         autocmd WinLeave,WinEnter,BufDelete,BufWinEnter,BufWinLeave * call s:legend()
645 augroup END
646         let s:saveSyn=&syntax
647         let s:pattern=@/
648         let s:saveHLS=&hlsearch
649         let s:saveCH=&ch
650         let s:saveCPO=&cpoptions
651         let s:AanchorPat=''
652         let s:BanchorPat=''
653         set cpoptions-=C
654         set ch=3
655         set nohlsearch
656         let @/=''
657         let g:VimrexRunning=1
658         let g:VimRexUserCalled=nr2char(21).nr2char(19).nr2char(5).nr2char(18).nr2char(3).nr2char(1).nr2char(12).nr2char(12).nr2char(5).nr2char(4)
659         if getline(1) !~ '^\%$'
660                 new
661         endif
662         if has("gui_running")
663                 call s:doGvimMenu()
664                 if has("gui_win32")
665                         tearoff &Vimrex
666                 elseif has("gui_gtk")
667                         popup &Vimrex
668                 endif
669         endif
670         execute 'edit! '.escape(g:VimrexSrcFile,' ')
671         if getline(1) =~ '^\%$'
672                 call s:doSampleSrc()
673         endif
674         setlocal nomodified noswapfile nobackup nowritebackup nonumber syntax= filetype=
675         call s:delFile(g:VimrexRsltFile)
676         execute 'split '.escape(g:VimrexRsltFile,' ')
677         setlocal noswapfile nobackup nowritebackup nonumber syntax= filetype=
678         execute 'split! '.escape(g:VimrexFile,' ')
679         if getline(1) =~ '^\%$'
680                 call s:doSampleRegex()
681         endif
682         setlocal nomodified noswapfile nobackup nowritebackup nonumber syntax=vim filetype=vim
683         if exists("g:VimrexSrchPatLnk")
684                 execute 'highlight link VimrexSearchPattern '.g:VimrexSrchPatLnk
685         else
686                 execute 'highlight VimrexSearchPattern ctermfg='.g:VimrexSrchPatCFG.' ctermbg='.g:VimrexSrchPatCBG.' guifg='.g:VimrexSrchPatGFG.' guibg='.g:VimrexSrchPatGBG
687         endif
688         if exists("g:VimrexSrchAncLnk")
689                 execute 'highlight link VimrexSearchAnchor '.g:VimrexSrchAncLnk
690         else
691                 execute 'highlight VimrexSearchAnchor ctermfg='.g:VimrexSrchAncCFG.' ctermbg='.g:VimrexSrchAncCBG.' guifg='.g:VimrexSrchAncGFG.' guibg='.g:VimrexSrchAncGBG
692         endif
693         if exists("g:VimrexSrchTokLnk")
694                 execute 'highlight link VimrexSearchToken '.g:VimrexSrchTokLnk
695         else
696                 execute 'highlight VimrexSearchToken ctermfg='.g:VimrexSrchTokCFG.' ctermbg='.g:VimrexSrchTokCBG.' guifg='.g:VimrexSrchTokGFG.' guibg='.g:VimrexSrchTokGBG
697         endif
698         if exists("g:VimrexSrchCgpLnk")
699                 execute 'highlight link VimrexSearchCgp '.g:VimrexSrchCgpLnk
700         else
701                 execute 'highlight VimrexSearchCgp ctermfg='.g:VimrexSrchCgpCFG.' ctermbg='.g:VimrexSrchCgpCBG.' guifg='.g:VimrexSrchCgpGFG.' guibg='.g:VimrexSrchCgpGBG
702         endif
703         if exists("g:VimrexSrchGrpLnk")
704                 execute 'highlight link VimrexSearchGrp '.g:VimrexSrchGrpLnk
705         else
706                 execute 'highlight VimrexSearchGrp ctermfg='.g:VimrexSrchGrpCFG.' ctermbg='.g:VimrexSrchGrpCBG.' guifg='.g:VimrexSrchGrpGFG.' guibg='.g:VimrexSrchGrpGBG
707         endif
708         if exists("g:VimrexSrchChcLnk")
709                 execute 'highlight link VimrexSearchChc '.g:VimrexSrchChcLnk
710         else
711                 execute 'highlight VimrexSearchChc ctermfg='.g:VimrexSrchChcCFG.' ctermbg='.g:VimrexSrchChcCBG.' guifg='.g:VimrexSrchChcGFG.' guibg='.g:VimrexSrchChcGBG
712         endif
713         if exists("g:VimrexSrchExpLnk")
714                 execute 'highlight link VimrexSearchExp '.g:VimrexSrchExpLnk
715         else
716                 execute 'highlight VimrexSearchExp ctermfg='.g:VimrexSrchExpCFG.' ctermbg='.g:VimrexSrchExpCBG.' guifg='.g:VimrexSrchExpGFG.' guibg='.g:VimrexSrchExpGBG
717         endif
718         if exists("g:VimrexFilePatLnk")
719                 execute 'highlight link VimrexFilePattern '.g:VimrexFilePatLnk
720         else
721                 execute 'highlight VimrexFilePattern ctermfg='.g:VimrexFilePatCFG.' ctermbg='.g:VimrexFilePatCBG.' guifg='.g:VimrexFilePatGFG.' guibg='.g:VimrexFilePatGBG
722         endif
723         call s:doMap('Exec',':call <SID>execRegex()')
724         call s:doMap('Anlz',':call TranslateRegex()')
725         call s:doMap('Top',':call <SID>gotoWin(g:VimrexFile)')
726         call s:doMap('Btm',':call <SID>gotoWin(g:VimrexSrcFile)')
727         call s:doMap('Ctr',':call <SID>gotoWin(g:VimrexRsltFile)')
728         call s:doMap('CLS',':call <SID>cls(g:VimrexFile)')
729         call s:doMap('DSrc',':call <SID>cls(g:VimrexSrcFile)')
730         call s:doMap('DRslt',':call <SID>cls(g:VimrexRsltFile)')
731         call s:doMap('RdSrc',':call <SID>browser(g:VimrexSrcFile)')
732         call s:doMap('RdRex',':call <SID>browser(g:VimrexFile)')
733         call s:doMap('QQ',':call <SID>usage()')
734         call s:doMap('QC',':call <SID>adjustWin(g:VimrexUsageFile,"c")')
735         call s:doMap('QP',':call <SID>adjustWin(g:VimrexUsageFile,"p")')
736         call s:doMap('QL',':call <SID>closeUsage()')
737         call s:doMap('ZHV',':call <SID>generate(g:VimrexFile,"HTML")')
738         call s:doMap('ZHS',':call <SID>generate(g:VimrexSrcFile,"HTML")')
739         call s:doMap('ZHU',':call <SID>generate(g:VimrexUsageFile,"HTML")')
740         call s:doMap('ZHR',':call <SID>generate(g:VimrexUsageFile,"HTML")')
741         call s:doMap('ZHA',':call <SID>generate("ALLBUTUSAGE","HTML")')
742         call s:doMap('ZTV',':call <SID>generate(g:VimrexFile,"TEXT")')
743         call s:doMap('ZTS',':call <SID>generate(g:VimrexSrcFile,"TEXT")')
744         call s:doMap('ZTU',':call <SID>generate(g:VimrexUsageFile,"TEXT")')
745         call s:doMap('ZTR',':call <SID>generate(g:VimrexUsageFile,"TEXT")')
746         call s:doMap('ZTA',':call <SID>generate("ALLBUTUSAGE","TEXT")')
747         call s:doMap('Exit',':call <SID>isVimrexRunning(g:VimRexUserCalled)')
748 endfunction
750 function! s:doSampleRegex()
751         call append(0,s:sampleRegex1)
752         let nr=2
753         normal G
754         normal dd
755         while nr < 29
756                 call append('$',s:sampleRegex{nr})
757                 let nr=nr+1
758         endwhile
759 endfunction
761 function! s:doSampleSrc()
762         call append(0,s:sampleSrc1)
763         let nr=2
764         normal G
765         normal dd
766         while nr < 18
767                 call append('$',s:sampleSrc{nr})
768                 let nr=nr+1
769         endwhile
770 endfunction
772 function! s:patHilite(pat,grp,...)
773         let thePat=''
774         if a:0
775                 let thePat='\%'.a:1.'l'
776                 if a:0 > 1
777                         let thePat=thePat.'\&\%'.a:2.'c'
778                 endif
779         endif
780         let thePat=thePat.'\%('.escape(a:pat[0],'\[^*$~"').'\)'
781         let idx=1
782         let lidx=strlen(a:pat)
783         while idx < lidx
784                 let theGrp='\%('.escape(a:pat[idx],'\[^*$~"').'\)'
785                 let thePat=thePat.theGrp.'\@='.theGrp
786                 let idx=idx+1
787         endwhile
788         execute 'syntax match '.a:grp.' "'.thePat.'"'
789         syntax sync fromstart
790 endfunction
792 function! s:getAnchors(pat)
793         let pat=a:pat
794         let s:BanchorPat=''
795         let s:AanchorPat=''
796         let matchPos=match(pat,'\\@\%[<][=!]')
797         let anchorStr=matchstr(pat,'\\@\%[<][=!]')
798         while matchPos != -1
799                 let idx=matchPos-1
800                 let found=0
801                 while idx >= 0 && !found
802                         if pat[idx] == '\*' && pat[idx-1] != '\'
803                                 let idx=idx-1
804                                 continue
805                         endif
806                         if pat[idx] == '}' && pat[idx-1] != '\'
807                                 let idx=idx-1
808                                 let tmpPat=strpart(pat,idx)
809                                 while match(tmpPat,'\{') != 0
810                                         let idx=idx-1
811                                         let tmpPat=strpart(pat,idx)
812                                 endwhile
813                                 if match(tmpPat,'\{') == 0
814                                         let idx=idx-1
815                                         continue
816                                 endif
817                         endif
818                         if pat[idx] =~ ')' && pat[idx-1] == '\'
819                                 let idx=idx-2
820                                 while pat[idx] != '('
821                                         let idx=idx-1
822                                 endwhile
823                                 if pat[idx] =~ '(' && pat[idx-1] == '\' && pat[idx-2] != '\'
824                                         let idx=idx-1
825                                         let found=1
826                                 endif
827                                 if pat[idx] == '(' && pat[idx-1] == '%' && pat[idx-2] == '\' && pat[idx-3] != '\'
828                                         let idx=idx-2
829                                         let found=1
830                                 endif
831                         endif
832                         let found=1
833                 endwhile
834                 if match(anchorStr,'<') != -1
835                         if s:BanchorPat == ''
836                                 let s:BanchorPat=strpart(pat,idx,matchPos-idx)
837                         else
838                                 let s:BanchorPat=s:BanchorPat."\<NL>".strpart(pat,idx,matchPos-idx)
839                         endif
840                 else
841                         if s:AanchorPat == ''
842                                 let s:AanchorPat=strpart(pat,idx,matchPos-idx)
843                         else
844                                 let s:AanchorPat=s:AanchorPat."\<NL>".strpart(pat,idx,matchPos-idx)
845                         endif
846                 endif
847                 let pat=strpart(pat,matchPos+2)
848                 let matchPos=match(pat,'\\@')
849                 let anchorStr=matchstr(pat,'\\@\%[<][=!]')
850         endwhile
851 endfunction
853 let s:grp=''
854 let s:capgrp=''
855 let s:choice=''
856 let s:expansion=''
857 let s:class=''
858 let s:grpOpen='\\(\|\\%(\|\\%[\|[:\@!'
859 let s:grpClose='\\)\|]'
861 function! s:parsePat(pat)
862         let s:grp=''
863         let s:capgrp=''
864         let s:choice=''
865         let s:expansion=''
866         let idx=0
867         let lidx=strlen(a:pat)
868         while idx < lidx
869                 let restPat=strpart(a:pat,idx)
870                 let firstPat=strpart(a:pat,0,idx)
871                 let atomIdx=0
872                 if match(restPat,s:grpOpen) == 0
873                         let opengrp=matchstr(restPat,s:grpOpen)
874                         let atomIdx=strlen(matchstr(restPat,s:grpOpen))
875                         let ingroup=1
876                         while ingroup && restPat[atomIdx] != ''
877                                 let tmpPat=strpart(restPat,atomIdx)
878                                 if match(tmpPat,s:grpOpen) == 0 && restPat[atomIdx-1] != '\'
879                                         let atomIdx=strlen(matchstr(tmpPat,s:grpOpen))+atomIdx
880                                         let ingroup=ingroup+1
881                                 elseif match(tmpPat,s:grpClose) == 0 && restPat[atomIdx-1] != '\'
882                                         if tmpPat[0] == ']'
883                                                 if restPat[atomIdx-1] == ':' && restPat[atomIdx-2] != '\'
884                                                         let atomIdx=atomIdx+1
885                                                         continue
886                                                 endif
887                                         endif
888                                         let closegrp=matchstr(tmpPat,s:grpClose)
889                                         let closepos=atomIdx
890                                         let atomIdx=strlen(matchstr(tmpPat,s:grpClose))+atomIdx
891                                         let afterpos=atomIdx
892                                         let ingroup=ingroup-1
893                                 else
894                                         let atomIdx=atomIdx+1
895                                 endif
896                         endwhile
897                         if !ingroup
898                                 let tmpPat=strpart(restPat,atomIdx)
899                                 let modMatch=match(tmpPat,'\*\|\\[+?=]\|\\@\%[<][!=]\|\\{\%[-]\%[+]\d*\%[,]\d*}')
900                                 if modMatch == 0
901                                         let modStr=matchstr(tmpPat,'\*\|\\[+?=]\|\\@\%[<][!=]\|\\{\%[-]\%[+]\d*\%[,]\d*}')
902                                         let atomIdx=atomIdx+strlen(modStr)
903                                 endif
904                         endif
905                         let theGrp=strpart(restPat,0,atomIdx)
906                         let restPat=strpart(restPat,atomIdx)
907                         if firstPat != ''
908                                 let theGrp='\%('.firstPat.'\)\@<=\%('.theGrp.'\)'
909                         else
910                                 let theGrp='\%('.theGrp.'\)'
911                         endif
912                         if restPat != ''
913                                 let theGrp=theGrp.'\%('.restPat.'\)\@='
914                         endif
915                         if opengrp == '\('
916                                 let targetGrp='s:capgrp'
917                         elseif opengrp == '\%('
918                                 let targetGrp='s:grp'
919                         elseif opengrp == '\%['
920                                 let targetGrp='s:expansion'
921                         else
922                                 let targetGrp='s:choice'
923                         endif
924                         let thisGrp=StrListTok({targetGrp},'g:grpList',"\<NL>")
925                         let found=0
926                         while thisGrp != ''
927                                 if thisGrp ==# theGrp
928                                         let found=1
929                                         while thisGrp != ''
930                                                 let thisGrp=StrListTok('','g:grpList')
931                                         endwhile
932                                 endif
933                                 let thisGrp=StrListTok('','g:grpList')
934                         endwhile
935                         unlet! g:grpList
936                         if !found
937                                 let {targetGrp}={targetGrp}.theGrp."\<NL>"
938                         endif
939                 endif
940                 if atomIdx
941                         let idx=idx+atomIdx-1
942                 else
943                         let idx=idx+1
944                 endif
945         endwhile
946 endfunction
948 let s:hit=0
949 let s:lline=1
950 let s:lpat=''
951 let s:rline=0
953 function! s:execRegex()
954         let caller=winnr()
955         execute bufwinnr(g:VimrexFile).'wincmd w'
956         let pattern=getline('.')
957         if pattern == ''
958                 echohl Errormsg
959                 echomsg "No search pattern specified"
960                 echohl None
961                 execute caller.'wincmd w'
962                 return
963         endif
964         let sameregex=(s:rline == line('.') && s:lpat ==# pattern)
965         if !sameregex
966                 if match(pattern,'\s*"') == 0
967                         echohl Warningmsg
968                         let ans=input("This could be a comment line, execute? ","n")
969                         echohl None
970                         if tolower(ans[0]) == 'n'
971                                 execute caller.'wincmd w'
972                                 return
973                         endif
974                 endif
975                 syntax clear VimrexFilePattern
976                 let s:rline=line('.')
977                 let s:lpat=pattern
978                 call s:patHilite(pattern,'VimrexFilePattern',s:rline)
979                 let @/=pattern
980                 call s:parsePat(pattern)
981                 if match(pattern,'\\@') != -1
982                         call s:getAnchors(pattern)
983                 else
984                         let s:BanchorPat=''
985                         let s:AanchorPat=''
986                 endif
987         endif
988         execute bufwinnr(g:VimrexSrcFile).'wincmd w'
989         let v:errmsg=''
990         silent! normal n
991         if v:errmsg != ''
992                 execute bufwinnr(g:VimrexRsltFile).'wincmd w'
993                 normal gg
994                 call append(line('.'),">>".pattern."<< search error: ".v:errmsg)
995                 setlocal nomodified
996                 echohl Errormsg
997                 echomsg ">>".pattern."<< search error: ".v:errmsg
998                 echohl None
999                 execute bufwinnr(g:VimrexSrcFile).'wincmd w'
1000                 execute caller.'wincmd w'
1001                 return
1002         endif
1003         syntax clear VimrexSearchAnchor
1004         syntax clear VimrexSearchPattern
1005         syntax clear VimrexSearchToken
1006         syntax clear VimrexSearchCgp
1007         syntax clear VimrexSearchGrp
1008         syntax clear VimrexSearchChc
1009         syntax clear VimrexSearchExp
1010         let lnum=line('.')
1011         let cnum=col('.')
1012         let sline=getline('.')
1013         let matchPos=cnum-1
1014         if cnum == 1
1015                 if lnum == 1
1016                         call cursor(line('$'),col('$'))
1017                         call cursor(line('$'),col('$'))
1018                 else
1019                         call cursor(lnum-1,col('$'))
1020                         call cursor(lnum-1,col('$'))
1021                 endif
1022         else
1023                 call cursor(lnum,cnum-1)
1024         endif
1025         execute "silent! normal //e\<CR>"
1026         let matchEnd=col('.')
1027         let s:hit=s:hit+1
1028         if lnum < s:lline
1029                 let s:hit=1
1030         endif
1031         let s:lline=lnum
1032         let token=strpart(sline,matchPos,matchEnd-matchPos)
1033         if s:BanchorPat != ''
1034                 let thisAnchor=StrListTok(s:BanchorPat,'b:anchors',"\<NL>")
1035                 while thisAnchor != ''
1036                         let matchAnchor=match(sline,thisAnchor)
1037                         while matchAnchor != -1
1038                                 let matchAnchorEnd=matchend(sline,thisAnchor,matchAnchor)
1039                                 if matchAnchorEnd == matchPos
1040                                         let cnum=matchAnchor+1
1041                                         execute 'syntax match VimrexSearchAnchor        "\%'.lnum.'l\&\%'.cnum.'c'.escape(thisAnchor,'"').'"'
1042                                         break
1043                                 endif
1044                                 let matchAnchor=match(sline,thisAnchor,matchAnchor+1)
1045                         endwhile
1046                         let thisAnchor=StrListTok('','b:anchors')
1047                 endwhile
1048                 unlet b:anchors
1049         endif
1050         if s:AanchorPat != ''
1051                 let thisAnchor=StrListTok(s:AanchorPat,'b:anchors',"\<NL>")
1052                 while thisAnchor != ''
1053                         let tokenLen=strlen(token)
1054                         let matchAnchor=match(strpart(sline,matchPos+tokenLen),thisAnchor)
1055                         if matchAnchor != -1
1056                                 let cnum=matchAnchor+matchPos+tokenLen+1
1057                                 if cnum == (matchEnd+1)
1058                                         execute 'syntax match VimrexSearchAnchor        "\%'.lnum.'l\&\%'.cnum.'c'.escape(thisAnchor,'"').'"'
1059                                 endif
1060                         endif
1061                         let thisAnchor=StrListTok('','b:anchors')
1062                 endwhile
1063                 unlet b:anchors
1064         endif
1065         execute 'syntax match VimrexSearchPattern       "'.escape(pattern,'"').'" contains=VimrexSearchToken'
1066         let cnum=matchPos+1
1067         execute 'syntax match VimrexSearchToken "\%'.lnum.'l\&\%'.cnum.'c'.escape(token,'~"\[]*').'" contained contains=VimrexSearchCgp,VimrexSearchGrp,VimrexSearchChc,VimrexSearchExp'
1068         call s:hiliteGrp(s:capgrp,'VimrexSearchCgp',lnum,matchPos)
1069         call s:hiliteGrp(s:grp,'VimrexSearchGrp',lnum,matchPos)
1070         call s:hiliteGrp(s:choice,'VimrexSearchChc',lnum,matchPos)
1071         call s:hiliteGrp(s:expansion,'VimrexSearchExp',lnum,matchPos)
1072         syntax sync fromstart
1073         execute bufwinnr(g:VimrexRsltFile).'wincmd w'
1074         normal gg
1075         call append(line('.'),s:hit.": Length=".strlen(token).", at line #".lnum.", column #".cnum)
1076         call append(line('.'),s:hit.": Token: >>".token."<<")
1077         call append(line('.'),s:hit.": Found: >>".pattern."<<")
1078         setlocal nomodified
1079         execute bufwinnr(g:VimrexSrcFile).'wincmd w'
1080         call cursor(lnum,cnum)
1081         execute caller.'wincmd w'
1082 endfunction
1084 function! s:hiliteGrp(which,synGrp,lnum,matchPos)
1085         let sline=getline(a:lnum)
1086         let grp=StrListTok(a:which,'g:VimrexHLgrp',"\<NL>")
1087         while grp != ''
1088                 let strt=0
1089                 let grpTokStrt=match(sline,grp,strt)
1090                 while grpTokStrt != -1
1091                         let grpTok=matchstr(sline,grp,strt)
1092                         if grpTok != ''
1093                                 let grpTokEnd=strlen(grpTok)+grpTokStrt
1094                                 let grpCnum=1+grpTokStrt
1095                                 execute 'syntax match '.a:synGrp.'      "\%'.a:lnum.'l\&\%'.grpCnum.'c'.escape(grpTok,'~"\[]*').'" contained'
1096                         else
1097                                 let grpTokEnd=grpTokStrt+1
1098                         endif
1099                         let strt=grpTokEnd
1100                         let grpTokStrt=match(sline,grp,strt)
1101                 endwhile
1102                 let grp=StrListTok('','g:VimrexHLgrp')
1103         endwhile
1104         unlet! g:VimrexHLgrp
1105 endfunction
1107 function! s:saveCurrent()
1108         let s:cWin=winnr()
1109         let s:cBuf=bufnr('')
1110         let s:clnum=line('.')
1111         let s:ccnum=col('.')
1112 endfunction
1114 function! s:restoreCurrent()
1115         if winnr() != s:cWin
1116                 execute s:cWin.'wincmd w'
1117         endif
1118         execute 'b'.s:cBuf
1119         call cursor(s:clnum,s:ccnum)
1120 endfunction
1122 function! s:cls(which)
1123         if a:which == g:VimrexFile || a:which == g:VimrexSrcFile
1124                 let ans=confirm("Clear ".a:which,"&Ok\n&Cancel",1)
1125                 if ans == 0 || ans == 2
1126                         return
1127                 endif
1128         endif
1129         call s:saveCurrent()
1130         execute bufwinnr(a:which).'wincmd w'
1131         normal gg
1132         normal ma
1133         normal G
1134         silent normal d'a
1135         set nomodified
1136         call s:restoreCurrent()
1137         if a:which == g:VimrexFile
1138                 let @/=''
1139         endif
1140 endfunction
1142 function! s:delFile(fname)
1143         let fname=glob(a:fname)
1144         if fname == ''
1145                 return
1146         endif
1147         let failure=delete(fname)
1148         if !failure
1149                 return
1150         endif
1151         echohl Warningmsg
1152         echomsg expand("<sfile>").": Could not delete <".fname.">"
1153         echomsg "Reason: ".v:errmsg
1154         echohl Cursor
1155         echomsg "        Press a key to continue"
1156         echohl None
1157         call getchar()
1158 endfunction
1160 function! TranslateRegex(...)
1161         let doLocal=!a:0
1162         if doLocal
1163                 execute bufwinnr(g:VimrexFile).'wincmd w'
1164                 let s:pat=getline('.')
1165                 if s:pat == ''
1166                         echohl Errormsg
1167                         echomsg "No search pattern specified"
1168                         echohl None
1169                         return
1170                 endif
1171                 let sameregex=(s:rline == line('.') && s:lpat ==# s:pat)
1172                 if !sameregex
1173                         if match(s:pat,'\s*"') == 0
1174                                 echohl Warningmsg
1175                                 let ans=input("This could be a comment line, execute? ","n")
1176                                 echohl None
1177                                 if tolower(ans[0]) == 'n'
1178                                         return
1179                                 endif
1180                         endif
1181                         syntax clear VimrexFilePattern
1182                         let s:rline=line('.')
1183                         let s:lpat=s:pat
1184                         call s:patHilite(s:pat,'VimrexFilePattern',s:rline)
1185                         let @/=s:pat
1186                         call s:parsePat(s:pat)
1187                         if match(s:pat,'\\@') != -1
1188                                 call s:getAnchors(s:pat)
1189                         else
1190                                 let s:BanchorPat=''
1191                                 let s:AanchorPat=''
1192                         endif
1193                         execute bufwinnr(g:VimrexSrcFile).'wincmd w'
1194                         syntax clear VimrexSearchAnchor
1195                         syntax clear VimrexSearchPattern
1196                         syntax clear VimrexSearchToken
1197                         syntax clear VimrexSearchCgp
1198                         syntax clear VimrexSearchGrp
1199                         syntax clear VimrexSearchChc
1200                         syntax clear VimrexSearchExp
1201                 endif
1202                 execute bufwinnr(g:VimrexRsltFile).'wincmd w'
1203                 let b:pat=s:pat
1204                 unlet s:pat
1205                 normal G
1206                 call append(line('$'),'Analyzing pattern: '.b:pat)
1207                 setlocal nomodified
1208                 normal j
1209                 execute "normal z\<CR>"
1210         else
1211                 let b:pat=a:1
1212                 echomsg 'Analyzing pattern: '.b:pat
1213         endif
1214         while b:pat != ''
1215                 let desc=s:getTokDesc(b:pat,'b:foundPat','b:pat')
1216                 let pad=''
1217                 if s:ingroup
1218                         let indents=s:ingroup
1219                         if match(b:foundPat,'^\%(\\(\|\\%(\|[\|\\%[\):\@!') != -1
1220                                 let indents=indents-1
1221                         endif
1222                         while indents
1223                                 let spaces=&sw
1224                                 while spaces
1225                                         let pad=pad.' '
1226                                         let spaces=spaces-1
1227                                 endwhile
1228                                 let indents=indents-1
1229                         endwhile
1230                 endif
1231                 if doLocal
1232                         call append(line('$'),pad.b:foundPat.'  >>:'.desc)
1233                         setlocal nomodified
1234                 else
1235                         echomsg pad.b:foundPat.'  >>:'.desc
1236                 endif
1237         endwhile
1238         unlet! b:pat b:foundPat
1239         if doLocal
1240                 execute bufwinnr(g:VimrexFile).'wincmd w'
1241         endif
1242 endfunction
1244 function! s:repeatAtomDesc(qualifier)
1245         let qualifier=a:qualifier
1246         if qualifier == '' || match(qualifier,'\d*,\d*') != -1 || match(qualifier,'\%(+\|-\)') != -1
1247                 let qualify=match(qualifier,'-') != -1 ? 'few as possible "lazy"' : 'all possible "greedy"'
1248                 if qualify[0] == 'f'
1249                         let qualifier=strpart(qualifier,1)
1250                 endif
1251                 let theDesc=qualify.' match'
1252                 if qualifier != ''
1253                         let commaPos=match(qualifier,',')
1254                         let low=strpart(qualifier,0,commaPos)
1255                         let high=strpart(qualifier,commaPos+1)
1256                         if low != ''
1257                                 let theDesc=theDesc.' from '.low
1258                         else
1259                                 let theDesc=theDesc.' from 0'
1260                         endif
1261                         if high != ''
1262                                 let theDesc=theDesc.' to '.high.' of previous atom'
1263                         else
1264                                 let theDesc=theDesc.' to maximum of previous atom'
1265                         endif
1266                 else
1267                         let theDesc=theDesc.' of 0 or more of previous atom'
1268                 endif
1269         else
1270                 let theDesc='exactly '.qualifier.' of previous atom'
1271         endif
1272         return theDesc
1273 endfunction
1275 function! s:charClassDesc(class)
1276         let theClass=StrListTok(s:charClass,'b:charClass',"\<NL>")
1277         let found=0
1278         while theClass != '' && !found
1279                 if theClass ==# a:class
1280                         let theDesc=StrListTok('','b:charClass')
1281                         while StrListTok('','b:charClass') != ''
1282                         endwhile
1283                         let found=1
1284                         break
1285                 endif
1286                 let theClass=StrListTok('','b:charClass')
1287         endwhile
1288         unlet b:charClass
1289         if !found
1290                 let theDesc='Unknown class'
1291         endif
1292         return theDesc
1293 endfunction
1295 function! s:getTokDesc(pat,thePat,retPat)
1296         let idx=0
1297         let lidx=strlen(a:pat)
1298         let found=0
1299         let opener=matchstr(a:pat,'^\%(\\(\|\\%(\|[\|\\%[\):\@!')
1300         if opener != ''
1301                 let s:ingroup=s:ingroup+1
1302         endif
1303         let closer=matchstr(a:pat,'^\%(\\)\|]\):\@!')
1304         if closer != ''
1305                 let s:ingroup=s:ingroup-1
1306                 if closer == ']'
1307                         if s:inChoice
1308                                 let s:inChoice=0
1309                         elseif s:inExpansion
1310                                 let s:inExpansion=0
1311                         endif
1312                 endif
1313         endif
1314         let matchPos=match(a:pat,'\%(\[:\)\@<=\%(\a\+\%(:]\)\@=\)')
1315         if matchPos == 2
1316                 let matchEnd=matchend(a:pat,'\%(\[:\)\@<=\%(\a\+\%(:]\)\@=\)')
1317                 let qualifier='[:'.matchstr(a:pat,'\%(\[:\)\@<=\%(\a\+\%(:]\)\@=\)').':]'
1318                 let {a:retPat}=strpart(a:pat,matchEnd+2)
1319                 let {a:thePat}=strpart(a:pat,0,matchEnd+2)
1320                 return s:charClassDesc(qualifier)
1321         endif
1322         if s:inExpansion && a:pat[0] != ']' && a:pat[0] != '[' && a:pat[0] != '\'
1323                 let matchPos=match(a:pat,'\%(]\|[\|\\\)')
1324                 if a:pat[matchPos] == ']'
1325                         let s:inExpansion=0
1326                 endif
1327                 let {a:retPat}=strpart(a:pat,matchPos)
1328                 let thePat=strpart(a:pat,0,matchPos)
1329                 let {a:thePat}=thePat
1330                 return 'literal character(s): >>'.substitute(thePat,'\%(\\\)\%(\\\|-\)\@=','','g').'<<'
1331         endif
1332         if s:inChoice && a:pat[0] != ']'
1333                 let matchPos=match(a:pat,'\%(]\|\[:\)')
1334                 if a:pat[matchPos] == ']'
1335                         let s:inChoice=0
1336                 endif
1337                 let {a:retPat}=strpart(a:pat,matchPos)
1338                 let thePat=strpart(a:pat,0,matchPos)
1339                 let {a:thePat}=thePat
1340                 return 'literal character(s): >>'.substitute(thePat,'\%(\\\)\%(\\\|-\)\@=','','g').'<<'
1341         endif
1342         let matchPos=match(a:pat,'\%(\\{\)\@<=\%(\%(\%(-\|+\)\?\d*,\?\d*\)}\@=\)')
1343         if matchPos == 2
1344                 let matchEnd=matchend(a:pat,'\%(\\{\)\@<=\%(\%(\%(-\|+\)\?\d*,\?\d*\)}\@=\)')
1345                 let qualifier=matchstr(a:pat,'\%(\\{\)\@<=\%(\%(\%(-\|+\)\?\d*,\?\d*\)}\@=\)')
1346                 let {a:retPat}=strpart(a:pat,matchEnd+1)
1347                 let {a:thePat}=strpart(a:pat,0,matchEnd+1)
1348                 return s:repeatAtomDesc(qualifier)
1349         endif
1350         if a:pat[0] == '\' && a:pat[1] =~ '\d'
1351                 let matchBeg=match(a:pat,'\d\+',1)
1352                 let matchEnd=matchend(a:pat,'\d\+',1)
1353                 let {a:retPat}=strpart(a:pat,matchEnd)
1354                 let theNum=strpart(a:pat,1,matchEnd)
1355                 let {a:thePat}='\'.theNum
1356                 let theDesc="back reference to capture group ".theNum." in this pattern"
1357                 return theDesc
1358         endif
1359         if a:pat[0] == '\'
1360                 if match(s:VimRegExTokBS1stChar,a:pat[1]) == -1 || a:pat[1] == '.'
1361                         let idx=2
1362                         while match(s:VimRegExTokOpen,escape(a:pat[idx],'$~.^')) == -1
1363                                 let idx=idx+1
1364                         endwhile
1365                         let {a:retPat}=strpart(a:pat,idx)
1366                         let {a:thePat}=strpart(a:pat,0,idx)
1367                         return 'literal character(s): >>'.strpart(a:pat,1,idx-1).'<<'
1368                 endif
1369         endif
1370         if match(s:VimRegExTokOpen,escape(a:pat[0],'$~^*.')) == -1
1371                 let idx=idx+1
1372                 while match(s:VimRegExTokOpen,escape(a:pat[idx],'$~.^')) == -1
1373                         let idx=idx+1
1374                 endwhile
1375                 let {a:retPat}=strpart(a:pat,idx)
1376                 let {a:thePat}=strpart(a:pat,0,idx)
1377                 return 'literal character(s): >>'.strpart(a:pat,0,idx).'<<'
1378         endif
1379         if match(a:pat,'^\\%[') != -1
1380                 let s:inExpansion=1
1381         endif
1382         if a:pat[0] == '['
1383                 let s:inChoice=1
1384                 if a:pat[1] == '^'
1385                         let {a:retPat}=strpart(a:pat,2)
1386                         let {a:thePat}='[^'
1387                         return 'begin disallowed choice list'
1388                 else
1389                         let {a:retPat}=strpart(a:pat,1)
1390                         let {a:thePat}='['
1391                         return 'begin allowed choice list'
1392                 endif
1393         endif
1394         while idx < lidx && !found
1395                 let thisPat=StrListTok(s:VimRegExTokDesc,'b:thisTokDescList',"\<NL>")
1396                 let matchPat=strpart(a:pat,0,idx+1)
1397                 while thisPat != ''
1398                         let theDesc=StrListTok('','b:thisTokDescList')
1399                         if matchPat ==# '^'
1400                                 let thisPat='^'
1401                                 let theDesc='begin line'
1402                                 while StrListTok('','b:thisTokDescList') != ''
1403                                 endwhile
1404                                 let found=1
1405                                 break
1406                         endif
1407                         if matchPat ==# thisPat
1408                                 while StrListTok('','b:thisTokDescList') != ''
1409                                 endwhile
1410                                 let found=1
1411                                 break
1412                         endif
1413                         let thisPat=StrListTok('','b:thisTokDescList')
1414                 endwhile
1415                 let idx=idx+1
1416         endwhile
1417         if thisPat == ''
1418                 let {a:retPat}=''
1419                 let {a:thePat}=a:pat
1420                 unlet! b:thisTokDescList
1421                 return 'literal character(s): >>'.a:pat.'<<'
1422         endif
1423         let {a:retPat}=strpart(a:pat,idx)
1424         let {a:thePat}=thisPat
1425         unlet! b:thisTokDescList
1426         return theDesc
1427 endfunction
1429 if exists('loaded_regex_token_descriptions')
1430         finish
1431 endif
1432 let loaded_regex_token_descriptions=1
1433 let s:VimRegExTokBS1stChar='%|&+<=>?@ACDFHIKLMOPSUVWXZ_abcdefhiklmnoprstuvwxz()\'
1435 let s:ingroup=0
1436 let s:inChoice=0
1437 let s:inExpansion=0
1438 let s:charClass=
1440 \[:alnum:]\<NL>
1441 \letters and decimal digits\<NL>
1442 \[:alpha:]\<NL>
1443 \letters\<NL>
1444 \[:blank:]\<NL>
1445 \space and tab\<NL>
1446 \[:cntrl:]\<NL>
1447 \control\<NL>
1448 \[:digit:]\<NL>
1449 \decimal digits\<NL>
1450 \[:graph:]\<NL>
1451 \printable except space\<NL>
1452 \[:lower:]\<NL>
1453 \lowercase\<NL>
1454 \[:print:]\<NL>
1455 \printable including space\<NL>
1456 \[:punct:]\<NL>
1457 \punctuation\<NL>
1458 \[:space:]\<NL>
1459 \whitespace\<NL>
1460 \[:upper:]\<NL>
1461 \uppercase\<NL>
1462 \[:xdigit:]\<NL>
1463 \hexadecimal digits\<NL>
1464 \[:return:]\<NL>
1465 \carriage return (non-POSIX)\<NL>
1466 \[:tab:]\<NL>
1467 \tab (non-POSIX)\<NL>
1468 \[:escape:]\<NL>
1469 \esc (non-POSIX)\<NL>
1470 \[:backspace:]\<NL>
1471 \bs (non-POSIX)"
1473 let s:VimRegExTokOpen='$\\~^*.[]'
1474 let s:VimRegExTokDesc="
1475                         \$\<NL>
1476                         \end of line\<NL>
1477                         \*\<NL>
1478                         \0 or more of previous atom\<NL>
1479                         \.\<NL>
1480                         \any but newline\<NL>
1481                         \]\<NL>
1482                         \end choice list or expansion sequence\<NL>
1483                         \\\%[\<NL>
1484                         \begin expansion sequence\<NL>
1485                         \\\%$\<NL>
1486                         \end of file or string\<NL>
1487                         \\\&\<NL>
1488                         \previous atom and next atom are required together ('and')\<NL>
1489                         \\\|\<NL>
1490                         \previous atom and next atom are alternate choices ('or')\<NL>
1491                         \\\(\<NL>
1492                         \begin capture group\<NL>
1493                         \\\)\<NL>
1494                         \end group\<NL>
1495                         \\\%(\<NL>
1496                         \begin non-capture group\<NL>
1497                         \\\)\<NL>
1498                         \end group\<NL>
1499                         \\\%^\<NL>
1500                         \start of file or string\<NL>
1501                         \\\+\<NL>
1502                         \1 or more of previous atom\<NL>
1503                         \\\<\<NL>
1504                         \begin word boundary\<NL>
1505                         \\\=\<NL>
1506                         \0 or 1 of previous atom\<NL>
1507                         \\\>\<NL>
1508                         \end word boundary\<NL>
1509                         \\\?\<NL>
1510                         \0 or 1 of previous atom\<NL>
1511                         \\\@!\<NL>
1512                         \negative lookahead== previous atom present ? no match : match\<NL>
1513                         \\\@<!\<NL>
1514                         \negative lookbehind== previous atom present ? no match : match\<NL>
1515                         \\\@<=\<NL>
1516                         \positive lookbehind== previous atom present ? match : no match\<NL>
1517                         \\\@=\<NL>
1518                         \positive lookahead== previous atom present ? match : no match\<NL>
1519                         \\\@>\<NL>
1520                         \'grab all' independent subexpression\<NL>
1521                         \\\A\<NL>
1522                         \non-alpha\<NL>
1523                         \\\C\<NL>
1524                         \match case\<NL>
1525                         \\\D\<NL>
1526                         \non-digit (decimal)\<NL>
1527                         \\\F\<NL>
1528                         \non-filename non-digit (decimal)\<NL>
1529                         \\\H\<NL>
1530                         \non-head of word (alpha or _)\<NL>
1531                         \\\I\<NL>
1532                         \non-identifier non-digit (decimal)\<NL>
1533                         \\\K\<NL>
1534                         \non-keyword non-digit (decimal)\<NL>
1535                         \\\L\<NL>
1536                         \non-lowercase\<NL>
1537                         \\\M\<NL>
1538                         \magic off for following\<NL>
1539                         \\\O\<NL>
1540                         \non-digit (octal)\<NL>
1541                         \\\P\<NL>
1542                         \printable non-digit (decimal)\<NL>
1543                         \\\S\<NL>
1544                         \non-whitespace\<NL>
1545                         \\\U\<NL>
1546                         \non-uppercase\<NL>
1547                         \\\V\<NL>
1548                         \very magic off for following\<NL>
1549                         \\\W\<NL>
1550                         \non-word (alpha or decimal or _)\<NL>
1551                         \\\X\<NL>
1552                         \non-digit (hex)\<NL>
1553                         \\\Z\<NL>
1554                         \ignore Unicode combine diff\<NL>
1555                         \\\_\<NL>
1556                         \following and newline\<NL>
1557                         \\\_$\<NL>
1558                         \end of line (anywhere)\<NL>
1559                         \\\_.\<NL>
1560                         \single char or end of line\<NL>
1561                         \\\_^\<NL>
1562                         \start of line (anywhere)\<NL>
1563                         \\\a\<NL>
1564                         \alpha\<NL>
1565                         \\\b\<NL>
1566                         \backspace <BS>\<NL>
1567                         \\\c\<NL>
1568                         \ignore case\<NL>
1569                         \\\d\<NL>
1570                         \digit (decimal)\<NL>
1571                         \\\e\<NL>
1572                         \escape <Esc>\<NL>
1573                         \\\f\<NL>
1574                         \filename\<NL>
1575                         \\\h\<NL>
1576                         \head of word (alpha or _)\<NL>
1577                         \\\i\<NL>
1578                         \identifier\<NL>
1579                         \\\k\<NL>
1580                         \keyword\<NL>
1581                         \\\l\<NL>
1582                         \lowercase\<NL>
1583                         \\\m\<NL>
1584                         \magic on for following\<NL>
1585                         \\\n\<NL>
1586                         \newline (possibly combination)\<NL>
1587                         \\\o\<NL>
1588                         \digit (octal)\<NL>
1589                         \\\p\<NL>
1590                         \printable\<NL>
1591                         \\\r\<NL>
1592                         \carriage return <CR>\<NL>
1593                         \\\s\<NL>
1594                         \whitespace <Space> or <Tab>\<NL>
1595                         \\\t\<NL>
1596                         \tab <Tab>\<NL>
1597                         \\\u\<NL>
1598                         \uppercase\<NL>
1599                         \\\v\<NL>
1600                         \very magic on for following\<NL>
1601                         \\\w\<NL>
1602                         \word (alpha or decimal or _)\<NL>
1603                         \\\x\<NL>
1604                         \digit (hex)\<NL>
1605                         \\\ze\<NL>
1606                         \previous atom is end of whole match\<NL>
1607                         \\\zs\<NL>
1608                         \following is start of whole match\<NL>
1609                         \~\<NL>
1610                         \last given substitute
1611                         \"
1613 let s:sampleRegex1='\w\+'
1614 let s:sampleRegex2='[[:punct:]]\+'
1615 let s:sampleRegex3='\%(ABC\|abc\)\@<=\(DEF\|def\)\%(GHIJ\|ghij\)\@='
1616 let s:sampleRegex4='\%(ABC\|abc\)\@<=\%(DEF\|def\)\%(GHIJ\|ghij\)\@='
1617 let s:sampleRegex5='\%(ABC\|abc\)\@<=DEF\|def\%(GHIJ\|ghij\)\@='
1618 let s:sampleRegex6='" Any alpha sequence as long as it is followed by a non-vowel'
1619 let s:sampleRegex7='[[:alpha:]]\+\([^aeiouAEIOU]\)\@='
1620 let s:sampleRegex8='" A regex for email address'
1621 let s:sampleRegex9='\<[A-Za-z0-9._%-]\+@[A-Za-z0-9._%-]\+\.[A-Za-z]\{2,4}\>'
1622 let s:sampleRegex10='" Another regex for email address'
1623 let s:sampleRegex11='\<[[:alnum:]._%-]\+@[._%\-[:alnum:]]\+\.[[:alpha:]]\{2,4}\>'
1624 let s:sampleRegex12='" Yet another regex for email address'
1625 let s:sampleRegex13='\<\%(\w\|[.%-]\)\+@\%(\w\|[.%-]\)\+\.\w\{2,4}\>'
1626 let s:sampleRegex14='\<\(\w\|[.%-]\)\+@\(\w\|[.%-]\)\+\.\w\{2,4}\>'
1627 let s:sampleRegex15='\<\%(\w\|[.%-]\)\+@\(\w\|[.%-]\)\+\.\w\{2,4}\>'
1628 let s:sampleRegex16='\<\(\w\|[.%-]\)\+@\%(\w\|[.%-]\)\+\.\w\{2,4}\>'
1629 let s:sampleRegex17='" RTFM or Read The Fine Manual'
1630 let s:sampleRegex18='R\%[ead\s]T\%[he\s]F\%[ine\s]M\%[anual]'
1631 let s:sampleRegex19='" This allows anything printable after the "F"; or even unprintable!;)'
1632 let s:sampleRegex20='R\%[ead]\s*T\%[he]\s*F\p\{-}\s*M\%[anual]'
1633 let s:sampleRegex21='" Even more flexibility'
1634 let s:sampleRegex22='R\%[ea[[:alpha:]]]\s\{-}T\%[he]\s\{-}F\p\{-}\s\{-}M\%[anu]\a*'
1635 let s:sampleRegex23='R\%[ea\a]\s\{-}T\%[he]\s\{-}F\p\{-}\s\{-}M\%[anu]\a*'
1636 let s:sampleRegex24='R\%[ea\a\a]\s\{-}T\%[he]\s\{-}F\p\{-}\s\{-}M\%[anu]\a*'
1637 let s:sampleRegex25='" Hmm...'
1638 let s:sampleRegex26='\%(\<\)\@<=\%([A-Za-z0-9._%-]\+\)\%(@[A-Za-z0-9._%-]\+\.[A-Za-z]\{2,4}\>\)\@='
1639 let s:sampleRegex27='\%(\<[A-Za-z0-9._%-]\+@\)\@<=\%([A-Za-z0-9._%-]\+\)\%(\.[A-Za-z]\{2,4}\>\)\@='
1640 let s:sampleRegex28='\%(\<[A-Za-z0-9._%-]\+@[A-Za-z0-9._%-]\+\.\)\@<=\%([A-Za-z]\{2,4}\)\%(\>\)\@='
1642 let s:sampleSrc1='1 2 3 4 five six seven 8910'
1643 let s:sampleSrc2=" !\"#$%&'()*+,-./0123456789:;<=>?"
1644 let s:sampleSrc3='@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_'
1645 let s:sampleSrc4='`abcdefghijklmnopqrstuvwxyz{|}'
1646 let s:sampleSrc5=' ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿'
1647 let s:sampleSrc6='ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß'
1648 let s:sampleSrc7='àáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ'
1649 let s:sampleSrc8='JoeValachi@crime.org'
1650 let s:sampleSrc9='LegsDiamond@crime.org'
1651 let s:sampleSrc10='BillGates@crime.org'
1652 let s:sampleSrc11='RTFM'
1653 let s:sampleSrc12='Read The Fine Manual'
1654 let s:sampleSrc13='Read The Formidable Manual'
1655 let s:sampleSrc14='Read The Facinating Manual'
1656 let s:sampleSrc15='Read The Finished Manuscript'
1657 let s:sampleSrc16='Reap The Future Manufacturing Benefits'
1658 let s:sampleSrc17='Reach The Final Manufacture Phase'
1660 function s:doUsageSyntax()
1661         syntax match VimrexUsageDesc '\p*' contains=VimrexUsageTitle,VimrexUsageSketch,VimrexUsageEmph,VimrexUsageHotkey,VimrexSearchPattern,VimrexFilePattern,VimrexSearchToken,VimrexSearchCgp,VimrexSearchGrp,VimrexSearchChc,VimrexSearchAnchor,VimrexSearchExp
1662         syntax match VimrexFilePattern "current regex"
1663         syntax match VimrexSearchToken "plain search"
1664         syntax match VimrexSearchCgp "capture"
1665         syntax match VimrexSearchGrp "non-capture"
1666         syntax match VimrexSearchChc "choice"
1667         syntax match VimrexSearchExp "expansion"
1668         syntax match VimrexSearchAnchor "lookaround"
1669         syntax match VimrexSearchPattern "non-current"
1670         syntax match VimrexUsageTitle ": Vim Regular Expression Developer Plugin"
1671         syntax match VimrexUsageTitle ": Synopsis of Use"
1672         syntax match VimrexUsageTitle ": Command Summary"
1673         syntax match VimrexUsageTitle ": Global Variables"
1674         syntax match VimrexUsageTitle ": Pattern and Match Highlighting"
1675         syntax match VimrexUsageTitle ": Generating Files"
1676         syntax match VimrexUsageTitle ": Contact Information"
1677         syntax match VimrexUsageSketch '+\|-\||'
1678         syntax match VimrexUsageEmph '[Rr]egular [Ee]xpression\%[s]'
1679         syntax match VimrexUsageEmph '[Ss]earch\%[e[sd]]'
1680         syntax match VimrexUsageEmph '[Ee]xecut\%(e\%[d]\|ion\|ing\)'
1681         syntax match VimrexUsageEmph '[Aa]nalys[ei]s'
1682         syntax match VimrexUsageEmph '[Aa]nalyze\%[[ds]]'
1683         syntax match VimrexUsageEmph '[Aa]nalyzing'
1684         syntax match VimrexUsageEmph '[Rr]esult\%[s]'
1685         syntax match VimrexUsageEmph '[Tt]ext'
1686         syntax match VimrexUsageEmph '[Mm]atch\%[ing]'
1687         syntax match VimrexUsageEmph '[Mm]atche[ds]'
1688         syntax match VimrexUsageEmph '\%[reverse ][Hh]ighlight\%(s\|ed\|ing\)'
1689         syntax match VimrexUsageEmph '[Tt]oken\%[s]'
1690         syntax match VimrexUsageEmph 'NOTE:'
1691         syntax match VimrexUsageEmph 'See:'
1692         syntax match VimrexUsageHotkey 'g:VimrexExec'
1693         syntax match VimrexUsageHotkey 'g:VimrexAnlz'
1694         syntax match VimrexUsageHotkey 'g:VimrexTop'
1695         syntax match VimrexUsageHotkey 'g:VimrexBtm'
1696         syntax match VimrexUsageHotkey 'g:VimrexCtr'
1697         syntax match VimrexUsageHotkey 'g:VimrexCLS'
1698         syntax match VimrexUsageHotkey 'g:VimrexDRslt'
1699         syntax match VimrexUsageHotkey 'g:VimrexDSrc'
1700         syntax match VimrexUsageHotkey 'g:VimrexRdSrc'
1701         syntax match VimrexUsageHotkey 'g:VimrexRdRex'
1702         syntax match VimrexUsageHotkey 'g:VimrexQQ'
1703         syntax match VimrexUsageHotkey 'g:VimrexQC'
1704         syntax match VimrexUsageHotkey 'g:VimrexQP'
1705         syntax match VimrexUsageHotkey 'g:VimrexQL'
1706         syntax match VimrexUsageHotkey 'g:VimrexZHV'
1707         syntax match VimrexUsageHotkey 'g:VimrexZHS'
1708         syntax match VimrexUsageHotkey 'g:VimrexZHU'
1709         syntax match VimrexUsageHotkey 'g:VimrexZHR'
1710         syntax match VimrexUsageHotkey 'g:VimrexZHA'
1711         syntax match VimrexUsageHotkey 'g:VimrexZTV'
1712         syntax match VimrexUsageHotkey 'g:VimrexZTS'
1713         syntax match VimrexUsageHotkey 'g:VimrexZTU'
1714         syntax match VimrexUsageHotkey 'g:VimrexZTR'
1715         syntax match VimrexUsageHotkey 'g:VimrexZTA'
1716         syntax match VimrexUsageHotkey 'g:VimrexExit'
1717         syntax match VimrexUsageHotkey 'g:VimrexBrowseDir'
1718         syntax match VimrexUsageHotkey 'g:VimrexFile\%[Dir]'
1719         syntax match VimrexUsageHotkey 'g:VimrexRsltFile'
1720         syntax match VimrexUsageHotkey 'g:VimrexSrcFile'
1721         syntax match VimrexUsageHotkey 'g:VimrexUsageFile'
1722         syntax match VimrexUsageHotkey 'g:VimrexSrchPatLnk'
1723         syntax match VimrexUsageHotkey 'g:VimrexSrchPatCFG'
1724         syntax match VimrexUsageHotkey 'g:VimrexSrchPatCBG'
1725         syntax match VimrexUsageHotkey 'g:VimrexSrchPatGFG'
1726         syntax match VimrexUsageHotkey 'g:VimrexSrchPatGBG'
1727         syntax match VimrexUsageHotkey 'g:VimrexSrchAncLnk'
1728         syntax match VimrexUsageHotkey 'g:VimrexSrchAncCFG'
1729         syntax match VimrexUsageHotkey 'g:VimrexSrchAncCBG'
1730         syntax match VimrexUsageHotkey 'g:VimrexSrchAncGFG'
1731         syntax match VimrexUsageHotkey 'g:VimrexSrchAncGBG'
1732         syntax match VimrexUsageHotkey 'g:VimrexSrchTokLnk'
1733         syntax match VimrexUsageHotkey 'g:VimrexSrchTokCBG'
1734         syntax match VimrexUsageHotkey 'g:VimrexSrchTokCFG'
1735         syntax match VimrexUsageHotkey 'g:VimrexSrchTokGBG'
1736         syntax match VimrexUsageHotkey 'g:VimrexSrchTokGFG'
1737         syntax match VimrexUsageHotkey 'g:VimrexFilePatLnk'
1738         syntax match VimrexUsageHotkey 'g:VimrexFilePatCFG'
1739         syntax match VimrexUsageHotkey 'g:VimrexFilePatCBG'
1740         syntax match VimrexUsageHotkey 'g:VimrexFilePatGFG'
1741         syntax match VimrexUsageHotkey 'g:VimrexFilePatGBG'
1742         syntax match VimrexUsageHotkey 'g:VimrexFileCgpLnk'
1743         syntax match VimrexUsageHotkey 'g:VimrexFileCgpCFG'
1744         syntax match VimrexUsageHotkey 'g:VimrexFileCgpCBG'
1745         syntax match VimrexUsageHotkey 'g:VimrexFileCgpGFG'
1746         syntax match VimrexUsageHotkey 'g:VimrexFileCgpGBG'
1747         syntax match VimrexUsageHotkey 'g:VimrexFileGrpLnk'
1748         syntax match VimrexUsageHotkey 'g:VimrexFileGrpCFG'
1749         syntax match VimrexUsageHotkey 'g:VimrexFileGrpCBG'
1750         syntax match VimrexUsageHotkey 'g:VimrexFileGrpGFG'
1751         syntax match VimrexUsageHotkey 'g:VimrexFileGrpGBG'
1752         syntax match VimrexUsageHotkey 'g:VimrexFileChcLnk'
1753         syntax match VimrexUsageHotkey 'g:VimrexFileChcCFG'
1754         syntax match VimrexUsageHotkey 'g:VimrexFileChcCBG'
1755         syntax match VimrexUsageHotkey 'g:VimrexFileChcGFG'
1756         syntax match VimrexUsageHotkey 'g:VimrexFileChcGBG'
1757         syntax match VimrexUsageHotkey 'g:VimrexFileExpLnk'
1758         syntax match VimrexUsageHotkey 'g:VimrexFileExpCFG'
1759         syntax match VimrexUsageHotkey 'g:VimrexFileExpCBG'
1760         syntax match VimrexUsageHotkey 'g:VimrexFileExpGFG'
1761         syntax match VimrexUsageHotkey 'g:VimrexFileExpGBG'
1762         syntax match VimrexUsageHotkey ':h tohtml'
1763         syntax match VimrexUsageHotkey '/Remarks:'
1764         execute 'syntax match VimrexUsageHotkey "'.g:VimrexExec.'"'
1765         execute 'syntax match VimrexUsageHotkey "'.g:VimrexAnlz.'"'
1766         execute 'syntax match VimrexUsageHotkey "'.g:VimrexTop.'"'
1767         execute 'syntax match VimrexUsageHotkey "'.g:VimrexBtm.'"'
1768         execute 'syntax match VimrexUsageHotkey "'.g:VimrexCtr.'"'
1769         execute 'syntax match VimrexUsageHotkey "'.g:VimrexCLS.'"'
1770         execute 'syntax match VimrexUsageHotkey "'.g:VimrexDRslt.'"'
1771         execute 'syntax match VimrexUsageHotkey "'.g:VimrexDSrc.'"'
1772         execute 'syntax match VimrexUsageHotkey "'.g:VimrexRdSrc.'"'
1773         execute 'syntax match VimrexUsageHotkey "'.g:VimrexRdRex.'"'
1774         execute 'syntax match VimrexUsageHotkey "'.g:VimrexQQ.'"'
1775         execute 'syntax match VimrexUsageHotkey "'.g:VimrexQC.'"'
1776         execute 'syntax match VimrexUsageHotkey "'.g:VimrexQP.'"'
1777         execute 'syntax match VimrexUsageHotkey "'.g:VimrexQL.'"'
1778         execute 'syntax match VimrexUsageHotkey "'.g:VimrexZHV.'"'
1779         execute 'syntax match VimrexUsageHotkey "'.g:VimrexZHS.'"'
1780         execute 'syntax match VimrexUsageHotkey "'.g:VimrexZHU.'"'
1781         execute 'syntax match VimrexUsageHotkey "'.g:VimrexZHR.'"'
1782         execute 'syntax match VimrexUsageHotkey "'.g:VimrexZHA.'"'
1783         execute 'syntax match VimrexUsageHotkey "'.g:VimrexZTV.'"'
1784         execute 'syntax match VimrexUsageHotkey "'.g:VimrexZTS.'"'
1785         execute 'syntax match VimrexUsageHotkey "'.g:VimrexZTU.'"'
1786         execute 'syntax match VimrexUsageHotkey "'.g:VimrexZTR.'"'
1787         execute 'syntax match VimrexUsageHotkey "'.g:VimrexZTA.'"'
1788         execute 'syntax match VimrexUsageHotkey "'.g:VimrexExit.'"'
1789         execute 'syntax match VimrexUsageHotkey "'.s:myName.'"'
1790         highlight link VimrexUsageTitle Title
1791         highlight link VimrexUsageDesc Identifier
1792         highlight link VimrexUsageSketch StatusLine
1793         highlight link VimrexUsageEmph NonText
1794         highlight link VimrexUsageHotkey Statement
1795 endfunction
1797 function! s:usage()
1798         if bufwinnr(g:VimrexUsageFile) != -1
1799                 return
1800         endif
1801         echohl WarningMsg
1802         echomsg 'Generating Usage Document...'
1803         echohl None
1804         let Exec=PadField('l','12',g:VimrexExec)
1805         let Anlz=PadField('l','12',g:VimrexAnlz)
1806         let Top=PadField('l','12',g:VimrexTop)
1807         let Btm=PadField('l','12',g:VimrexBtm)
1808         let Ctr=PadField('l','12',g:VimrexCtr)
1809         let CLS=PadField('l','12',g:VimrexCLS)
1810         let DRslt=PadField('l','12',g:VimrexDRslt)
1811         let DSrc=PadField('l','12',g:VimrexDSrc)
1812         let RdSrc=PadField('l','12',g:VimrexRdSrc)
1813         let RdRex=PadField('l','12',g:VimrexRdRex)
1814         let QQ=PadField('l','12',g:VimrexQQ)
1815         let QC=PadField('l','12',g:VimrexQC)
1816         let QP=PadField('l','12',g:VimrexQP)
1817         let QL=PadField('l','12',g:VimrexQL)
1818         let ZHV=PadField('l','12',g:VimrexZHV)
1819         let ZHS=PadField('l','12',g:VimrexZHS)
1820         let ZHU=PadField('l','12',g:VimrexZHU)
1821         let ZHR=PadField('l','12',g:VimrexZHR)
1822         let ZHA=PadField('l','12',g:VimrexZHA)
1823         let ZTV=PadField('l','12',g:VimrexZTV)
1824         let ZTS=PadField('l','12',g:VimrexZTS)
1825         let ZTU=PadField('l','12',g:VimrexZTU)
1826         let ZTR=PadField('l','12',g:VimrexZTR)
1827         let ZTA=PadField('l','12',g:VimrexZTA)
1828         let Exit=PadField('l','12',g:VimrexExit)
1829         wincmd t
1830         call s:delFile(g:VimrexUsageFile)
1831         new
1832         execute 'silent edit! '.escape(g:VimrexUsageFile,' ')
1833         setlocal noreadonly modifiable nonumber noswapfile
1834         execute 'resize '.&lines
1835         execute 'vertical resize '.&columns
1836         call append(0,PadField('c',76,s:myName.": Vim Regular Expression Developer Plugin"))
1837         call s:doUsageSection('ONE')
1838         call append(line('$'),PadField('c',76,s:myName.": Command Summary"))
1839         call append(line('$'),"")
1840         call append(line('$'),Exec."Execute Regular Expression")
1841         call append(line('$'),Anlz."Analyze Regular Expression")
1842         call append(line('$'),Top."Changes to .Vim Regular Expression Specification Window")
1843         call append(line('$'),Btm."Changes to .Vim Regular Expression Search Source Window")
1844         call append(line('$'),Ctr."Changes to .Vim Regular Expression Result Window")
1845         call append(line('$'),CLS."Clear .Vim Regular Expression Specification Window")
1846         call append(line('$'),DRslt."Clear .Vim Regular Expression Result Window")
1847         call append(line('$'),DSrc."Clear .Vim Regular Expression Search Source Window")
1848         call append(line('$'),RdSrc."Read File into .Vim Regular Expression Search Source Window")
1849         call append(line('$'),RdRex."Read File into .Vim Regular Expression Specification Window")
1850         call append(line('$'),QQ."Open Usage Window (display this file)")
1851         call append(line('$'),QL."Close Usage Window")
1852         call append(line('$'),QC."Collapse Usage Window")
1853         call append(line('$'),QP."Expand Usage Window")
1854         call append(line('$'),ZHV."Generate HTML File of Regular Expression Window")
1855         call append(line('$'),ZHS."Generate HTML File of Search Source Window")
1856         call append(line('$'),ZHU."Generate HTML File of Usage Window")
1857         call append(line('$'),ZHR."Generate HTML File of Results Window")
1858         call append(line('$'),ZHA."Generate HTML File of All But Usage Window")
1859         call append(line('$'),ZTV."Generate TEXT (.txt) File of Regular Expression Window")
1860         call append(line('$'),ZTS."Generate TEXT (.txt) File of Search Source Window")
1861         call append(line('$'),ZTU."Generate TEXT (.txt) File of Usage Window")
1862         call append(line('$'),ZTR."Generate TEXT (.txt) File of Results Window")
1863         call append(line('$'),ZTA."Generate TEXT (.txt) File of All But Usage Window")
1864         call append(line('$'),Exit."Exit ".s:myName." (close all windows)")
1865         call s:doUsageSection('TWO')
1866         call append(line('$'),PadField('c',76,s:myName.": Synopsis of Use"))
1867         call s:doUsageSection('THREE')
1868         call append(line('$'),PadField('c',76,g:VimrexAnlz))
1869         call s:doUsageSection('FOUR')
1870         call append(line('$'),PadField('c',76,g:VimrexExec))
1871         call s:doUsageSection('FIVE')
1872         call append(line('$'),PadField('c',76,s:myName.": Global Variables"))
1873         call append(line('$')," ")
1874         call append(line('$'),PadField('l',20,'g:VimrexExec')."mapping sequence for executing regular expression")
1875         call append(line('$'),PadField('l',20,'g:VimrexAnlz')."mapping sequence for analyzing regular expression")
1876         call append(line('$'),PadField('l',20,'g:VimrexTop')."mapping sequence for goto top window")
1877         call append(line('$'),PadField('l',20,'g:VimrexBtm')."mapping sequence for goto bottom window")
1878         call append(line('$'),PadField('l',20,'g:VimrexCtr')."mapping sequence for goto center window")
1879         call append(line('$'),PadField('l',20,'g:VimrexCLS')."mapping sequence for clearing top window")
1880         call append(line('$'),PadField('l',20,'g:VimrexDSrc')."mapping sequence for clearing bottom window")
1881         call append(line('$'),PadField('l',20,'g:VimrexDRslt')."mapping sequence for clearing center window")
1882         call append(line('$'),PadField('l',20,'g:VimrexRdSrc')."mapping sequence to read file into bottom window")
1883         call append(line('$'),PadField('l',20,'g:VimrexRdRex')."mapping sequence to read file into top window")
1884         call append(line('$'),PadField('l',20,'g:VimrexQQ')."mapping sequence to open display of this file")
1885         call append(line('$'),PadField('l',20,'g:VimrexQL')."mapping sequence to close display of this file")
1886         call append(line('$'),PadField('l',20,'g:VimrexQC')."mapping sequence to collapse display of this file")
1887         call append(line('$'),PadField('l',20,'g:VimrexQP')."mapping sequence to expand display of this file")
1888         call append(line('$'),PadField('l',20,'g:VimrexZHV')."mapping sequence to generate Regular Expression HTML file")
1889         call append(line('$'),PadField('l',20,'g:VimrexZHS')."mapping sequence to generate Source Search HTML file")
1890         call append(line('$'),PadField('l',20,'g:VimrexZHU')."mapping sequence to generate Usage HTML file")
1891         call append(line('$'),PadField('l',20,'g:VimrexZHR')."mapping sequence to generate Results HTML file")
1892         call append(line('$'),PadField('l',20,'g:VimrexZHA')."mapping sequence to generate All But Usage HTML file")
1893         call append(line('$'),PadField('l',20,'g:VimrexZTV')."mapping sequence to generate Regular Expression TEXT file")
1894         call append(line('$'),PadField('l',20,'g:VimrexZTS')."mapping sequence to generate Source Search TEXT file")
1895         call append(line('$'),PadField('l',20,'g:VimrexZTU')."mapping sequence to generate Usage TEXT file")
1896         call append(line('$'),PadField('l',20,'g:VimrexZTR')."mapping sequence to generate Results TEXT file")
1897         call append(line('$'),PadField('l',20,'g:VimrexZTA')."mapping sequence to generate All But Usage TEXT file")
1898         call append(line('$'),PadField('l',20,'g:VimrexExit')."mapping sequence to exit ".s:myName)
1899         call append(line('$'),PadField('l',20,"g:VimrexBrowseDir")."directory to browse for read files")
1900         call append(line('$'),PadField('l',20,"g:VimrexFileDir")."directory to create files ('~')")
1901         call append(line('$'),PadField('l',20,"g:VimrexFile")."regular expression file")
1902         call append(line('$'),PadField('l',20,"g:VimrexRsltFile")."result file")
1903         call append(line('$'),PadField('l',20,"g:VimrexSrcFile")."search source file")
1904         call append(line('$'),PadField('l',20,"g:VimrexUsageFile")."usage file")
1905         call append(line('$'),PadField('l',20,"g:VimrexSrchPatLnk")."highlight link for non-current highlighting")
1906         call append(line('$'),PadField('l',20,"g:VimrexSrchPatCFG")."ctermfg= value for non-current highlighting ('black')")
1907         call append(line('$'),PadField('l',20,"g:VimrexSrchPatCBG")."ctermbg= value for non-current highlighting ('DarkMagenta')")
1908         call append(line('$'),PadField('l',20,"g:VimrexSrchPatGFG")."guifg= value for non-current highlighting ('black')")
1909         call append(line('$'),PadField('l',20,"g:VimrexSrchPatGBG")."guibg= value for non-current highlighting ('DarkMagenta')")
1910         call append(line('$'),PadField('l',20,"g:VimrexSrchAncLnk")."highlight link for lookaround highlighting")
1911         call append(line('$'),PadField('l',20,"g:VimrexSrchAncCFG")."ctermfg= value for lookaround highlighting ('DarkRed')")
1912         call append(line('$'),PadField('l',20,"g:VimrexSrchAncCBG")."ctermbg= value for lookaround highlighting ('gray')")
1913         call append(line('$'),PadField('l',20,"g:VimrexSrchAncGFG")."guifg= value for lookaround highlighting ('DarkRed')")
1914         call append(line('$'),PadField('l',20,"g:VimrexSrchAncGBG")."guibg= value for lookaround highlighting ('gray')")
1915         call append(line('$'),PadField('l',20,"g:VimrexSrchTokLnk")."highlight link for plain search highlighting")
1916         call append(line('$'),PadField('l',20,"g:VimrexSrchTokCBG")."ctermfg= value for plain search highlighting ('LightCyan')")
1917         call append(line('$'),PadField('l',20,"g:VimrexSrchTokCFG")."ctermbg= value for plain search highlighting ('black')")
1918         call append(line('$'),PadField('l',20,"g:VimrexSrchTokGBG")."guifg= value for plain search highlighting ('LightCyan')")
1919         call append(line('$'),PadField('l',20,"g:VimrexSrchTokGFG")."guibg= value for plain search highlighting ('black')")
1920         call append(line('$'),PadField('l',20,"g:VimrexFilePatLnk")."highlight link for current regex highlighting")
1921         call append(line('$'),PadField('l',20,"g:VimrexFilePatCFG")."ctermfg= value for current regex highlighting ('cyan')")
1922         call append(line('$'),PadField('l',20,"g:VimrexFilePatCBG")."ctermfg= value for current regex highlighting ('brown')")
1923         call append(line('$'),PadField('l',20,"g:VimrexFilePatGFG")."guifg= value for current regex highlighting ('cyan')")
1924         call append(line('$'),PadField('l',20,"g:VimrexFilePatGBG")."guifg= value for current regex highlighting ('brown')")
1925         call append(line('$'),PadField('l',20,"g:VimrexFileCgpLnk")."highlight link for capture group highlighting")
1926         call append(line('$'),PadField('l',20,"g:VimrexFileCgpCFG")."ctermfg= value for capture group highlighting ('blue')")
1927         call append(line('$'),PadField('l',20,"g:VimrexFileCgpCBG")."ctermfg= value for capture group highlighting ('red')")
1928         call append(line('$'),PadField('l',20,"g:VimrexFileCgpGFG")."guifg= value for capture group highlighting ('blue')")
1929         call append(line('$'),PadField('l',20,"g:VimrexFileCgpGBG")."guifg= value for capture group highlighting ('red')")
1930         call append(line('$'),PadField('l',20,"g:VimrexFileGrpLnk")."highlight link for capture group highlighting")
1931         call append(line('$'),PadField('l',20,"g:VimrexFileGrpCFG")."ctermfg= value for non-capture group highlighting ('red')")
1932         call append(line('$'),PadField('l',20,"g:VimrexFileGrpCBG")."ctermfg= value for non-capture group highlighting ('blue')")
1933         call append(line('$'),PadField('l',20,"g:VimrexFileGrpGFG")."guifg= value for non-capture group highlighting ('red')")
1934         call append(line('$'),PadField('l',20,"g:VimrexFileGrpGBG")."guifg= value for non-capture group highlighting ('blue')")
1935         call append(line('$'),PadField('l',20,"g:VimrexFileChcLnk")."highlight link for choice list highlighting")
1936         call append(line('$'),PadField('l',20,"g:VimrexFileChcCFG")."ctermfg= value for choice list highlighting ('black')")
1937         call append(line('$'),PadField('l',20,"g:VimrexFileChcCBG")."ctermfg= value for choice list highlighting ('LightBlue')")
1938         call append(line('$'),PadField('l',20,"g:VimrexFileChcGFG")."guifg= value for choice list highlighting ('black')")
1939         call append(line('$'),PadField('l',20,"g:VimrexFileChcGBG")."guifg= value for choice list highlighting ('LightBlue')")
1940         call append(line('$'),PadField('l',20,"g:VimrexFileExpLnk")."highlight link for expansion seq highlighting")
1941         call append(line('$'),PadField('l',20,"g:VimrexFileExpCFG")."ctermfg= value for expansion seq highlighting ('black')")
1942         call append(line('$'),PadField('l',20,"g:VimrexFileExpCBG")."ctermfg= value for expansion seq highlighting ('LightGreen')")
1943         call append(line('$'),PadField('l',20,"g:VimrexFileExpGFG")."guifg= value for expansion seq highlighting ('black')")
1944         call append(line('$'),PadField('l',20,"g:VimrexFileExpGBG")."guifg= value for expansion seq highlighting ('LightGreen')")
1945         call append(line('$')," ")
1946         call append(line('$')," ")
1947         call append(line('$'),PadField('c',76,s:myName.": Pattern and Match Highlighting"))
1948         call s:doUsageSection('SIX')
1949         call append(line('$'),PadField('c',76,s:myName.": Generating Files"))
1950         call append(line('$')," ")
1951         call append(line('$'),s:myName." will generate files of the current windows for you to view")
1952         call s:doUsageSection('SEVEN')
1953         call append(line('$'),PadField('c',76,s:myName.": Contact Information"))
1954         call append(line('$')," ")
1955         call append(line('$'),"If you find bugs, have suggestions, or just want to chat:")
1956         call append(line('$'),"http://www.vim.org/account/profile.php?user_id=5397")
1957         call append(line('$'),"You'll find my current email address there.")
1958         syntax sync fromstart
1959         setlocal nomodified readonly nomodifiable
1960         echohl Question
1961         echon 'Done.'
1962         echohl None
1963 endfunction
1965 function s:doUsageSection(sect)
1966         silent :w
1967         execute 'silent view! +set\ noswapfile '.s:thisScript
1968         let strtStr='^BEGIN MANUAL SECTION '.a:sect
1969         let endStr='^END MANUAL SECTION '.a:sect
1970         let lnum=search(strtStr,'W')+1
1971         let elnum=search(endStr,'W')
1972         while lnum < elnum
1973                 let usageLine=getline(lnum)
1974                 silent b#
1975                 call append(line('$'),usageLine)
1976                 silent :w
1977                 silent b#
1978                 let lnum=lnum+1
1979         endwhile
1980         silent b#
1981         execute 'silent '.bufnr(s:thisScript).'bd'
1982         call s:doUsageSyntax()
1983 endfunction
1985 function s:IT_LL_NEVER_HAPPEN()
1986 BEGIN MANUAL SECTION ONE
1987 Uses 3 windows for developing Vim regular expressions.
1989 The top window is used to type in the regular expression(s) or you may
1990 optionally read in a file containing regular expressions.  There can be more
1991 than one regular expression in the top window, as well as comment lines (lines
1992 that begin with a double quote with optional leading whitespace).  The line
1993 containing the cursor in this window is the line of the current regular
1994 expression for execution and/or analysis.
1996 The middle window shows the result of each successive execution or analysis of
1997 the current regular expression.
1999 The bottom window is for source text used in testing regular expressions.  You
2000 either type in text, or read in a file for searching.
2002 The contents of the top and bottom window are saved from one session to the
2003 next.  When the files used to save these contents do not exist or are empty
2004 when starting up, sample contents are placed in each to use as a self
2005 tutorial.
2008 END MANUAL SECTION ONE
2009 BEGIN MANUAL SECTION TWO
2011 The mappings for all the above are configurable in your vimrc by setting their
2012 respective global variables (see below) to the key sequences you desire.
2015 END MANUAL SECTION TWO
2016 BEGIN MANUAL SECTION THREE
2018    +----------------------------------------------------------------------+
2019    |" comment line                                                        |
2020    |regular expression                                                    |
2021    |                                                                      |
2022    |             Build regular expressions here                           |
2023    |                                                                      |
2024    |                                                                      |
2025    |                                                                      |
2026    |                                                                      |
2027    |----------------------------------------------------------------------|
2028    |                                                                      |
2029    |                                                                      |
2030    |                                                                      |
2031    |       Execution/Analysis results displayed here                      |
2032    |                                                                      |
2033    |                                                                      |
2034    |                                                                      |
2035    |                                                                      |
2036    |----------------------------------------------------------------------|
2037    |                                                                      |
2038    |                                                                      |
2039    |                                                                      |
2040    |              Text to be searched goes here                           |
2041    |                                                                      |
2042    |                                                                      |
2043    |                                                                      |
2044    |                                                                      |
2045    +----------------------------------------------------------------------+
2047 To use, enter a regular expression in the top window and some text to search in
2048 the bottom window.  With the cursor on the line with the regular expression in
2049 the top window, type
2051 END MANUAL SECTION THREE
2052 BEGIN MANUAL SECTION FOUR
2054 and the analysis of the regular expression will be displayed in the center
2055 window.  Now, type
2057 END MANUAL SECTION FOUR
2058 BEGIN MANUAL SECTION FIVE
2060 the results of the search with the current regular expression will be
2061 displayed in the center window.  Additionally,  all text that qualifies as a
2062 match in the bottom window will be highlighted in the 'non-current'
2063 highlighting with the matching specific token of the current search location
2064 highlighted as appropriate to its regular expression atom(s).
2066 NOTE:  you need to use the menu 'Execute Regular Expression' button or the key
2067        mapping to search and have the described results.  Using Vim's search
2068                          commands will move to different matches, but will not effect the
2069                          highlighting.  See : Pattern and Match Highlighting below.
2072 END MANUAL SECTION FIVE
2073 BEGIN MANUAL SECTION SIX
2075 Highlighting is set by either a link or by setting the foreground and/or
2076 background values for cterm or gui.  If the respective 'g:Vimrex...Lnk'
2077 variable exists, the link is used, else the highlighting is set via the
2078 cterm/gui values.
2080 There are eight highlight groups used.  They are:
2082      current regex
2083                  plain search
2084                  capture
2085                  non-capture
2086                  choice
2087                  expansion
2088                  lookaround
2089                  non-current
2091 current regex is used to highlight the current regular expression in the top
2092 window.
2094 plain search is the default highlighting for the current match.  If no other
2095 atom highlighting applies, this is the highlighting that is displayed.
2097 capture is the highlighting used to delineate the portion of the current match
2098 that is part of a capture group, i.e., results from a regular expression
2099 enclosed in '\(...\)'.
2101 non-capture highlighting is used to indicate the portion of the current match
2102 that is part of a non-capture group, i.e., results from a regular expression
2103 enclosed in '\%(...\)'.
2105 choice highlighting indicates the portion of the current match that is the
2106 result of a choice list atom, that is, a list of characters or character
2107 classes enclosed in '[...]'.
2109 expansion highlighting indicates the portion of the current match that is the
2110 result of an expansion list, or sequence, atom, that is, a list of characters
2111 or character classes enclosed in '\%[...]'.
2113 lookaround highlighting results from the portion of the current match that
2114 conforms to a lookaround anchor, e.g., '\@<=' or '\@='.  It is, of course,
2115 only seen in the case of a positive lookaround, since the absence of the
2116 anchor triggers the negative lookaround and an 'absence' is difficult to
2117 highlight!;)
2119 non-current highlighting applies to all of the bottom window text that matches
2120 the pattern but is not the current match.
2123 END MANUAL SECTION SIX
2124 BEGIN MANUAL SECTION SEVEN
2125 separately.  Files can be of HTML (.html) or TEXT (.txt) format.  There are
2126 menu buttons and mappings to generate files for each of the windows,
2127 individually or you can generate all but the Usage file into one file for
2128 composite viewing.
2130 NOTE:  HTML only works with Vim compiled with GUI support.  The gui need not
2131        be running, but in some systems (X11), colors may not be what you see
2132        when in Vim.  On my system, Windows (g)vim produce comparable colors to
2133        those shown in Vim.  Cygwin produces the colors as seen in a standard
2134        xterm window, whether Vim was run in a command prompt window with bash
2135        or in a special xinit xterm.  By 'standard xterm', I mean an xterm
2136        started with no arguments, for example, from the command line as
2137        'xterm &'.
2139 See:   :h tohtml, then /Remarks: (search for 'Remarks:').
2143 END MANUAL SECTION SEVEN
2144 endfunction