Changes

Jump to navigation Jump to search
381 bytes added ,  11:02, 20 September 2010
<code>buffers.newvisualizer</code> function:
local visualizer = buffers.newvisualizer('foo')
Here, you pass the name of the pretty printer, which is the (lowercase)
simply declaring the function with <code>visualizer</code> as the first
component of the name (or whatever you assigned the return value from
<code>newvisualizer</code> to). Each of the function headers in the hooklist below use this.
== Defining hooks ==For example, after registering the 'foo' prettyprinter as above, the<tt>flush_line</tt> hook should be defined as:  function visualizer.flush_line(str,nested) Each pretty printer should can define a number of hook functions. Each of
these will be called at specific times during the pretty printing and
are free to handle the input in any way. Each See below for when and how ahook is called. Defining a hook is optional, if it isnot defined, a default version will be called instead. == Hooks ==This section lists all hooks available to a pretty printer. Firstwe'll show how and when the hooks are called.
When pretty printinga file or buffer (named or anonymous using<code>\starttyping</code>), the following hooks are called:
# Call <tt>begin_of_display</tt>
# For each line in the input:
#* If the line contains only whitespace:
#*# Call <tt>flush_line</tt> to process and output the current line.
#*# Call <tt>end_of_line</tt>
# Call <tt>end_of_display</tt>
Each hook should be defined as function named as follows:When prettyprint a single phrase (using <ttcode>buffers.visualizers.''printer_name''.''function_name''\type</ttcode>), the followinghooks are called:
For example, the # Call <tt>begin_of_inline</tt># Call <tt>flush_line</tt> function for the # Call <tt>fooend_of_inline</tt>pretty printer, above should be defined as:
function buffers.visualizers.foo.flush_line(strNote that in this case,nested) == Hooks ==the <tt>line</tt> hook is not called!
The following hooks are available to a pretty printer.
The above is not quite complete, some things are missing or
underdocumented. The code that drives the prettyprinting is in the file
<tt>[[source:buff-ini.lua</tt> |buff-ini.lua]] (which is called by <tt>[[source:buff-ini.mkiv</tt> |buff-ini.mkiv]] and<tt>[[source:buff-ver.mkiv|buff-ver.mkiv</tt> ]] from the TeX side), in the ConTeXt distribution.
If you're missing anything, you'll probably find some answers there.
Don't forget to write down what you find on this page!

Navigation menu