![]() |
DRD pitfalls and known inconsistencies | ![]() |
The DRD decides where the cursor may go in the tree; the boxes decide where it can be displayed. A child declared accessible but typeset as a decoration (because the macro computes with it, or passes it to extern), or a child typeset as editable content but declared inaccessible, produces invisible cursors or a cursor which cannot reach visible text. See the macro expansion chapter.
All low-level setters (set_type (l, nr, tp), set_accessible, …), the declaration methods of
drd_std.cpp
and the numeric arguments of drd-props designate records, not children. With CHILD_BIFORM there are only two records; with ARITY_VAR_REPEAT, record \(0\) is the repeated group. Out-of-range indices are silently ignored.
Child records are created by the arity. In a drd-props for a tag which has no record yet (a pseudo-label extern:f, or a macro defined later than the declaration), properties of children are lost unless arity comes first.
For a pseudo-label extern:f, the children are those of the extern tree, whose child \(0\) is the function name. To make the first argument accessible, declare an arity of \(2\) and accessible|1.
accessible (i) and hidden (i) reset the type of the child to regular; put type declarations after them.
arity_base has 6 bits and arity_extra 4 bits: a macro with more than 63 parameters, or a repeated group of more than 15 children, gets a truncated arity (assignments to bit fields wrap silently), while the array of child records has the full size.
Unknown properties, misspelled property names and values other than those listed in style and document DRDs are ignored without warning. Several freeze_* calls are executed even when the value was not recognized, which then blocks the heuristics (for instance with-like|true freezes the with-like flag to false).
Properties are added or overwritten, never removed: an editor DRD keeps the record of a macro whose definition has been deleted, and on-disk style caches keep the properties computed from an older version of a style file until they are cleared (Tools\(\rightarrow\)Update\(\rightarrow\)Styles).
Generic code consults the_drd, which is the DRD of the current view. Code that processes a tree of another buffer (converters, background tasks, Scheme code running on hidden buffers) must install the right DRD, with with_drd and get_document_drd in C++ or set-drd in Scheme.
The access and writable modes are global integers which every caller restores by hand. A Scheme error between set-access-mode and the restoring call leaves the editor in the wrong mode.
logic-holds?, logic-apply and logic-apply-list (
kernel/logic/logic-data.scm
) cache their results in hash tables which are never cleared. Rules added after a query (for instance by a lazily loaded module) are invisible for queries already answered; declare logic tables before they are first used.
The macro resets group-resolve-table and looks up the previous members of the group while it is expanded, and generates different code for the first and for later declarations. It is meant to be used at the top level of a module; inside a function, use eval as tm-register-new-list-tag does.
The following problems were found while writing this documentation, by reading the code; line numbers refer to the current sources. Some have already been reported upstream.
Typeset/Env/env_exec.cpp:753)
The value no sets BORDER_INNER instead of BORDER_NO, so the 64 or so declarations border|no in the standard packages behave like border|inner. (Reported.)
minimum is declared with repeat (2, 1) and maximum with repeat (1, 1). Since both are in the group binary-operation-tag (
utils/edit/variants.scm
), turning a one-argument maximum into a minimum with the variant menu yields a tree of invalid arity. (Reported.)
Data/Drd/drd_info.cpp:314, :329)
set_var_type tests freeze_with and freeze_var_type sets freeze_with instead of freeze_var_type. Declaring parameter or macro-parameter therefore freezes the with-like flag, and declaring with-like prevents the heuristics from setting the variable type.
The constructor parent_info (int, int, int, int, bool) initializes every field except freeze_type, and parent_info::operator == (tag_info.cpp:166-183) ignores it. The bit is thus indeterminate in all records created from scratch (including the default record of unknown labels); when it happens to be set, the type of the tag can no longer be changed by the heuristics. The record of a primitive is also never type-frozen on purpose, contrary to what the frozen argument suggests.
Data/Drd/drd_std.cpp:539, :972)
For script, name (0, "arguments") overwrites the name function of child \(0\) (child \(1\) was probably meant). For set, variable (0) -> regular (0) makes the variable name regular content (probably regular (1) was meant).
Data/Drd/drd_std.cpp:1047)
Declared as a color although its value is a boolean.
TYPE_RAW and TYPE_BINDING have no name (they decode as unknown), and obsolete can be decoded but not encoded, so it cannot be used in drd-props.
Data/Drd/drd_info.cpp:476, 540, 604, 641, 654)
For an extern tree whose function has no record, the getters execute ti= info(EXTERN); info(lab)= ti;. This writes into the DRD during a query (possibly a shared style DRD), and makes the records of extern and extern:f share the same tag_info_rep, so that a later setter on one of them (a drd-props executed after the first query) also changes the other.
Unlike the other high-level queries, it uses the record of extern itself.
Edit/Editor/edit_typeset.cpp:284)
When a style is not found in the cache, typeset_style_use_cache replaces the editor DRD by the object returned by get_style_drd, which is also stored in drd_cached. The subsequent heuristic_init (pre), the drd_update calls and the drd-props of the document then modify the in-memory style DRD, which is later returned by get_style_drd to other users (get_document_drd, widgets). The serialized cache is written before these modifications, so editors which hit the cache are not affected. The code at
Texmacs/Window/tm_button.cpp:58
has the same structure.
The parent and child block fields are never set nor read; the methods set_block, get_block and freeze_block (both overloads) and drd_info::operator tree are declared in
drd_info.hpp
but not defined. The macro macro (i) of
drd_std.cpp:25
refers to a non-existent TYPE_MACRO.
Data/Drd/tag_info.hpp:62, :150)
The comment on ARITY_OPTIONS gives a strict upper bound whereas correct_arity uses \(\operatorname{base} \leqslant n \leqslant \operatorname{base}+\operatorname{extra}\); the comment on child_info describes a “mode” field with MODE_PARENT, which has been replaced by env.
Data/Tree/tree_traverse.cpp:284)
move_valid_bis saves the result of set_access_mode in a bool, which would restore DRD_ACCESS_SOURCE as DRD_ACCESS_HIDDEN. It is harmless in practice because the branch is not reached in source mode.
Data/Drd/drd_info.cpp:412)
For an or-value tree, get_syntax (tree, path) returns the tree itself instead of the syntax r which it has just found. This may be intentional.
The Scheme function tree-insert_point has an underscore in its name, unlike all other glue functions.
packages/customize/math/math-check.ts
The declaration <drd-props|extern:math-check|with-like|true|arity|1|accessible|all|regular|all> uses true, which is not a recognized value (only yes and no are), and declares an arity of \(1\) although the extern trees have two children (the function name and the argument). As a result, the argument of math-check is outside the declared layout and therefore not accessible, which is probably the opposite of what was intended. The same holds for extern:math-check-table.
packages/documentation/standard/scheme-api.ts
The property accesible (sic) in the declaration of doc-module-header-body is ignored.
From Scheme, inspect the DRD of the current buffer with tree-child-type, tree-accessible-child?, tree-child-env, tree-label-type, tag-minimal-arity, … on the tree at the cursor ((cursor-tree), (tree-up (cursor-tree))).
In source mode (Document\(\rightarrow\)Source\(\rightarrow\)Edit source tree), the arguments of tags are colored according to their child types, which gives a quick visual check of drd-props declarations.
In C++, tag_info and parent_info have an operator << (cout << drd->info[l]); printing a drd_info only prints its name. The serialized form of the local entries is drd->get_locals ().
The cached style environments and DRDs are the files $TEXMACS_HOME_PATH/system/cache/__*; they contain the serialized form in Scheme syntax and can be removed at any time.
The warning bad heuristic drd convergence means that the heuristic loop did not reach a fixed point after ten rounds (the properties of some macros kept changing from one round to the next); the resulting properties are those of the last round.