From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/24097 Path: news.gmane.org!not-for-mail From: Nikolai Weibull Newsgroups: gmane.comp.tex.context Subject: Re: An idea Date: Sun, 4 Dec 2005 18:57:48 +0100 Message-ID: <20051204175748.GB8819@puritan.petwork> References: <20051201162914.GA14497@fly.srk.fer.hr> <20051202165636.GA8858@puritan.petwork> <20051202174653.GB3376@fly.srk.fer.hr> <20051202184337.GB8858@puritan.petwork> <20051203194557.GA8903@puritan.petwork> <439220C0.5000007@creutzig.de> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="TB36FDmn/VVEgNH/" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1133719398 2611 80.91.229.2 (4 Dec 2005 18:03:18 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 4 Dec 2005 18:03:18 +0000 (UTC) Original-X-From: ntg-context-bounces@ntg.nl Sun Dec 04 19:03:16 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 1EiyBN-0002xv-AU for gctc-ntg-context-518@m.gmane.org; Sun, 04 Dec 2005 19:01:53 +0100 Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id CD1FE127F0; Sun, 4 Dec 2005 19:01:52 +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 29856-02-2; Sun, 4 Dec 2005 19:01:48 +0100 (CET) Original-Received: from ronja.vet.uu.nl (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id 4D8E212791; Sun, 4 Dec 2005 19:01:48 +0100 (CET) Original-Received: from localhost (localhost [127.0.0.1]) by ronja.ntg.nl (Postfix) with ESMTP id E62F31278B for ; Sun, 4 Dec 2005 19:01:46 +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 29862-10 for ; Sun, 4 Dec 2005 19:01:45 +0100 (CET) Original-Received: from mxfep02.bredband.com (mxfep02.bredband.com [195.54.107.73]) by ronja.ntg.nl (Postfix) with ESMTP id 54B88127D9 for ; Sun, 4 Dec 2005 18:57:48 +0100 (CET) Original-Received: from puritan.petwork ([213.112.43.250] [213.112.43.250]) by mxfep02.bredband.com with ESMTP id <20051204175747.CGH17186.mxfep02.bredband.com@puritan.petwork> for ; Sun, 4 Dec 2005 18:57:47 +0100 Original-Received: by puritan.petwork (Postfix, from userid 1000) id BEA72ADFE5; Sun, 4 Dec 2005 18:57:48 +0100 (CET) Original-To: ntg-context@ntg.nl Content-Disposition: inline In-Reply-To: <439220C0.5000007@creutzig.de> 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:24097 Archived-At: --TB36FDmn/VVEgNH/ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Christopher Creutzig wrote: > Nikolai Weibull wrote: >=20 > > this than I have is welcome to finish it. The \highlight command > > should be defined something like this (pseudo-tex-code): > >=20 > > \pdef\highlight[#1]{#2}% > > {\bgroup > > \setupcolorforgroup[#1]% > > \type{#2}% > > \egroup} > >=20 > > #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 w= ork on > > the TeX side. It may also contain special characters like {, #, &, > > and so on. Suggestions? >=20 > The most simple one I expect to work would be >=20 > \def\highlight[#1]{% > \bgroup > \setuphighlightcolors[{#1}]% never forget those {}, > % % since [] aren't balanced! > \processinlineverbatim\egroup}% \egroup is an argument to > % % \processinlineverbatim here >=20 OK, check the attachments for what I=E2=80=99ve got so far. It works wel= l it seems. Still need to do more escaping, though. 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);} --TB36FDmn/VVEgNH/ 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-04 function! s:Format(text, group) let formatted =3D strtrans(a:text) let formatted =3D substitute(formatted, '{', '\\leftargument', 'g') let formatted =3D substitute(formatted, '}', '\\rightargument', 'g') " TODO: Replace the reserved ConTeXt characters. " TODO: make sure to escape everything. if a:group !=3D "" let formatted =3D "\\highlight[" . a:group . ']{' . formatted . '}' endif return formatted endfunction function! s:Append(text) exe s:new_win . 'wincmd w' call append(line('$'), a:text) exe s:org_win . 'wincmd w' endfunction function! s:AppendFillers(filler, diff_fillchar) let n =3D filler while n > 0 let new =3D repeat(diff_fillchar, 3) if n > 2 && n < filler && !exists('context_whole_filler') let new .=3D ' ' . filler . ' inserted lines ' let n =3D 2 endif let new .=3D repeat(diff_fillchar, &columns - strlen(new)) call s:Append(s:Format(new, 'DiffDelete')) let n -=3D 1 endwhile endfunction function! s:GetFillChar(char, default) let fillchar =3D &fillchars[matchend(&fillchars, a:char . ':')] return (fillchar !=3D '' ? fillchar : default) endfunction function! s:MainLoop() " Set up stuff for handling folding. if has('folding') && !exists('context_ignore_folding') let fold_fillchar =3D s:GetFillChar('fold', '-') endif " Set up stuff for handling diffs. let diff_fillchar =3D s:GetFillChar('diff', '-') let lnum =3D 1 let last =3D line('$') while lnum <=3D last " If there are filler lines for diff mode, show these above the line. let filler =3D diff_filler(lnum) if filler > 0 call s:AppendFillers(filler, diff_fillchar) endif let new =3D "" if has('folding') && !exists('context_ignore_folding') && foldclosed(= lnum) > -1 let new =3D s:Format(new . foldtextresult(lnum), 'Folded') let lnum =3D foldclosedend(lnum) else let line =3D getline(lnum) let len =3D strlen(line) let diff_attr =3D diff_hlID(lnum, 1) let col =3D 1 while col <=3D len || (col =3D=3D 1 && diff_attr) let start_col =3D col " The start column for processing text. if diff_attr let id =3D diff_hlID(lnum, col) let col +=3D 1 while col <=3D len && id =3D=3D diff_hlID(lnum, col) | let col = +=3D 1 | endwhile if len < &columns " Add spaces at the end to mark the changed line. let line =3D line . repeat(' ', &columns - len) let len =3D &columns endif else " TODO: why not use synIDtrans here instead? That=E2=80=99t gi= ve longest " possible matches. let id =3D synID(lnum, col, 1) let col +=3D 1 while col <=3D len && id =3D=3D synID(lnum, col, 1) | let col += =3D 1 | endwhile endif " Expand tabs. " TODO: make a function? let new .=3D s:ExpandAndFormat(strpart(.= ..), id) let expanded =3D strpart(line, start_col - 1, col - start_col) let idx =3D stridx(expanded, "\t") while idx >=3D 0 let i =3D &ts - (idx + start_col - 1) % &ts let expanded =3D substitute(expanded, '\t', repeat(' ', i), '') let idx =3D stridx(expanded, "\t") endwhile if expanded =3D~ '^\s*$' let new .=3D expanded else let new .=3D s:Format(expanded, synIDattr(synIDtrans(id), 'name= ')) endif endwhile endif call s:Append(new) let lnum =3D lnum + 1 endwhile endfunction " Set up options. let s:old_title =3D &title let s:old_icon =3D &icon let s:old_search =3D @/ set notitle noicon " Split window to create a buffer with the ConTeXt 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 the new buffer. set modifiable %delete call setline(1, '\startlines') " Switch to the original window. exe s:org_win . 'wincmd w' call s:MainLoop() " Cleanup. exe s:new_win . 'wincmd w' call append(line('$'), '\stoplines') silent %s:\s\+$::e " Restore old settings. let &title =3D s:old_title let &icon =3D s:old_icon let @/ =3D s:old_search " Save a little bit of memory. (Is this worth doing?) unlet s:old_title s:old_icon s:old_search unlet s:org_bufnr s:new_win s:org_win if !v:profiling delfunction s:Format delfunction s:Append delfunction s:AppendFillers delfunction s:GetFillChar delfunction s:MainLoop endif --TB36FDmn/VVEgNH/ Content-Type: text/x-csrc; charset=iso-8859-1 Content-Disposition: attachment; filename="b.c" Content-Transfer-Encoding: quoted-printable /* * contents: unknown * * Copyright =A9 2005 Nikolai Weibull */ int main(void) { return 0; } --TB36FDmn/VVEgNH/ Content-Type: text/x-tex; charset=iso-8859-1 Content-Disposition: attachment; filename="b.c.tex" Content-Transfer-Encoding: quoted-printable \enableregime[utf] \setupcolors [state=3Dstart] \definecolor [Comment] [r=3D0.14509803921568629, g=3D0.4509803921568= 6275, b=3D0.14509803921568629] \definecolor [Type] [r=3D0.37647058823529411, g=3D0.1843137254901= 9609, b=3D0.50196078431372548] \definecolor [Identifier] [r=3D0.18431372549019609, g=3D0.3529411764705= 8826, b=3D0.60784313725490191] \definecolor [Statement] [r=3D0.46274509803921571, g=3D0.3764705882352= 9411, b=3D0.12549019607843137] \definecolor [Constant] [r=3D0.58431372549019611, g=3D0.0862745098039= 21567, b=3D0.086274509803921567] \def\highlight[#1]% {\bgroup\startcolor[#1]\processinlineverbatim{\stopcolor\egroup}} \setuplines[space=3Dyes] \starttext \startlines \setverbatimspaceskip \frenchspacing \parindent\zeropoint \verbatimfont \highlight[Comment]{/*} \highlight[Comment]{ * contents: A minimal C program.} \highlight[Comment]{ *} \highlight[Comment]{ * Copyright =A9 2005 Nikolai Weibull } \highlight[Comment]{*/} \highlight[Type]{int} \highlight[Identifier]{main}(\highlight[Type]{void}) \leftargument \highlight[Statement]{return} \highlight[Constant]{0}; \rightargument \stoplines \stoptext --TB36FDmn/VVEgNH/ 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 --TB36FDmn/VVEgNH/--