GNU TeXmacsUser manualReferenceAboutEnglish
DRD pitfalls and known inconsistencies

1.Pitfalls when declaring properties

DRD and boxes must agree

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.

Physical indices

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.

Arity first

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.

extern arities count the function

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.

Order of chained declarations

accessible (i) and hidden (i) reset the type of the child to regular; put type declarations after them.

Field widths

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.

Silent failures

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).

Stale properties

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).

Which DRD?

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.

Global modes are not exception safe

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.

Memoized logic queries

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.

define-group works at expansion time

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.

2.Known bugs and inconsistencies

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.

2.1.In the C++ code

drd-props border no (
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 and maximum (Data/Drd/drd_std.cpp:380-383)

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.)

Variable type uses the with-like freeze bit (
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.

Uninitialized freeze_type (Data/Drd/tag_info.cpp:109-124)

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.

Wrong child in two declarations (
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).

Type of no-patterns (
Data/Drd/drd_std.cpp:1047
)

Declared as a color although its value is a boolean.

Type names are not symmetric (Data/Drd/tag_info.cpp:45-104)

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.

Queries modify the DRD (
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.

get_env_child ignores extern:f

Unlike the other high-level queries, it uses the record of extern itself.

Sharing of the cached style DRD (
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.

Unused or unimplemented declarations

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.

Outdated comments (
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.

Mode stored in a bool (
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.

Suspicious return value (
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.

Glue name

The Scheme function tree-insert_point has an underscore in its name, unlike all other glue functions.

2.2.In style packages

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.

3.Debugging hints

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".