docidx_plugin_apiref(n)
β¨ NAME β¨
docidx_plugin_apiref β the docidx plugin API reference π
(it lives in the Documentation tools manual, section n, and yes bestie, this is the glow-up version)
π SYNOPSIS π
dt_fmap symfname
dt_format
dt_read file
dt_source file
ex_cappend text
ex_cget varname
ex_cis cname
ex_cname
ex_cpop cname
ex_cpush cname
ex_cset varname value
ex_lb ?newbracket?
ex_rb ?newbracket?
idx_initialize
idx_listvariables
idx_numpasses
idx_postprocess text
idx_setup n
idx_shutdown
idx_varset varname text
fmt_plain_text text
π DESCRIPTION π
okay so this doc is for plugin writers, aka the developers who wanna build an index formatting engine for some output format X. slay, very niche, very powerful. π
It spells out the whole interaction between the doctools::idx package and its plugins β meaning the interface that any index formatting engine has to comply with. no cap, that's the contract.
This document deals with version 1 of the interface. (iykyk, versions matter.)
Now if you're the kind of reader who's actually more into the markup language itself, then don't start here β start with the docidx language introduction, and from there go on to the formal specifications, i.e. the docidx language syntax and the docidx language command reference. different quest line, same universe. π¦
π OVERVIEW π
The API for an index formatting engine breaks down into two major sections. two! both essential.
On one side, there's a set of commands the plugin uses to query the frontend. These are provided by the frontend and linked straight into the plugin interpreter. The full tea is in the section FRONTEND COMMANDS below. π
And on the other side, the plugin has to provide its own set of commands, which the frontend then calls in a very specific sequence while it's processing input. Those fall into two categories again β management and formatting. Go read PLUGIN COMMANDS and its subsections for the whole breakdown. πΈ
π«Ά FRONTEND COMMANDS π«Ά
This section is the set of commands through which a plugin β also known as an index formatting engine, main character energy β can query the frontend. These commands come from the frontend and get linked into the plugin interpreter.
So basically: an index formatting engine can assume that every single one of the following commands is present whenever any of its own commands (the ones in section PLUGIN COMMANDS) get executed. periodt.
Beyond that, it can also assume it has full access to its own safe interpreter, which means it can't damage the other parts of the processor, and it can't damage the filesystem either. protected, bestie. π
but lowkey it can kill or hang the whole process β either by exiting, or by running an infinite loop. so like, power, but also consequences. π
Coming back to the imported commands: everything with the dt_ prefix gives you limited access to specific parts of the frontend, whereas everything with the ex_ prefix gives you access to the state of the textutil::expander object β the thing doing the main parsing of the input inside the frontend. These commands should not be used except under very special circumstances. fr fr, leave them alone unless you truly know what you're doing. π
dt_fmap symfnameβ Query command. It returns the actual pathname you should put in the output, in place of the symbolic filenamesymfname. And if no mapping was established forsymfname? It just returns your input unchanged, no edits, no notes. β¨
The mappings it wants are established with the method map of a frontend, as explained in section OBJECT METHODS of the documentation for the package doctools::idx.
dt_formatβ Query command. Returns the name of the format associated with the index formatting engine. that's it, that's the whole vibe. πdt_read fileβ Controlled filesystem access. Returns the contents offilefor whatever the plugin wants to do with it. but here's the catch β only files that are either in the same directory as the file containing the engine, or below it can be loaded. Trying to load a file outside of that directory causes an error. stay in your lane, literally. π§dt_source fileβ Controlled filesystem access. This one lets the index formatting engine load additional Tcl code it might need. Same rules though: only files either in the same directory as the file containing the engine, or below it can be loaded. Trying to load a file outside of that directory causes an error. π«Άex_cappend textβ Appends a string to the output in the current context. This command should rarely be used by macros or application code. like, rare rare. πex_cget varnameβ Retrieves the value of the variablevarname, defined in the current context.ex_cis cnameβ Determines whether or not the name of the current context iscname. vibe check on the context name, basically. βex_cnameβ Returns the name of the current context. no arguments, just answers. πex_cpop cnameβ Pops a context from the context stack, returning all the accumulated output in that context. The context must be namedcname, or an error results. πex_cpush cnameβ Pushes a context namedcnameonto the context stack. It must be popped bycpopbefore expansion ends, or an error results. don't leave it hanging, bestie. πex_cset varname valueβ Sets the variablevarnametovaluein the current context.ex_lb ?newbracket?β Returns the current value of the left macro expansion bracket. This is for use as, or within, a macro, when the bracket needs to be included in the output text. Ifnewbracketis specified, it becomes the new bracket, and is returned. π¦ex_rb ?newbracket?β Returns the current value of the right macro expansion bracket. This is for use as, or within, a macro, when the bracket needs to be included in the output text. Ifnewbracketis specified, it becomes the new bracket, and is returned. πΈ
β¨ PLUGIN COMMANDS β¨
okay bestie, so the plugin has to provide its own set of commands, and the frontend will call them in a specific sequence while it's processing input. π
These commands fall into two categories: management and formatting. Their expected names, signatures, and responsibilities are all specified in the next two subsections. π«Ά
π οΈ MANAGEMENT COMMANDS π οΈ
The management commands a plugin has to provide are used by the frontend to:
- initialize and shutdown the plugin
- determine the number of passes it has to make over the input
- initialize and shutdown each pass
- query and initialize engine parameters
After the plugin has been loaded and the frontend commands are established the commands will be called in the following sequence:
idx_numpasses -> n
idx_listvariables -> vars
idx_varset var1 value1
idx_varset var2 value2
...
idx_varset varK valueK
idx_initialize
idx_setup 1
...
idx_setup 2
...
...
idx_setup n
...
idx_postprocess
idx_shutdown
...
I.e. first the number of passes and the set of available engine parameters is established, followed by calls setting the parameters. That second part is optional. β¨
After that the plugin is initialized, the specified number of passes executed, the final result run through a global post processing step and at last the plugin is shutdown again. This can be followed by more conversions, restarting the sequence at idx_varset. π
In each of the passes, i.e. after the calls of idx_setup the frontend will process the input and call the formatting commands as markup is encountered. This means that the sequence of formatting commands is determined by the grammar of the docidx markup language, as specified in the docidx language syntax specification. π
A different way of looking at the sequence is:
- First some basic parameters are determined.
- Then everything starting at the first
idx_varsettoidx_shutdownforms a run, the formatting of a single input. Each run can be followed by more. - Embedded within each run we have one or more passes, each starting with
idx_setupand going until either the nextidx_setuporidx_postprocessis reached.
If more than one pass is required to perform the formatting only the output of the last pass is relevant. The output of all the previous, preparatory passes is ignored.
The commands, their names, signatures, and responsibilities are, in detail:
idx_initializeβ Initialization/Shutdown. This command is called at the beginning of every conversion run, as the first command of that run. Note that a run is not a pass, but may consist of multiple passes. It has to initialize the general state of the plugin, beyond the initialization done during the load. No return value is expected, and any returned value is ignored.idx_listvariablesβ Initialization/Shutdown and Engine parameters. Second command is called after the plugin code has been loaded, i.e. immediately afteridx_numpasses. It has to return a list containing the names of the parameters the frontend can set to configure the engine. This list can be empty.idx_numpassesβ Initialization/Shutdown and Pass management. First command called after the plugin code has been loaded. No other command of the engine will be called before it. It has to return the number of passes this engine requires to fully process the input document. This value has to be an integer number greater or equal to one.idx_postprocess textβ Initialization/Shutdown. This command is called immediately after the last pass in a run. Its argument is the result of the conversion generated by that pass. It is provided to allow the engine to perform any global modifications of the generated document. If no post-processing is required for a specific format the command has to just return the argument.
Expected to return a value, the final result of formatting the input.
idx_setup nβ Initialization/Shutdown and Pass management. This command is called at the beginning of each pass over the input in a run. Its argument is the number of the pass which has begun. Passes are counted from 1 upward. The command has to set up the internal state of the plugin for this particular pass. No return value is expected, and any returned value is ignored.idx_shutdownβ Initialization/Shutdown. This command is called at the end of every conversion run. It is the last command called in a run. It has to clean up of all the run-specific state in the plugin. After the call the engine has to be in a state which allows the initiation of another run without fear that information from the last run is leaked into this new run. No return value is expected, and any returned value is ignored.idx_varset varname textβ Engine parameters. This command is called by the frontend to set an engine parameter to a particular value. The parameter to change is specified by varname, the value to set in text.
The command has to throw an error if an unknown varname is used. Only the names returned by idx_listvariables have to be considered as known.
The values of all engine parameters have to persist between passes and runs.
π FORMATTING COMMANDS π
The formatting commands have to implement the formatting for the output format, for all the markup commands of the docidx markup language, except lb, rb, vset, include, and comment. These exceptions are processed by the frontend and are never seen by the plugin. In return a command for the formatting of plain text has to be provided, something which has no markup in the input at all. π
This means, that each of the five markup commands specified in the docidx language command reference and outside of the set of exceptions listed above has an equivalent formatting command which takes the same arguments as the markup command and whose name is the name of markup command with the prefix fmt_ added to it. π₯
All commands are expected to format their input in some way per the semantics specified in the command reference and to return whatever part of this that they deem necessary as their result, which will be added to the output. π
To avoid essentially duplicating the command reference we do not list any of the command here and simply refer the reader to the docidx language command reference for their signature and description. The sole exception is the plain text formatter, which has no equivalent markup command. π
The calling sequence of formatting commands is not as rigid as for the management commands, but determined by the grammar of the docidx markup language, as specified in the docidx language syntax specification. π
fmt_plain_text textβ No associated markup command.
Called by the frontend for any plain text encountered in the input. It has to perform any and all special processing required for plain text.
The formatted text is expected as the result of the command, and added to the output. If no special processing is required it has to simply return its argument without change.
π BUGS, IDEAS, FEEDBACK π
This document, and the package it describes, will undoubtedly contain bugs and other problems. π Please report such in the category doctools of the Tcllib Trackers (http://core.tcl.tk/tcllib/reportlist). Please also report any ideas for enhancements you may have for either package and/or documentation.
When proposing code changes, please provide unified diffs, i.e the output of diff -u.
Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. π«Ά
π SEE ALSO π
docidx_introdocidx_lang_cmdrefdocidx_lang_faqdocidx_lang_introdocidx_lang_syntaxdoctools::idx
π KEYWORDS π
- formatting engine
- index
- index formatter
- keywords
- markup
- plugin
- semantic markup
π CATEGORY π
Documentation tools
Β©οΈ COPYRIGHT Β©οΈ
Copyright (c) 2007 Andreas Kupries <andreas_kupries@users.sourceforge.net>
okay bestie, that's the whole page! it's from tcllib, version 1.0, and the page is docidx_plugin_apiref(n). stay iconic, you got this π
β¨π¦
π¦ where this page comes from
- alpine 3.24: tcl-lib-doc 1.21-r1 Β· BSD-2-Clause
- epel 9: tcllib 1.21-1.el9 Β· BSD
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- opensuse-leap 16.0: tcllib 1.21-bp160.1.2 Β· TCL
- Copyright (c) 2007 Andreas Kupries <andreas_kupries@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms