From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/77064 Path: news.gmane.org!not-for-mail From: Philipp Gesang Newsgroups: gmane.comp.tex.context Subject: [callbacks] proper registration, node subtypes Date: Mon, 25 Jun 2012 15:39:24 +0200 Message-ID: <20120625133924.GB31738@phlegethon> Reply-To: mailing list for ConTeXt users NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1784288943==" X-Trace: dough.gmane.org 1340631499 9660 80.91.229.3 (25 Jun 2012 13:38:19 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 25 Jun 2012 13:38:19 +0000 (UTC) To: ConTeXt ML Original-X-From: ntg-context-bounces@ntg.nl Mon Jun 25 15:38:14 2012 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from balder.ntg.nl ([195.12.62.10]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Sj9UY-00058O-Bt for gctc-ntg-context-518@m.gmane.org; Mon, 25 Jun 2012 15:38:10 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id E0FED101EA; Mon, 25 Jun 2012 15:38:07 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id IT3uHLroztmN; Mon, 25 Jun 2012 15:38:02 +0200 (CEST) Original-Received: from balder.ntg.nl (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 7668B101E5; Mon, 25 Jun 2012 15:38:02 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by balder.ntg.nl (Postfix) with ESMTP id 2D2CB101E5 for ; Mon, 25 Jun 2012 15:38:01 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at balder.ntg.nl Original-Received: from balder.ntg.nl ([127.0.0.1]) by localhost (balder.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with LMTP id lcKg8JDH-A3j for ; Mon, 25 Jun 2012 15:38:00 +0200 (CEST) Original-Received: from filter1-ams.mf.surf.net (filter1-ams.mf.surf.net [192.87.102.69]) by balder.ntg.nl (Postfix) with ESMTP id 4C425101DD for ; Mon, 25 Jun 2012 15:38:00 +0200 (CEST) Original-Received: from relay2.uni-heidelberg.de (relay2.uni-heidelberg.de [129.206.210.211]) by filter1-ams.mf.surf.net (8.14.3/8.14.3/Debian-9.4) with ESMTP id q5PDbwR2011628 for ; Mon, 25 Jun 2012 15:37:59 +0200 Original-Received: from ix.urz.uni-heidelberg.de (cyrus-portal.urz.uni-heidelberg.de [129.206.100.176]) by relay2.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id q5PDbrAW002728 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 25 Jun 2012 15:37:57 +0200 Original-Received: from extmail.urz.uni-heidelberg.de (extmail.urz.uni-heidelberg.de [129.206.100.140]) by ix.urz.uni-heidelberg.de (8.13.8/8.13.8) with ESMTP id q5PDbr9O017820 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 25 Jun 2012 15:37:53 +0200 Original-Received: from localhost (dslb-188-104-131-199.pools.arcor-ip.net [188.104.131.199]) (authenticated bits=0) by extmail.urz.uni-heidelberg.de (8.13.4/8.13.1) with ESMTP id q5PDbqOi001635 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Mon, 25 Jun 2012 15:37:52 +0200 Mail-Followup-To: ConTeXt ML X-Operating-System: Linux phlegethon 3.3.7-1-ARCH X-License: "CC-BY-SA 3.0" User-Agent: Mutt/1.5.21 (2010-09-15) X-Bayes-Prob: 0.0045 (Score 0, tokens from: @@RPTN) X-CanIt-Geo: ip=129.206.210.211; country=DE; region=01; city=Heidelberg; latitude=49.4167; longitude=8.7000; http://maps.google.com/maps?q=49.4167,8.7000&z=6 X-CanItPRO-Stream: uu:ntg-context@ntg.nl (inherits from uu:default, base:default) X-Canit-Stats-ID: 0NHqBBX1v - 1b2c4edad107 - 20120625 X-Scanned-By: CanIt (www . roaringpenguin . com) on 192.87.102.69 X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.13 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 Xref: news.gmane.org gmane.comp.tex.context:77064 Archived-At: --===============1784288943== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="KN5l+BnMqAQyZLvT" Content-Disposition: inline --KN5l+BnMqAQyZLvT Content-Type: multipart/mixed; boundary="yNb1oOkm5a9FJOVX" Content-Disposition: inline --yNb1oOkm5a9FJOVX Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi all, I need a (pre-linebreak) callback to behave the same way with the Context and Plain formats. *The sequence that nodes are traversed in is very important.* Afaict the callback will have to be registered as a =E2=80=9Cprocessors=E2=80=9D/=E2=80=9Cbefore=E2=80=9D nodes= task. However, the behavior is not identical: 1. If the list contains a vlist or hlist, the callback is applied first on the inner list and then on the outer list. (Guess: it=E2=80=99s applied on the hpack_filter as well?) 2. In Plain, glyph nodes have subtype 0 (GLYPH_CHARACTER), while in Context it=E2=80=99s 1 (GLYPH_LIGATURE). Example code is appended. Questions: - Which node task gets me a behavior similar to the raw pre_linebreak_filter?[*] - Does the difference wrt node subtype matter assuming I only (a) copy glyph nodes and (b) manipulate their .char field? Any insights on this matter would be greatly appreciated. Regards Philipp [*] If this is not possible|recommended, what would a clean solution look like? --yNb1oOkm5a9FJOVX Content-Type: application/x-tex Content-Disposition: inline; filename="nlist-context.tex" Content-Transfer-Encoding: quoted-printable \enabletrackers[system.callbacks]=0A=0A\def\tasktype{processors}=0A\startlu= acode=0A thirddata =3D thirddata or { foo =3D { } } --- namespace=0A loca= l ncalls, nnodes =3D 0, 0=0A --- main callback; third arg is head=0A loca= l do_cbk =3D function (_, _, head)=0A ncalls =3D ncalls + 1=0A print(= "=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7= =C2=B7=C2=B7=C2=B7[" .. ncalls .. "]=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2= =B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7")=0A for n in node.t= raverse(head) do=0A nnodes =3D nnodes + 1=0A local nid =3D n.id= =0A print(n, (nid =3D=3D node.id"glyph" and unicode.utf8.char(n.char) = or false))=0A end=0A return head=0A end=0A --- context wrapper=0A = thirddata.foo.cbk =3D nodes.installattributehandler{=0A namespace =3D th= irddata.foo,=0A processor =3D do_cbk,=0A }=0A --- registration=0A nod= es.tasks.appendaction ("\tasktype","before","thirddata.foo.cbk")=0A nodes.= tasks.disableaction("\tasktype", "thirddata.foo.cbk")=0A --- displ= ay counters=0A thirddata.foo.dumpstats =3D function (head)=0A print(str= ing.rep("=C2=B7", 71))=0A print(string.format("callback invoked %d times= , %d nodes inspected", ncalls, nnodes))=0A print(string.rep("=C2=B7", 71= ))=0A end=0A\stopluacode=0A=0A%% wrapper macros=0A\def\startfoo{\par\ctxlu= a{nodes.tasks. enableaction("\tasktype","thirddata.foo.cbk")}}=0A\def \stop= foo{\par\ctxlua{nodes.tasks.disableaction("\tasktype","thirddata.foo.cbk")}= }=0A=0A%% invoke counter on exit=0A\appendtoks \ctxlua{thirddata.foo.dumpst= ats()} \to \everystoptext=0A=0A\starttext=0A \startfoo=0A foo \vbox{\hb= ox{bar}} baz=0A \stopfoo=0A\stoptext \endinput=0A=0A --yNb1oOkm5a9FJOVX Content-Type: application/x-tex Content-Disposition: attachment; filename="nlist-plain.tex" Content-Transfer-Encoding: quoted-printable \input luatexbase.sty=0A=0A% \def\cbktype{hpack_filter}=0A\def\cbktype{pre_= linebreak_filter}=0A\directlua{=0A local ncalls, nnodes =3D 0, 0=0A cbk = =3D function (head)=0A ncalls =3D ncalls + 1=0A print("=C2=B7=C2=B7= =C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2= =B7[" .. ncalls .. "]=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7= =C2=B7=C2=B7=C2=B7=C2=B7=C2=B7=C2=B7")=0A for n in node.traverse(head) d= o=0A nnodes =3D nnodes + 1=0A local nid =3D n.id=0A print(n,= (nid =3D=3D node.id"glyph" and unicode.utf8.char(n.char) or false))=0A = end=0A return head=0A end=0A dumpstats =3D function (head)=0A print= (string.rep("=C2=B7", 71))=0A print(string.format("callback invoked \%d = times, \%d nodes inspected", ncalls, nnodes))=0A print(string.rep("=C2= =B7", 71))=0A end=0A}=0A=0A\def\startfoo{\par\directlua{luatexbase. ad= d_to_callback("\cbktype",cbk, "cbk")}}=0A\def \stopfoo{\par\directlua{luate= xbase.remove_from_callback("\cbktype", "cbk")}}=0A=0A\def\dumpstats{\di= rectlua{dumpstats()}}=0A=0A\startfoo=0A foo \vbox{\hbox{bar}} baz=0A\stopf= oo=0A=0A\dumpstats\bye=0A --yNb1oOkm5a9FJOVX-- --KN5l+BnMqAQyZLvT Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAk/oagwACgkQ02lYlJYWs9Lq2gCgjyTAhgQPubM3PVCO2wxmoebs i4kAn3SXugbH5RHiN8p22M1vCOuB4n9/ =6q7q -----END PGP SIGNATURE----- --KN5l+BnMqAQyZLvT-- --===============1784288943== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://tex.aanhet.net archive : http://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________ --===============1784288943==--