Changes

Jump to navigation Jump to search
1,314 bytes added ,  14:08, 8 June 2020
m
no edit summary
<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.
function visualizer.flush_line(str, nested)
This hook is called for every non-empty line, or the entire content ofan inline <code>\type</code> command. The first argument is the
line itself, as returned by the <tt>line</tt> hook. The second argument
is some indication of nested brackets in the input, but it's not
table and pass that to <tt>buffers.flush_result</tt> (which also handles
some stuff related to nesting).
 
===<tt>begin_of_display, end_of_display, begin_of_inline, end_of_inline</tt>===
 
function visualizer.begin_of_display()
function visualizer.end_of_display()
function visualizer.begin_of_inline()
function visualizer.end_of_inline()
 
These hooks are called at the start and end of prettyprinting a buffer,
file or phrase. The <code>_display</code> versions are used when
prettyprinting a buffer (named or anonymous using
<code>\starttyping</code>) or a file. The <code>_inline</code> versions
are used for prettyprinting a phrase inline, using <code>\type</code>.
 
These functions should return nothing, but can use <tt>texprint</tt> and
friends to produce output.
 
The default implementations output some tex commands using
<tt>buffers.commands.{begin,end}_of_{display,inline}_command</tt> (which
seem to expand to nothing currently).
== Utility functions and variables ==
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!
 
[[Category:Old_Content]]

Navigation menu