1 " Vim plugin for Vim Regular Expression Development
3 " Maintainer: Dave Silvia <dsilvia@mchsi.com>
9 " - Problem with UNIX type
10 " systems and have a single
11 " quote in the filename for
12 " the usage file. Removed
21 " - Added 'lookaround' anchor
22 " highlighting per suggestion
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
36 " Possible final beta release
43 " - Added expanded usage message
44 " in a scrollable window
48 " - Added highlight to current
49 " selected pattern in top
52 "arrow commend it, bcs, now has not VSUTIL
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
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"
69 if exists('g:VimrexDebug')
70 command! -nargs=1 VimrexDBG :if g:VimrexDebug | call append(line('$'),<args>) | endif
72 command! -nargs=1 VimrexDBG :
75 function! s:doGlobals()
76 if !exists("g:VimrexBrowseDir")
77 let RTdirs=expand(&runtimepath)
78 if !exists("*StrListTok")
79 runtime plugin/vsutil.vim
81 let RTdir=StrListTok(RTdirs,'b:rtdirs')
84 let g:VimrexBrowseDir=RTdir
87 let RTdir=StrListTok('','b:rtdirs')
90 let RTdir=StrListTok('','b:rtdirs')
95 if !exists("g:VimrexFileDir")
96 let g:VimrexFileDir=fnamemodify(expand("~"),":p:h")
98 if !exists("g:VimrexFile")
99 let g:VimrexFile=fnamemodify(expand(g:VimrexFileDir."/.Vim Regular Expression Specification"),":p")
101 if !exists("g:VimrexRsltFile")
102 let g:VimrexRsltFile=fnamemodify(expand(g:VimrexFileDir."/.Vim Regular Expression Result"),":p")
104 if !exists("g:VimrexSrcFile")
105 let g:VimrexSrcFile=fnamemodify(expand(g:VimrexFileDir."/.Vim Regular Expression Search Source"),":p")
107 if !exists("g:VimrexUsageFile")
108 let g:VimrexUsageFile=fnamemodify(expand(g:VimrexFileDir."/.Vim Regular Expression The Fine Manual"),":p")
110 if !exists("g:VimrexExec")
111 let g:VimrexExec="ze"
113 if !exists("g:VimrexAnlz")
114 let g:VimrexAnlz="za"
116 if !exists("g:VimrexTop")
119 if !exists("g:VimrexBtm")
122 if !exists("g:VimrexCtr")
125 if !exists("g:VimrexDSrc")
126 let g:VimrexDSrc="zs"
128 if !exists("g:VimrexDRslt")
129 let g:VimrexDRslt="zr"
131 if !exists("g:VimrexCLS")
134 if !exists("g:VimrexRdSrc")
135 let g:VimrexRdSrc="zS"
137 if !exists("g:VimrexRdRex")
138 let g:VimrexRdRex="zR"
140 if !exists("g:VimrexExit")
141 let g:VimrexExit="zx"
143 if !exists("g:VimrexQQ")
146 if !exists("g:VimrexQC")
149 if !exists("g:VimrexQP")
152 if !exists("g:VimrexQL")
155 if !exists("g:VimrexZHV")
156 let g:VimrexZHV='zhv'
158 if !exists("g:VimrexZHS")
159 let g:VimrexZHS='zhs'
161 if !exists("g:VimrexZHU")
162 let g:VimrexZHU='zhu'
164 if !exists("g:VimrexZHR")
165 let g:VimrexZHR='zhr'
167 if !exists("g:VimrexZHA")
168 let g:VimrexZHA='zha'
170 if !exists("g:VimrexZTV")
171 let g:VimrexZTV='ztv'
173 if !exists("g:VimrexZTS")
174 let g:VimrexZTS='zts'
176 if !exists("g:VimrexZTU")
177 let g:VimrexZTU='ztu'
179 if !exists("g:VimrexZTR")
180 let g:VimrexZTR='ztr'
182 if !exists("g:VimrexZTA")
183 let g:VimrexZTA='zta'
186 if !exists("g:VimrexSrchPatLnk")
187 if !exists("g:VimrexSrchPatCFG")
188 let g:VimrexSrchPatCFG='black'
190 if !exists("g:VimrexSrchPatCBG")
191 let g:VimrexSrchPatCBG='DarkMagenta'
193 if !exists("g:VimrexSrchPatGFG")
194 let g:VimrexSrchPatGFG='black'
196 if !exists("g:VimrexSrchPatGBG")
197 let g:VimrexSrchPatGBG='DarkMagenta'
201 if !exists("g:VimrexSrchAncLnk")
202 if !exists("g:VimrexSrchAncCFG")
203 let g:VimrexSrchAncCFG='DarkRed'
205 if !exists("g:VimrexSrchAncCBG")
206 let g:VimrexSrchAncCBG='gray'
208 if !exists("g:VimrexSrchAncGFG")
209 let g:VimrexSrchAncGFG='DarkRed'
211 if !exists("g:VimrexSrchAncGBG")
212 let g:VimrexSrchAncGBG='gray'
216 if !exists("g:VimrexSrchTokLnk")
217 if !exists("g:VimrexSrchTokCBG")
218 let g:VimrexSrchTokCBG='LightCyan'
220 if !exists("g:VimrexSrchTokCFG")
221 let g:VimrexSrchTokCFG='black'
223 if !exists("g:VimrexSrchTokGBG")
224 let g:VimrexSrchTokGBG='LightCyan'
226 if !exists("g:VimrexSrchTokGFG")
227 let g:VimrexSrchTokGFG='black'
231 if !exists("g:VimrexSrchCgpLnk")
232 if !exists("g:VimrexSrchCgpCFG")
233 let g:VimrexSrchCgpCFG='blue'
235 if !exists("g:VimrexSrchCgpCBG")
236 let g:VimrexSrchCgpCBG='red'
238 if !exists("g:VimrexSrchCgpGFG")
239 let g:VimrexSrchCgpGFG='blue'
241 if !exists("g:VimrexSrchCgpGBG")
242 let g:VimrexSrchCgpGBG='red'
246 if !exists("g:VimrexSrchGrpLnk")
247 if !exists("g:VimrexSrchGrpCFG")
248 let g:VimrexSrchGrpCFG='red'
250 if !exists("g:VimrexSrchGrpCBG")
251 let g:VimrexSrchGrpCBG='blue'
253 if !exists("g:VimrexSrchGrpGFG")
254 let g:VimrexSrchGrpGFG='red'
256 if !exists("g:VimrexSrchGrpGBG")
257 let g:VimrexSrchGrpGBG='blue'
261 if !exists("g:VimrexSrchChcLnk")
262 if !exists("g:VimrexSrchChcCFG")
263 let g:VimrexSrchChcCFG='black'
265 if !exists("g:VimrexSrchChcCBG")
266 let g:VimrexSrchChcCBG='LightBlue'
268 if !exists("g:VimrexSrchChcGFG")
269 let g:VimrexSrchChcGFG='black'
271 if !exists("g:VimrexSrchChcGBG")
272 let g:VimrexSrchChcGBG='LightBlue'
276 if !exists("g:VimrexSrchExpLnk")
277 if !exists("g:VimrexSrchExpCFG")
278 let g:VimrexSrchExpCFG='black'
280 if !exists("g:VimrexSrchExpCBG")
281 let g:VimrexSrchExpCBG='LightGreen'
283 if !exists("g:VimrexSrchExpGFG")
284 let g:VimrexSrchExpGFG='black'
286 if !exists("g:VimrexSrchExpGBG")
287 let g:VimrexSrchExpGBG='LightGreen'
291 if !exists("g:VimrexFilePatLnk")
292 if !exists("g:VimrexFilePatCFG")
293 let g:VimrexFilePatCFG='cyan'
295 if !exists("g:VimrexFilePatCBG")
296 let g:VimrexFilePatCBG='brown'
298 if !exists("g:VimrexFilePatGFG")
299 let g:VimrexFilePatGFG='cyan'
301 if !exists("g:VimrexFilePatGBG")
302 let g:VimrexFilePatGBG='brown'
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'
327 function! s:browser(which)
328 if has("gui_running") && has("browse")
329 let fullname=browse(0,'Read File Into '.a:which,g:VimrexBrowseDir,'')
331 let fname=input("File name: ")
332 let fullname=glob(fname)
334 let fullname=g:VimrexBrowseDir.'/'.fname
335 if glob(fullname) == ''
337 echomsg "Cannot find ".fname
346 execute bufwinnr(a:which).'wincmd w'
349 let ans=input("This is the buffer's first line, insert Above or Below? : ","A")
350 if tolower(ans[0]) == 'a'
354 execute ':'.lnr.'r '.fullname
356 call s:restoreCurrent()
359 function! s:generate(which,type)
360 if a:which == 'ALLBUTUSAGE'
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")
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'
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'
380 call s:restoreCurrent()
383 let whichBufNr=bufwinnr(a:which)
386 echomsg "No open window for ".a:which
391 execute whichBufNr.'wincmd w'
393 runtime syntax/2html.vim
399 call s:restoreCurrent()
402 function! s:adjustWin(which,how)
403 let whichBufNr=bufwinnr(a:which)
408 execute whichBufNr.'wincmd w'
409 execute 'resize '.&lines
412 let usageBuf=bufwinnr(g:VimrexUsageFile)
415 execute 'let winexists=winwidth('.winNr.')'
416 while winexists != -1
418 execute 'let winexists=winwidth('.winNr.')'
431 let size=tot/fullWins
437 while thisWin < winNr
438 execute thisWin.'wincmd w'
439 execute 'resize '.size
440 let thisWin=thisWin+1
442 execute winNr.'wincmd w'
446 function! s:closeUsage()
447 let usageBuf=bufwinnr(g:VimrexUsageFile)
449 execute usageBuf."wincmd w"
463 let legendWinNr=bufwinnr('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"
479 execute 'let winExists=winheight('.winNr.') != -1'
482 execute 'let winExists=winheight('.winNr.') != -1'
485 if winNr == legendWinNr && winheight(legendWinNr) == 1
489 execute legendWinNr.'wincmd w'
491 call s:adjustWin('Legend','c')
492 set nomodified noswapfile nonumber readonly modifiable
493 call s:restoreCurrent()
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>'
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>'
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>'
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>'
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}
544 let {sname}=substitute({sname},'|','
\x16|','g')
545 execute 'map '.{gname}.' '.{sname}
548 let {siname}=substitute({siname},'|','
\x16|','g')
549 execute 'imap '.{gname}.' '.{siname}
553 function! s:isVimrexRunning(file)
554 if !exists("g:VimrexRunning")
557 if a:file != g:VimrexFile && a:file != g:VimrexRsltFile && a:file != g:VimrexSrcFile && a:file != g:VimRexUserCalled
560 unlet g:VimrexRunning g:VimRexUserCalled
564 if has("gui_running")
567 let winNr=bufwinnr(g:VimrexFile)
568 execute winNr.'wincmd w'
570 execute 'bwipeout '.bufnr(g:VimrexFile)
571 let winNr=bufwinnr(g:VimrexRsltFile)
572 execute winNr.'wincmd w'
574 execute 'bwipeout '.bufnr(g:VimrexRsltFile)
575 call s:delFile(g:VimrexRsltFile)
576 let winNr=bufwinnr(g:VimrexSrcFile)
577 execute winNr.'wincmd w'
579 execute 'bwipeout '.bufnr(g:VimrexSrcFile)
580 let winNr=bufwinnr(g:VimrexUsageFile)
582 execute winNr.'wincmd w'
584 execute 'bwipeout '.bufnr(g:VimrexUsageFile)
585 call s:delFile(g:VimrexUsageFile)
587 let winNr=bufwinnr('Legend')
588 execute winNr.'wincmd w'
590 execute 'bwipeout '.bufnr('Legend')
592 let &hlsearch=s:saveHLS
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')
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")
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
643 autocmd VimLeavePre,VimLeave,BufDelete * call s:isVimrexRunning(expand("<afile>"))
644 autocmd WinLeave,WinEnter,BufDelete,BufWinEnter,BufWinLeave * call s:legend()
646 let s:saveSyn=&syntax
648 let s:saveHLS=&hlsearch
650 let s:saveCPO=&cpoptions
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) !~ '^\%$'
662 if has("gui_running")
666 elseif has("gui_gtk")
670 execute 'edit! '.escape(g:VimrexSrcFile,' ')
671 if getline(1) =~ '^\%$'
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()
682 setlocal nomodified noswapfile nobackup nowritebackup nonumber syntax=vim filetype=vim
683 if exists("g:VimrexSrchPatLnk")
684 execute 'highlight link VimrexSearchPattern '.g:VimrexSrchPatLnk
686 execute 'highlight VimrexSearchPattern ctermfg='.g:VimrexSrchPatCFG.' ctermbg='.g:VimrexSrchPatCBG.' guifg='.g:VimrexSrchPatGFG.' guibg='.g:VimrexSrchPatGBG
688 if exists("g:VimrexSrchAncLnk")
689 execute 'highlight link VimrexSearchAnchor '.g:VimrexSrchAncLnk
691 execute 'highlight VimrexSearchAnchor ctermfg='.g:VimrexSrchAncCFG.' ctermbg='.g:VimrexSrchAncCBG.' guifg='.g:VimrexSrchAncGFG.' guibg='.g:VimrexSrchAncGBG
693 if exists("g:VimrexSrchTokLnk")
694 execute 'highlight link VimrexSearchToken '.g:VimrexSrchTokLnk
696 execute 'highlight VimrexSearchToken ctermfg='.g:VimrexSrchTokCFG.' ctermbg='.g:VimrexSrchTokCBG.' guifg='.g:VimrexSrchTokGFG.' guibg='.g:VimrexSrchTokGBG
698 if exists("g:VimrexSrchCgpLnk")
699 execute 'highlight link VimrexSearchCgp '.g:VimrexSrchCgpLnk
701 execute 'highlight VimrexSearchCgp ctermfg='.g:VimrexSrchCgpCFG.' ctermbg='.g:VimrexSrchCgpCBG.' guifg='.g:VimrexSrchCgpGFG.' guibg='.g:VimrexSrchCgpGBG
703 if exists("g:VimrexSrchGrpLnk")
704 execute 'highlight link VimrexSearchGrp '.g:VimrexSrchGrpLnk
706 execute 'highlight VimrexSearchGrp ctermfg='.g:VimrexSrchGrpCFG.' ctermbg='.g:VimrexSrchGrpCBG.' guifg='.g:VimrexSrchGrpGFG.' guibg='.g:VimrexSrchGrpGBG
708 if exists("g:VimrexSrchChcLnk")
709 execute 'highlight link VimrexSearchChc '.g:VimrexSrchChcLnk
711 execute 'highlight VimrexSearchChc ctermfg='.g:VimrexSrchChcCFG.' ctermbg='.g:VimrexSrchChcCBG.' guifg='.g:VimrexSrchChcGFG.' guibg='.g:VimrexSrchChcGBG
713 if exists("g:VimrexSrchExpLnk")
714 execute 'highlight link VimrexSearchExp '.g:VimrexSrchExpLnk
716 execute 'highlight VimrexSearchExp ctermfg='.g:VimrexSrchExpCFG.' ctermbg='.g:VimrexSrchExpCBG.' guifg='.g:VimrexSrchExpGFG.' guibg='.g:VimrexSrchExpGBG
718 if exists("g:VimrexFilePatLnk")
719 execute 'highlight link VimrexFilePattern '.g:VimrexFilePatLnk
721 execute 'highlight VimrexFilePattern ctermfg='.g:VimrexFilePatCFG.' ctermbg='.g:VimrexFilePatCBG.' guifg='.g:VimrexFilePatGFG.' guibg='.g:VimrexFilePatGBG
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)')
750 function! s:doSampleRegex()
751 call append(0,s:sampleRegex1)
756 call append('$',s:sampleRegex{nr})
761 function! s:doSampleSrc()
762 call append(0,s:sampleSrc1)
767 call append('$',s:sampleSrc{nr})
772 function! s:patHilite(pat,grp,...)
775 let thePat='\%'.a:1.'l'
777 let thePat=thePat.'\&\%'.a:2.'c'
780 let thePat=thePat.'\%('.escape(a:pat[0],'\[^*$~"').'\)'
782 let lidx=strlen(a:pat)
784 let theGrp='\%('.escape(a:pat[idx],'\[^*$~"').'\)'
785 let thePat=thePat.theGrp.'\@='.theGrp
788 execute 'syntax match '.a:grp.' "'.thePat.'"'
789 syntax sync fromstart
792 function! s:getAnchors(pat)
796 let matchPos=match(pat,'\\@\%[<][=!]')
797 let anchorStr=matchstr(pat,'\\@\%[<][=!]')
801 while idx >= 0 && !found
802 if pat[idx] == '\*' && pat[idx-1] != '\'
806 if pat[idx] == '}' && pat[idx-1] != '\'
808 let tmpPat=strpart(pat,idx)
809 while match(tmpPat,'\{') != 0
811 let tmpPat=strpart(pat,idx)
813 if match(tmpPat,'\{') == 0
818 if pat[idx] =~ ')' && pat[idx-1] == '\'
820 while pat[idx] != '('
823 if pat[idx] =~ '(' && pat[idx-1] == '\' && pat[idx-2] != '\'
827 if pat[idx] == '(' && pat[idx-1] == '%' && pat[idx-2] == '\' && pat[idx-3] != '\'
834 if match(anchorStr,'<') != -1
835 if s:BanchorPat == ''
836 let s:BanchorPat=strpart(pat,idx,matchPos-idx)
838 let s:BanchorPat=s:BanchorPat."\<NL>".strpart(pat,idx,matchPos-idx)
841 if s:AanchorPat == ''
842 let s:AanchorPat=strpart(pat,idx,matchPos-idx)
844 let s:AanchorPat=s:AanchorPat."\<NL>".strpart(pat,idx,matchPos-idx)
847 let pat=strpart(pat,matchPos+2)
848 let matchPos=match(pat,'\\@')
849 let anchorStr=matchstr(pat,'\\@\%[<][=!]')
858 let s:grpOpen='\\(\|\\%(\|\\%[\|[:\@!'
859 let s:grpClose='\\)\|]'
861 function! s:parsePat(pat)
867 let lidx=strlen(a:pat)
869 let restPat=strpart(a:pat,idx)
870 let firstPat=strpart(a:pat,0,idx)
872 if match(restPat,s:grpOpen) == 0
873 let opengrp=matchstr(restPat,s:grpOpen)
874 let atomIdx=strlen(matchstr(restPat,s:grpOpen))
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] != '\'
883 if restPat[atomIdx-1] == ':' && restPat[atomIdx-2] != '\'
884 let atomIdx=atomIdx+1
888 let closegrp=matchstr(tmpPat,s:grpClose)
890 let atomIdx=strlen(matchstr(tmpPat,s:grpClose))+atomIdx
892 let ingroup=ingroup-1
894 let atomIdx=atomIdx+1
898 let tmpPat=strpart(restPat,atomIdx)
899 let modMatch=match(tmpPat,'\*\|\\[+?=]\|\\@\%[<][!=]\|\\{\%[-]\%[+]\d*\%[,]\d*}')
901 let modStr=matchstr(tmpPat,'\*\|\\[+?=]\|\\@\%[<][!=]\|\\{\%[-]\%[+]\d*\%[,]\d*}')
902 let atomIdx=atomIdx+strlen(modStr)
905 let theGrp=strpart(restPat,0,atomIdx)
906 let restPat=strpart(restPat,atomIdx)
908 let theGrp='\%('.firstPat.'\)\@<=\%('.theGrp.'\)'
910 let theGrp='\%('.theGrp.'\)'
913 let theGrp=theGrp.'\%('.restPat.'\)\@='
916 let targetGrp='s:capgrp'
917 elseif opengrp == '\%('
918 let targetGrp='s:grp'
919 elseif opengrp == '\%['
920 let targetGrp='s:expansion'
922 let targetGrp='s:choice'
924 let thisGrp=StrListTok({targetGrp},'g:grpList',"\<NL>")
927 if thisGrp ==# theGrp
930 let thisGrp=StrListTok('','g:grpList')
933 let thisGrp=StrListTok('','g:grpList')
937 let {targetGrp}={targetGrp}.theGrp."\<NL>"
941 let idx=idx+atomIdx-1
953 function! s:execRegex()
955 execute bufwinnr(g:VimrexFile).'wincmd w'
956 let pattern=getline('.')
959 echomsg "No search pattern specified"
961 execute caller.'wincmd w'
964 let sameregex=(s:rline == line('.') && s:lpat ==# pattern)
966 if match(pattern,'\s*"') == 0
968 let ans=input("This could be a comment line, execute? ","n")
970 if tolower(ans[0]) == 'n'
971 execute caller.'wincmd w'
975 syntax clear VimrexFilePattern
976 let s:rline=line('.')
978 call s:patHilite(pattern,'VimrexFilePattern',s:rline)
980 call s:parsePat(pattern)
981 if match(pattern,'\\@') != -1
982 call s:getAnchors(pattern)
988 execute bufwinnr(g:VimrexSrcFile).'wincmd w'
992 execute bufwinnr(g:VimrexRsltFile).'wincmd w'
994 call append(line('.'),">>".pattern."<< search error: ".v:errmsg)
997 echomsg ">>".pattern."<< search error: ".v:errmsg
999 execute bufwinnr(g:VimrexSrcFile).'wincmd w'
1000 execute caller.'wincmd w'
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
1012 let sline=getline('.')
1016 call cursor(line('$'),col('$'))
1017 call cursor(line('$'),col('$'))
1019 call cursor(lnum-1,col('$'))
1020 call cursor(lnum-1,col('$'))
1023 call cursor(lnum,cnum-1)
1025 execute "silent! normal //e\<CR>"
1026 let matchEnd=col('.')
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,'"').'"'
1044 let matchAnchor=match(sline,thisAnchor,matchAnchor+1)
1046 let thisAnchor=StrListTok('','b:anchors')
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,'"').'"'
1061 let thisAnchor=StrListTok('','b:anchors')
1065 execute 'syntax match VimrexSearchPattern "'.escape(pattern,'"').'" contains=VimrexSearchToken'
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'
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."<<")
1079 execute bufwinnr(g:VimrexSrcFile).'wincmd w'
1080 call cursor(lnum,cnum)
1081 execute caller.'wincmd w'
1084 function! s:hiliteGrp(which,synGrp,lnum,matchPos)
1085 let sline=getline(a:lnum)
1086 let grp=StrListTok(a:which,'g:VimrexHLgrp',"\<NL>")
1089 let grpTokStrt=match(sline,grp,strt)
1090 while grpTokStrt != -1
1091 let grpTok=matchstr(sline,grp,strt)
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'
1097 let grpTokEnd=grpTokStrt+1
1100 let grpTokStrt=match(sline,grp,strt)
1102 let grp=StrListTok('','g:VimrexHLgrp')
1104 unlet! g:VimrexHLgrp
1107 function! s:saveCurrent()
1109 let s:cBuf=bufnr('')
1110 let s:clnum=line('.')
1111 let s:ccnum=col('.')
1114 function! s:restoreCurrent()
1115 if winnr() != s:cWin
1116 execute s:cWin.'wincmd w'
1119 call cursor(s:clnum,s:ccnum)
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
1129 call s:saveCurrent()
1130 execute bufwinnr(a:which).'wincmd w'
1136 call s:restoreCurrent()
1137 if a:which == g:VimrexFile
1142 function! s:delFile(fname)
1143 let fname=glob(a:fname)
1147 let failure=delete(fname)
1152 echomsg expand("<sfile>").": Could not delete <".fname.">"
1153 echomsg "Reason: ".v:errmsg
1155 echomsg " Press a key to continue"
1160 function! TranslateRegex(...)
1163 execute bufwinnr(g:VimrexFile).'wincmd w'
1164 let s:pat=getline('.')
1167 echomsg "No search pattern specified"
1171 let sameregex=(s:rline == line('.') && s:lpat ==# s:pat)
1173 if match(s:pat,'\s*"') == 0
1175 let ans=input("This could be a comment line, execute? ","n")
1177 if tolower(ans[0]) == 'n'
1181 syntax clear VimrexFilePattern
1182 let s:rline=line('.')
1184 call s:patHilite(s:pat,'VimrexFilePattern',s:rline)
1186 call s:parsePat(s:pat)
1187 if match(s:pat,'\\@') != -1
1188 call s:getAnchors(s:pat)
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
1202 execute bufwinnr(g:VimrexRsltFile).'wincmd w'
1206 call append(line('$'),'Analyzing pattern: '.b:pat)
1209 execute "normal z\<CR>"
1212 echomsg 'Analyzing pattern: '.b:pat
1215 let desc=s:getTokDesc(b:pat,'b:foundPat','b:pat')
1218 let indents=s:ingroup
1219 if match(b:foundPat,'^\%(\\(\|\\%(\|[\|\\%[\):\@!') != -1
1220 let indents=indents-1
1228 let indents=indents-1
1232 call append(line('$'),pad.b:foundPat.' >>:'.desc)
1235 echomsg pad.b:foundPat.' >>:'.desc
1238 unlet! b:pat b:foundPat
1240 execute bufwinnr(g:VimrexFile).'wincmd w'
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)
1251 let theDesc=qualify.' match'
1253 let commaPos=match(qualifier,',')
1254 let low=strpart(qualifier,0,commaPos)
1255 let high=strpart(qualifier,commaPos+1)
1257 let theDesc=theDesc.' from '.low
1259 let theDesc=theDesc.' from 0'
1262 let theDesc=theDesc.' to '.high.' of previous atom'
1264 let theDesc=theDesc.' to maximum of previous atom'
1267 let theDesc=theDesc.' of 0 or more of previous atom'
1270 let theDesc='exactly '.qualifier.' of previous atom'
1275 function! s:charClassDesc(class)
1276 let theClass=StrListTok(s:charClass,'b:charClass',"\<NL>")
1278 while theClass != '' && !found
1279 if theClass ==# a:class
1280 let theDesc=StrListTok('','b:charClass')
1281 while StrListTok('','b:charClass') != ''
1286 let theClass=StrListTok('','b:charClass')
1290 let theDesc='Unknown class'
1295 function! s:getTokDesc(pat,thePat,retPat)
1297 let lidx=strlen(a:pat)
1299 let opener=matchstr(a:pat,'^\%(\\(\|\\%(\|[\|\\%[\):\@!')
1301 let s:ingroup=s:ingroup+1
1303 let closer=matchstr(a:pat,'^\%(\\)\|]\):\@!')
1305 let s:ingroup=s:ingroup-1
1309 elseif s:inExpansion
1314 let matchPos=match(a:pat,'\%(\[:\)\@<=\%(\a\+\%(:]\)\@=\)')
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)
1322 if s:inExpansion && a:pat[0] != ']' && a:pat[0] != '[' && a:pat[0] != '\'
1323 let matchPos=match(a:pat,'\%(]\|[\|\\\)')
1324 if a:pat[matchPos] == ']'
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').'<<'
1332 if s:inChoice && a:pat[0] != ']'
1333 let matchPos=match(a:pat,'\%(]\|\[:\)')
1334 if a:pat[matchPos] == ']'
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').'<<'
1342 let matchPos=match(a:pat,'\%(\\{\)\@<=\%(\%(\%(-\|+\)\?\d*,\?\d*\)}\@=\)')
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)
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"
1360 if match(s:VimRegExTokBS1stChar,a:pat[1]) == -1 || a:pat[1] == '.'
1362 while match(s:VimRegExTokOpen,escape(a:pat[idx],'$~.^')) == -1
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).'<<'
1370 if match(s:VimRegExTokOpen,escape(a:pat[0],'$~^*.')) == -1
1372 while match(s:VimRegExTokOpen,escape(a:pat[idx],'$~.^')) == -1
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).'<<'
1379 if match(a:pat,'^\\%[') != -1
1385 let {a:retPat}=strpart(a:pat,2)
1387 return 'begin disallowed choice list'
1389 let {a:retPat}=strpart(a:pat,1)
1391 return 'begin allowed choice list'
1394 while idx < lidx && !found
1395 let thisPat=StrListTok(s:VimRegExTokDesc,'b:thisTokDescList',"\<NL>")
1396 let matchPat=strpart(a:pat,0,idx+1)
1398 let theDesc=StrListTok('','b:thisTokDescList')
1401 let theDesc='begin line'
1402 while StrListTok('','b:thisTokDescList') != ''
1407 if matchPat ==# thisPat
1408 while StrListTok('','b:thisTokDescList') != ''
1413 let thisPat=StrListTok('','b:thisTokDescList')
1419 let {a:thePat}=a:pat
1420 unlet! b:thisTokDescList
1421 return 'literal character(s): >>'.a:pat.'<<'
1423 let {a:retPat}=strpart(a:pat,idx)
1424 let {a:thePat}=thisPat
1425 unlet! b:thisTokDescList
1429 if exists('loaded_regex_token_descriptions')
1432 let loaded_regex_token_descriptions=1
1433 let s:VimRegExTokBS1stChar='%|&+<=>?@ACDFHIKLMOPSUVWXZ_abcdefhiklmnoprstuvwxz()\'
1441 \letters and decimal digits\<NL>
1449 \decimal digits\<NL>
1451 \printable except space\<NL>
1455 \printable including space\<NL>
1463 \hexadecimal digits\<NL>
1465 \carriage return (non-POSIX)\<NL>
1467 \tab (non-POSIX)\<NL>
1469 \esc (non-POSIX)\<NL>
1473 let s:VimRegExTokOpen='$\\~^*.[]'
1474 let s:VimRegExTokDesc="
1478 \0 or more of previous atom\<NL>
1480 \any but newline\<NL>
1482 \end choice list or expansion sequence\<NL>
1484 \begin expansion sequence\<NL>
1486 \end of file or string\<NL>
1488 \previous atom and next atom are required together ('and')\<NL>
1490 \previous atom and next atom are alternate choices ('or')\<NL>
1492 \begin capture group\<NL>
1496 \begin non-capture group\<NL>
1500 \start of file or string\<NL>
1502 \1 or more of previous atom\<NL>
1504 \begin word boundary\<NL>
1506 \0 or 1 of previous atom\<NL>
1508 \end word boundary\<NL>
1510 \0 or 1 of previous atom\<NL>
1512 \negative lookahead== previous atom present ? no match : match\<NL>
1514 \negative lookbehind== previous atom present ? no match : match\<NL>
1516 \positive lookbehind== previous atom present ? match : no match\<NL>
1518 \positive lookahead== previous atom present ? match : no match\<NL>
1520 \'grab all' independent subexpression\<NL>
1526 \non-digit (decimal)\<NL>
1528 \non-filename non-digit (decimal)\<NL>
1530 \non-head of word (alpha or _)\<NL>
1532 \non-identifier non-digit (decimal)\<NL>
1534 \non-keyword non-digit (decimal)\<NL>
1538 \magic off for following\<NL>
1540 \non-digit (octal)\<NL>
1542 \printable non-digit (decimal)\<NL>
1544 \non-whitespace\<NL>
1548 \very magic off for following\<NL>
1550 \non-word (alpha or decimal or _)\<NL>
1552 \non-digit (hex)\<NL>
1554 \ignore Unicode combine diff\<NL>
1556 \following and newline\<NL>
1558 \end of line (anywhere)\<NL>
1560 \single char or end of line\<NL>
1562 \start of line (anywhere)\<NL>
1566 \backspace <BS>\<NL>
1570 \digit (decimal)\<NL>
1576 \head of word (alpha or _)\<NL>
1584 \magic on for following\<NL>
1586 \newline (possibly combination)\<NL>
1592 \carriage return <CR>\<NL>
1594 \whitespace <Space> or <Tab>\<NL>
1600 \very magic on for following\<NL>
1602 \word (alpha or decimal or _)\<NL>
1606 \previous atom is end of whole match\<NL>
1608 \following is start of whole match\<NL>
1610 \last given substitute
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
1798 if bufwinnr(g:VimrexUsageFile) != -1
1802 echomsg 'Generating Usage Document...'
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)
1830 call s:delFile(g:VimrexUsageFile)
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
1965 function s:doUsageSection(sect)
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')
1973 let usageLine=getline(lnum)
1975 call append(line('$'),usageLine)
1981 execute 'silent '.bufnr(s:thisScript).'bd'
1982 call s:doUsageSyntax()
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
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 +----------------------------------------------------------------------+
2020 |regular expression |
2022 | Build regular expressions here |
2027 |----------------------------------------------------------------------|
2031 | Execution/Analysis results displayed here |
2036 |----------------------------------------------------------------------|
2040 | Text to be searched goes here |
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
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
2080 There are eight highlight groups used. They are:
2091 current regex is used to highlight the current regular expression in the top
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
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
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
2139 See: :h tohtml, then /Remarks: (search for 'Remarks:').
2143 END MANUAL SECTION SEVEN