diff options
Diffstat (limited to 'Master/texmf-dist/tex/context/third/vim/2context.vim')
-rw-r--r-- | Master/texmf-dist/tex/context/third/vim/2context.vim | 99 |
1 files changed, 37 insertions, 62 deletions
diff --git a/Master/texmf-dist/tex/context/third/vim/2context.vim b/Master/texmf-dist/tex/context/third/vim/2context.vim index ef238121a33..7e2f32864a5 100644 --- a/Master/texmf-dist/tex/context/third/vim/2context.vim +++ b/Master/texmf-dist/tex/context/third/vim/2context.vim @@ -1,35 +1,27 @@ -"D \module -"D [ file=2context.vim, -"D version=2007.01.03, -"D title=ViM to \CONTEXT, -"D subtitle=Use ViM to generate code listing, -"D author=Mojca Miklavec \& Aditya Mahajan, -"D email=adityam at umich dot edu, -"D date=\currentdate, -"D copyright=Public Domain] - -"D This file is based on \filename{2html.vim}. It uses ViM systax highlighting -"D to generate a \CONTEXT\ file which is parsed using \filename{t-vimsyntax} -"D module. - -"D We use \filename{.tmp} extension so that the file is purged by -"D \filename{ctxtools} +" Author : Aditya Mahajan +" version : 0.2 +" This script converts the syntax highlighting of a file to ConTeXt. This file +" is based on 2html.vim. + +" Create a new buffer with .vimout extension if expand("%") == "" - new vimsyntax.tmp + new texput.vimout else - new %-vimsyntax.tmp + new %:r.vimout endif -"D We are right now in the new buffer. - +" Make sure that the buffer is modifiable set modifiable -%d "This empties the buffer. +" ... and empty +%d + +" Go to previous buffer wincmd p -"D Loop over all lines in the original text. -"D Use contextstartline and contextstopline if they are set. +" Loop over all lines in the original text. +" Use contextstartline and contextstopline if they are set. if exists("contextstartline") let s:lnum = contextstartline @@ -52,59 +44,42 @@ endif let s:buffer_lnum = 1 while s:lnum <= s:end -"D Get the current line +" Get the current line let s:line = getline(s:lnum) let s:len = strlen(s:line) - let s:new = "" + let s:new = "\\NL{}" -"D Loop over each character in the line +" Loop over each character in the line let s:col = 1 while s:col <= s:len let s:startcol = s:col " The start column for processing text let s:id = synID (s:lnum, s:col, 1) let s:col = s:col + 1 -"D Speed loop (it's small - that's the trick) -"D Go along till we find a change in synID +" Speed loop (it's small - that's the trick) +" Go along till we find a change in synID while s:col <= s:len && s:id == synID(s:lnum, s:col, 1) let s:col = s:col + 1 endwhile -"D Output the text with the same synID, with class set to {s:id_name} +" Output the text with the same synID, with class set to {s:id_name} let s:id = synIDtrans (s:id) let s:id_name = synIDattr (s:id, "name", "gui") let s:temp = strpart(s:line, s:startcol - 1, s:col - s:startcol) -"D Remove line endings (on unix machines reading windows files) +" Remove line endings (on unix machines reading windows files) let s:temp = substitute(s:temp, '\r*$', '', '') -"D It might have happened that that one has been the last item in a row, so -"D we don't need to print in in that case +" It might have happened that that one has been the last item in a row, so +" we don't need to print in in that case if strlen(s:temp) > 0 -"D We need to get rid of the characters that can cause trouble in \CONTEXT. -"D The funny \type{||||||||||} and \type{$$$$$$$$$} characters should never -"D appear in {\em normal} \TEX\ file. As a side||effect, this script can not -"D pretty print itself. - let s:temp = substitute( s:temp, '\\', '||||||||||\\letterbackslash$$$$$$$$$$', 'g') - let s:temp = substitute( s:temp, '{', '||||||||||\\letteropenbrace$$$$$$$$$$', 'g') - let s:temp = substitute( s:temp, '}', '||||||||||\\letterclosebrace$$$$$$$$$$', 'g') +" Change special TeX characters to escape sequences. +" The funny \type{||||||||||} and \type{$$$$$$$$$} characters should never +" appear in {\em normal} \TEX\ file. As a side||effect, this script can not +" pretty print itself. + let s:temp = substitute( s:temp, '\\', '\\letterbackslash||||||||||$$$$$$$$$$', 'g') + let s:temp = substitute( s:temp, '{', '\\letteropenbrace||||||||||$$$$$$$$$$', 'g') + let s:temp = substitute( s:temp, '}', '\\letterclosebrace||||||||||$$$$$$$$$$', 'g') let s:temp = substitute( s:temp, '||||||||||' , '{' , 'g') let s:temp = substitute( s:temp, '\$\$\$\$\$\$\$\$\$\$' , '}' , 'g') - let s:temp = substitute( s:temp, '&', '{\\letterampersand}', 'g') - let s:temp = substitute( s:temp, '<', '{\\letterless}', 'g') - let s:temp = substitute( s:temp, '>', '{\\lettermore}', 'g') - let s:temp = substitute( s:temp, '#', '{\\letterhash}', 'g') - let s:temp = substitute( s:temp, '"', '{\\letterdoublequote}', 'g') - let s:temp = substitute( s:temp, "'", '{\\lettersinglequote}', 'g') - let s:temp = substitute( s:temp, '\$', '{\\letterdollar}', 'g') - let s:temp = substitute( s:temp, '%', '{\\letterpercent}', 'g') - let s:temp = substitute( s:temp, '\^', '{\\letterhat}', 'g') - let s:temp = substitute( s:temp, '_', '{\\letterunderscore}', 'g') - let s:temp = substitute( s:temp, '|', '{\\letterbar}', 'g') - let s:temp = substitute( s:temp, '\~', '{\\lettertilde}', 'g') - let s:temp = substitute( s:temp, '/', '{\\letterslash}', 'g') - let s:temp = substitute( s:temp, '?', '{\\letterquestionmark}', 'g') - let s:temp = substitute( s:temp, '!', '{\\letterexclamationmark}', 'g') - let s:temp = substitute( s:temp, '@', '{\\letterat}', 'g') - let s:temp = substitute( s:temp, ':', '{\\lettercolon}', 'g') - let s:new = s:new . '\s[' . s:id_name . ']{' . s:temp . '}' + let s:new = s:new . '\SYN[' . s:id_name . ']{' . s:temp . '}' endif " Why will we ever enter this loop @@ -113,29 +88,29 @@ while s:lnum <= s:end " endif endwhile -"D Expand tabs +" Expand tabs let s:pad = 0 let s:start = 0 let s:idx = stridx(s:line, "\t") while s:idx >= 0 let s:i = &ts - ((s:start + s:pad + s:idx) % &ts) -" let s:new = substitute(s:new, '\t', strpart(s:expandedtab, 0, s:i), '') +" let s:new = substitute(s:new, '\t', strpart(s:expandedtab, 0, s:i), '') let s:new = substitute(s:new, '\t', '\\tab{' . s:i . '}', '') let s:pad = s:pad + s:i - 1 let s:start = s:start + s:idx + 1 let s:idx = stridx(strpart(s:line, s:start), "\t") endwhile -"D Go back and paste the current line +" Go back and paste the current line wincmd p call append (s:buffer_lnum-1, s:new) wincmd p -"D Increment line numbers +" Increment line numbers let s:lnum = s:lnum + 1 let s:buffer_lnum = s:buffer_lnum + 1 endwhile wincmd p -"D We have a spurious line in the end. So we remove it. +" We have a spurious line in the end. So we remove it. $delete |