From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/24080 Path: news.gmane.org!not-for-mail From: Nikolai Weibull Newsgroups: gmane.comp.tex.context Subject: Re: An idea Date: Sat, 3 Dec 2005 20:45:57 +0100 Message-ID: <20051203194557.GA8903@puritan.petwork> References: <20051201162914.GA14497@fly.srk.fer.hr> <20051202165636.GA8858@puritan.petwork> <20051202174653.GB3376@fly.srk.fer.hr> <20051202184337.GB8858@puritan.petwork> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="azLHFNyN32YCQGCU" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1133639216 23805 80.91.229.2 (3 Dec 2005 19:46:56 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 3 Dec 2005 19:46:56 +0000 (UTC) Original-X-From: ntg-context-bounces@ntg.nl Sat Dec 03 20:46:54 2005 Return-path: Original-Received: from ronja.vet.uu.nl ([131.211.172.88] helo=ronja.ntg.nl) by ciao.gmane.org with esmtp (Exim 4.43) id 1EidKi-0003MH-NM for gctc-ntg-context-518@m.gmane.org; Sat, 03 Dec 2005 20:46:08 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id BCE99127D7; Sat, 3 Dec 2005 20:46:07 +0100 (CET) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 31776-05; Sat, 3 Dec 2005 20:46:01 +0100 (CET) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 34DFF127C0; Sat, 3 Dec 2005 20:46:01 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id C2BAC127C0 for ; Sat, 3 Dec 2005 20:45:59 +0100 (CET) Original-Received: from ronja.ntg.nl ([127.0.0.1]) by localhost (smtp.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 31496-09 for ; Sat, 3 Dec 2005 20:45:58 +0100 (CET) Original-Received: from mxfep01.bredband.com (mxfep01.bredband.com [195.54.107.70]) by ronja.ntg.nl (Postfix) with ESMTP id 613D2127A0 for ; Sat, 3 Dec 2005 20:45:58 +0100 (CET) Original-Received: from puritan.petwork ([213.112.43.250] [213.112.43.250]) by mxfep01.bredband.com with ESMTP id <20051203194557.QRGI676.mxfep01.bredband.com@puritan.petwork> for ; Sat, 3 Dec 2005 20:45:57 +0100 Original-Received: by puritan.petwork (Postfix, from userid 1000) id A6B99ADFE5; Sat, 3 Dec 2005 20:45:57 +0100 (CET) Original-To: ntg-context@ntg.nl Content-Disposition: inline In-Reply-To: <20051202184337.GB8858@puritan.petwork> User-Agent: Mutt/1.5.11 X-Virus-Scanned: amavisd-new at ntg.nl X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.5 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: ntg-context-bounces@ntg.nl Errors-To: ntg-context-bounces@ntg.nl X-Virus-Scanned: amavisd-new at ntg.nl Xref: news.gmane.org gmane.comp.tex.context:24080 Archived-At: --azLHFNyN32YCQGCU Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Nikolai Weibull wrote: > It would require very little programming. syntax/2html.vim, which > converts the buffer to a HTML document with syntax highlighting, is 526 > lines in the current CVS incarnation. A syntax/2context.vim would be > even shorter, perhaps 150 to 200 lines. If I find the time I=E2=80=99l= l write > something this weekend. I=E2=80=99m catching a could though, so I migh= t not > :-(. A splitting headache notwithstanding, here=E2=80=99s a syntax/2context.vi= m that weighs in at 170 lines. There are still things to do, like figuring out how to complement this on the ConTeXt side (i.e., defining \highlight) and things will depend on how this is done. Some sort of \type environment would be nice, as it is better to not do escaping of special characters on the Vim side. Someone with better knowledge of how to do this than I have is welcome to finish it. The \highlight command should be defined something like this (pseudo-tex-code): \pdef\highlight[#1]{#2}% {\bgroup \setupcolorforgroup[#1]% \type{#2}% \egroup} #1 is a group name, such as Statement, Operator, or Comment. #2 may contain multiple lines, and I don=E2=80=99t know how well this will work = on the TeX side. It may also contain special characters like {, #, &, and so on. Suggestions? nikolai --=20 Nikolai Weibull: now available free of charge at http://bitwi.se/! Born in Chicago, IL USA; currently residing in Gothenburg, Sweden. main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);} --azLHFNyN32YCQGCU Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="2context.vim" Content-Transfer-Encoding: quoted-printable " Vim syntax support file " Maintainer: Nikolai Weibull " Latest Revision: 2005-12-03 function! s:Format(text, group) let formatted =3D strtrans(a:text) " TODO: Replace the reserved ConTeXt characters. return "\\highlight[" . a:group . ']{' . formatted . '}' endfun " Set up options. let s:old_title =3D &title let s:old_icon =3D &icon let s:old_et =3D &l:et let s:old_report =3D &report let s:old_search =3D @/ set notitle noicon setlocal et set report=3D1000000 " Split window to create a buffer with the HTML file. let s:org_bufnr =3D winbufnr(0) if expand("%") =3D=3D "" new untitled.tex else new %.tex endif let s:new_win =3D winnr() let s:org_win =3D bufwinnr(s:org_bufnr) " Set up options in the new buffer. set modifiable %d let s:old_paste =3D &paste set paste let s:old_magic =3D &magic set magic " Set up the buffer=E2=80=99s =E2=80=9Cheader=E2=80=9D. exe "normal! a\\startlines\n\e" " Switch to the original window. exe s:org_win . 'wincmd w' " Variables to keep track of the range to convert. let s:lnum =3D 1 let s:end =3D line('$') " Set up stuff for handling folding. if has('folding') && !exists('context_ignore_folding') let s:foldfillchar =3D &fillchars[matchend(&fillchars, 'fold:')] if s:foldfillchar =3D=3D '' let s:foldfillchar =3D '-' endif endif " Set up stuff for handling diffs. let s:difffillchar =3D &fillchars[matchend(&fillchars, 'diff:')] if s:difffillchar =3D=3D '' let s:difffillchar =3D '-' endif " Now, loop over all lines in the range. while s:lnum <=3D s:end " If there are filler lines for diff mode, show these above the line. let s:filler =3D diff_filler(s:lnum) if s:filler > 0 let s:n =3D s:filler while s:n > 0 let s:new =3D repeat(s:difffillchar, 3) if s:n > 2 && s:n < s:filler && !exists('context_whole_filler') let s:new =3D s:new . " " . s:filler . ' inserted lines ' let s:n =3D 2 endif let s:new =3D s:new . repeat(s:difffillchar, &columns - strlen(s:ne= w)) let s:new =3D s:Format(s:new, 'DiffDelete') exe s:new_win . 'wincmd w' exe 'normal! a' . s:new . "\n\e" exe s:org_win . 'wincmd w' let s:n -=3D 1 endwhile unlet s:n endif unlet s:filler let s:new =3D "" if has('folding') && !exists('context_ignore_folding') && foldclosed(s:= lnum) > -1 let s:new =3D s:Format(s:new . foldtextresult(s:lnum), 'Folded') let s:lnum =3D foldclosedend(s:lnum) else let s:line =3D getline(s:lnum) let s:len =3D strlen(s:line) let s:diffattr =3D diff_hlID(s:lnum, 1) let s:col =3D 1 while s:col <=3D s:len || (s:col =3D=3D 1 && s:diffattr) let s:startcol =3D s:col " The start column for processing text. if s:diffattr let s:id =3D diff_hlID(s:lnum, s:col) let s:col +=3D 1 while s:col <=3D s:len && s:id =3D=3D diff_hlID(s:lnum, s:col) | let s:c= ol +=3D 1 | endwhile if s:len < &columns " Add spaces at the end to mark the changed line. let s:line =3D s:line . repeat(' ', &columns - s:len) let s:len =3D &columns endif else let s:id =3D synID(s:lnum, s:col, 1) let s:col +=3D 1 while s:col <=3D s:len && s:id =3D=3D synID(s:lnum, s:col, 1) | let s:co= l +=3D 1 | endwhile endif " Expand tabs. let s:expanded =3D strpart(s:line, s:startcol - 1, s:col - s:startc= ol) let idx =3D stridx(s:expanded, "\t") while idx >=3D 0 let i =3D &ts - (idx + s:startcol - 1) % &ts let s:expanded =3D substitute(s:expanded, '\t', repeat(' ', i), '= ') let idx =3D stridx(s:expanded, "\t") endwhile " Output the text with the same synID, with class set to {s:id_name= }. let s:id =3D synIDtrans(s:id) let s:id_name =3D synIDattr(s:id, 'name') if s:expanded !~ '^\s*$' let s:new =3D s:new . s:Format(s:expanded, s:id_name) else let s:new =3D s:new . s:expanded endif endwhile endif exe s:new_win . 'wincmd w' exe 'normal! a' . s:new . "\n\e" exe s:org_win . 'wincmd w' let s:lnum =3D s:lnum + 1 endwhile " Cleanup. exe s:new_win . 'wincmd w' exe "normal! a\\stoplines\n\e" %s:\s\+$::e $g/^$/d " Restore old settings let &report =3D s:old_report let &title =3D s:old_title let &icon =3D s:old_icon let &paste =3D s:old_paste let &magic =3D s:old_magic let @/ =3D s:old_search exe s:org_win . 'wincmd w' let &l:et =3D s:old_et exe s:new_win . 'wincmd w' " Save a little bit of memory (worth doing?) unlet s:old_et s:old_paste s:old_icon s:old_report s:old_title s:old_sear= ch unlet s:lnum s:end s:old_magic unlet! s:col s:id s:attr s:len s:line s:new s:expandedtab unlet s:org_win s:new_win s:org_bufnr if !v:profiling delfunc s:Format endif silent! unlet s:diffattr s:difffillchar s:foldfillchar --azLHFNyN32YCQGCU Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ ntg-context mailing list ntg-context@ntg.nl http://www.ntg.nl/mailman/listinfo/ntg-context --azLHFNyN32YCQGCU--