[PATCH] Add begin_of_buffer and end_of_buffer hooks for lua pretty printers
Hi all, while working on a custom pretty printer, I was having the need to keep some state variables for the duration of one buffer, and reset them again for the next buffer. With the current hooks a pretty printer has available, this is not possible, since you never know what the first and last lines are. The attached patch adds two new hooks, begin_of_buffer and end_of_buffer, which will be called when typing a buffer or a file (e.g. \typebuffer or \typefile). They are not called for typing a phrase (e.g. \type). Is this patch acceptable for inclusion? Gr. Matthijs
Matthijs Kooijman wrote:
Hi all,
while working on a custom pretty printer, I was having the need to keep some state variables for the duration of one buffer, and reset them again for the next buffer. With the current hooks a pretty printer has available, this is not possible, since you never know what the first and last lines are.
The attached patch adds two new hooks, begin_of_buffer and end_of_buffer, which will be called when typing a buffer or a file (e.g. \typebuffer or \typefile). They are not called for typing a phrase (e.g. \type).
Is this patch acceptable for inclusion?
(no patch nor example of usage attached) ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hi Hans,
(no patch nor example of usage attached) *sigh*, attaching files is always hard :-)
Anyway, I've attached it now, together with an exapmle prettyprinter that uses it. I've also slightly changed the patch since my last message. Now, begin_of_buffer and end_of_buffer are always called, even for single line \type's. I found that I had to do all kinds of magic to make things work for \type as well, so this seems cleaner. To be able to differentiate, the type of buffer ('single', 'buffer' or 'file') and the name of the buffer/file gets passed to begin/end_of_buffer, though my example prettyprinter does not use these yet. Before, \type directly called hooks.flush_line. I've added buffers.typesingle to be called instead, which calls begin_of_line, flush_line and end_of_line. To prevent confusing with \type, I've renamed buffers.type to buffers.typebuffer. Finally, I've added some comments to the hooks.* functions, to document when they are called. Is there any place where lua pretty printers are documented? The wiki seems to say only "wait for lua", but not how to use them. If there isn't, I'll try to put something useful on the wiki. Gr. Matthijs
Hi, any chance of looking at and perhaps committing this patch?
Is there any place where lua pretty printers are documented? The wiki seems to say only "wait for lua", but not how to use them. If there isn't, I'll try to put something useful on the wiki. I've created [1] to document the creation of pretty printers in MkIV.
Matthijs Kooijman wrote:
Hi,
any chance of looking at and perhaps committing this patch?
Is there any place where lua pretty printers are documented? The wiki seems to say only "wait for lua", but not how to use them. If there isn't, I'll try to put something useful on the wiki. I've created [1] to document the creation of pretty printers in MkIV.
i uploaded a beta zip with two extra hooks i also moved the pretty printers to another namespace so you need to use the buffers.newvisualizer function so that we don't get clashes with future features you need to adapt the wiki accordingly Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
Hi Hans,
i uploaded a beta zip with two extra hooks I see the hooks, but I can't find the spot where they are called? It seems you missed this part of my patch?
i also moved the pretty printers to another namespace so you need to use the buffers.newvisualizer function so that we don't get clashes with future features This change looks good indeed, those long function names weren't all that
Also, I think you didn't update the definition of \type to use the typesingle lua function I proposed, which means that \type{} commands won't get begin_of_buffer and end_of_buffer called at all. Am I missing something, or did you? Will you fix this, or should I prepare a new patch? pretty.
you need to adapt the wiki accordingly I will, as soon as I get things working again :-)
Gr. Matthijs
(I've sent this mail before, but I think the mailing list troubles might have eaten it). Hi Hans,
i uploaded a beta zip with two extra hooks I see the hooks, but I can't find the spot where they are called? It seems you missed this part of my patch?
i also moved the pretty printers to another namespace so you need to use the buffers.newvisualizer function so that we don't get clashes with future features This change looks good indeed, those long function names weren't all that
Also, I think you didn't update the definition of \type to use the typesingle lua function I proposed, which means that \type{} commands won't get begin_of_buffer and end_of_buffer called at all. Am I missing something, or did you? Will you fix this, or should I prepare a new patch? pretty.
you need to adapt the wiki accordingly I will, as soon as I get things working again :-)
Gr. Matthijs
Hi Hans, any chance of replying to this mail? Currently, you only applied half of the patch, so it's not usable yet at all. Gr. Matthijs On Thu, Aug 13, 2009 at 12:10:54PM +0200, Matthijs Kooijman wrote:
(I've sent this mail before, but I think the mailing list troubles might have eaten it).
Hi Hans,
i uploaded a beta zip with two extra hooks I see the hooks, but I can't find the spot where they are called? It seems you missed this part of my patch?
Also, I think you didn't update the definition of \type to use the typesingle lua function I proposed, which means that \type{} commands won't get begin_of_buffer and end_of_buffer called at all.
Am I missing something, or did you? Will you fix this, or should I prepare a new patch?
i also moved the pretty printers to another namespace so you need to use the buffers.newvisualizer function so that we don't get clashes with future features This change looks good indeed, those long function names weren't all that pretty.
you need to adapt the wiki accordingly I will, as soon as I get things working again :-)
Gr.
Matthijs
___________________________________________________________________________________ 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 : https://foundry.supelec.fr/projects/contextrev/ wiki : http://contextgarden.net ___________________________________________________________________________________
participants (2)
-
Hans Hagen
-
Matthijs Kooijman