Module Namespaces

From Wiki
Revision as of 00:00, 27 September 2010 by Phg (talk | contribs) (namespaces of the world, unite!)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

List of Module Namespaces


TODO: This list is under construction and will eventually contain all namespaces used in context modules. (See: To-Do List)


To avoid clashes with existing and future commands, any module should adhere to the following rules:

  • Namespaces should have more than two characters (at least yours [1]),
  • the namespace should be registered here for others to know.
Namespace Name Main file Description
fb fancybreak t-fancybreak Inserting thought breaks (transitions).
Reserved module namespaces.

Generating a Namespace for Your Module

Context provides the user command \definenamespace that generates a valid namespace for variables and takes care of defining a setup command as well. Suppose you have a module called My Module (preferably in a file t-mymodule.mkiv) and want to reserve the namespace mymod. The following snippet will get you a setup command \setupMyMod.

\definenamespace[mymod] [
  type=module,
  name=MyMod,
  setup=list,
]

Through \setupMyMod you can now set the variables that you are planning to use in your module – it is already a mature command that conforms to the overall context style and can take a parameter list, a list of key-value pairs or both as arguments. Any parameter defined that way can now be retrieved via another command that got auto-generated, \MyModparameter.

% setting a parameter within the namespace
\setupMyMod[
  yamp=Yet another module parameter,
]

% command sequence that does something with the parameter
\def\blueparameter{\setupcolors[state=start]\colored[blue]\MyModparameter{yamp}}

% deploying the new user command
\starttext
\blueparameter
\stoptext

Wondering why your namespace, albeit defined as mymod initially, is always referred to as MyMod, i.e. the value of the parameter name as given in the definition? Internally the namespaces are represented as ordinary command sequences with a prefix. This prefix is composed from first the usual four @-signs, second the namespace identifier, and third the key id from the argument list. In the example this results in a macro \@@@@ + mymod + yamp. Thus, \MyModparameter{yamp} would be equivalent to calling:

\unprotect
\@@@@mymodyamp
\protect

Namespace Configuration

\definenamespace accepts a number of options that determine what commands will be available. At the time of this writing (2010-09-27), this is rather new stuff and so far neither guaranteed to stay in context as it is nor fully documented (and implemented?). Therefore, the following table uses double questionmarks to designate information that was only inferred indirectly.

Option Parameters and their description
name string: The identifier that will be used to reference setups and parameters.
parent string: a namespace identifier. Can reference itself. Functionality not yet known.
type module: intended use?? Not yet known.
command boolean: functionality not yet known.
setup Defines a setup command; list: ??. Further functionality not yet disclosed.
comment string: non-functional information that will be stored along with the namespace??
version number: versioning information?? Functionality not yet known.
Optional settings for module namespaces.


Further Information