GNU TeXmacsUser manualReferenceAboutEnglish
Creating and following links from Scheme

The Scheme side of the linking system lives in

progs/link/

. Most of it is loaded lazily (

init-texmacs.scm

declares link-follow-ids, link-active-ids, link-mouse-ids, link-active-upwards, get-link-locations, register-link-locations and a few others with lazy-define), so the first event over an active locus loads the navigation code.

1.Loci and identifiers (
locus-edit.scm
)

(create-unique-id)

Returns a new identifier +xxxyyy, made of a random prefix chosen at startup and a counter, both in base 62. The identifiers are unique with high probability across sessions and users, which is what makes links between files possible.

(make-locus)

Wraps the selection (or an empty string) in (locus (id new-id) …).

(locus-id t)

The identifier of the locus t (its first argument), or #f.

(id->loci id)

The locus tags carrying id (the parents of the trees returned by id->trees).

(locus-set id t)

Replaces the bodies of all loci with identifier id by t.

locus-insert-link, locus-remove-link, locus-remove-all-links

Insert a link as an argument of a locus (just before the body) or remove it.

2.Making links interactively (
link-edit.scm
)

Links are built in two steps, through the Link menu (

link-menu.scm

) and the keyboard shortcuts (

link-kbd.scm

) of the linking tool, which are only present when with-linking-tool? holds. First the participants are collected in the table link-participants, indexed by their position: (link-set-locus nr) stores a tree pointer to the innermost locus, link-set-url, link-set-target-url, link-set-script and link-set-target-script store url and script vertices. Then (make-link types) builds one link (link type v0 v1 …) per comma separated type and inserts it according to the link mode (set-link-mode):

simple

in the source locus only;

bidirectional

in every locus taking part in the link (the default);

external

in the locus containing the cursor, which need not be a participant.

remove-link-of-types and remove-all-links remove the links of the current locus, taking the mode into account; in bidirectional mode they are meant to remove the copies stored in the other loci as well (but see pitfalls). The utilities link-flatten, link-type, link-attributes, link-vertices, vertex->id, vertex->url and vertex->script take links apart.

3.Link lists and navigation lists (
link-navigate.scm
)

Following a link goes through two intermediate representations.

Link lists.
An item (id type attrs v1 … vn) describes a link found from the locus id. (ids->link-list ids) collects, for each identifier, the links registered for the vertex (id id) (that is, vertex->links). exact-link-list, upward-link-list (a tree and its ancestors) and complete-link-list (a tree and its descendants) build link lists for trees. When external navigation is switched off, only the links written inside the locus itself are considered.

The lists are filtered (filter-link-list) on three criteria:

The navigation options are the preferences bidirectional navigation (default off), external navigation (on) and link pages (on). link-active-ids keeps the identifiers which have a link passing the "hover" filter; this is how the editor decides which loci are active.

Navigation lists.
An item (type attrs n source-id target) is one possible jump: to the n-th vertex of a link, for every vertex other than the source. For a link with two vertices, n=1 is the direct direction and n=0 the inverse one; the extended types returned by navigation-list-xtypes append a * to the type of inverse jumps.
Following.
(link-follow-ids ids event) filters the link list of ids on the event, turns it into a navigation list and calls navigation-list-follow, which
  1. ignores links of type automatic when there are links of other types;

  2. follows all focus jumps at once;

  3. otherwise, if there are several jumps and link pages are enabled, opens an auxiliary page listing them (build-navigation-page);

  4. otherwise follows the single jump, or asks the user which extended type to follow.

Following a jump (navigation-item-follow) marks the source and the target as visited (declare-visited, then id-update retypesets the affected loci so that they change colour; hard identifiers starting with % are not recorded) and goes to the target vertex:

(id name)

go-to-id puts the cursor at the end of the first locus with that identifier. If none is known, it tries to load the file containing it (resolve-id, see below) and tries again a little later.

(url dest)

go-to-url chooses a pair of handlers according to the root of the URL (url-handlers). In all cases the file part is opened with load-browse-buffer (for local files, a disambiguation page is built when the URL has several alternatives). For local files, the part after # or ? is then handled by a post handler according to the file format: go-to-label for TeXmacs documents, line and column positioning for source files; for http, https and doi it is ignored.

(script fun args…)

execute-script runs the script, subject to the security policy (see scripts and security), using the secure attribute recorded by the typesetter.

locus-link-follow (link return in the linking tool) follows the links of the loci around the cursor as a click would.

4.Links between files (
link-extern.scm
)

A link may point to a locus in another file, which is not necessarily loaded. To find it, TeXmacs keeps a registry in $TEXMACS_HOME_PATH/system/registry.scm, which assigns a unique identifier to each linked file name (registry-id) and maps identifiers of files back to their names, and stores the necessary information in the documents themselves:

get-constellation lists all registered files;

link-extract.scm

builds auxiliary pages listing the linked files (build-constellation-page), the loci of the current buffer (build-locus-page), or all environments of a given type, after turning them into loci if necessary (build-environment-page).

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