GNU TeXmacsUser manualReferenceAboutEnglish
Editing modes on the Scheme side

1.Introduction

Almost all of the interactive behaviour of TeXmacs is written in Scheme. When the user presses ↩, the C++ editor only finds out which command is bound to the key; the command itself, and the decision of what ↩ means at the current position (a new paragraph, a new item of a list, a new row of a table, the evaluation of a session input, …), are taken by Scheme code which depends on the mode (text, mathematics, source code, …) and on the tags around the cursor.

This chapter describes how this code is organized: how modes are defined and tested, how functions, keyboard shortcuts and menus are specialized for a mode or a context, which generic hooks the editing modes implement, and what the main modes provide: text, mathematics, tables and the dynamic markup (folding, switches, slides, sessions, scripts, spreadsheets and animations).

The chapter builds on the following documents, which it does not repeat:

2.Overview

An editing mode is a set of Scheme modules under $TEXMACS_PATH/progs/mode/ which extend generic definitions. Three mechanisms make the extension possible:

Modes

A mode is a named predicate, such as in-math?, declared with texmacs-modes in

kernel/texmacs/tm-modes.scm

. Modes form a hierarchy: in-math-in-session? is a sub-mode of both in-math? and in-session?.

Conditional definitions

Functions (tm-define), keyboard shortcuts (kbd-map) and menus (menu-bind, tm-menu) may be redefined under a condition, either a mode (:mode) or an arbitrary predicate (:require). The most recent definition whose condition holds wins.

Generic hooks

Generic code calls a small set of functions, such as (kbd-enter t shift?) or (structured-insert-horizontal t forwards?), on the focus tree t; their default implementations recurse to the parent tree. A mode implements the behaviour of its tags by redefining the hooks for those tags.

For instance, when the user presses ↩ inside an itemize list, the key is bound (in

generic/generic-kbd.scm

) to (kbd-return), which calls (kbd-enter (focus-tree) #f). The focus tree is the innermost tag around the cursor, here the itemize tag. Among all definitions of kbd-enter, the one in

text/text-edit.scm

with the condition (list-context? t) applies, and inserts a new item. Inside a table which is itself inside the list, the table definition in

table/table-edit.scm

applies first, because the focus tree is then the table.

3.Source files

The relevant directories (relative to $TEXMACS_PATH/progs/) are:

kernel/texmacs/tm-modes.scm

The macro texmacs-modes, the standard modes, the sub-mode test and lazy-initialize.

kernel/texmacs/tm-define.scm

Conditional definitions: tm-define, tm-property and their options.

kernel/gui/kbd-define.scm

The keyboard tables, kbd-map, kbd-wildcards and lazy-keyboard.

kernel/gui/menu-define.scm

Menus: menu-bind, tm-menu, lazy-menu.

generic/

Behaviour common to all modes: the generic hooks (

generic-edit.scm

), the basic keyboard (

generic-kbd.scm

), the focus menus and focus icon bar (

generic-menu.scm

) and the format, insert and document menus.

text/

Text mode: document titles, sections, lists, enunciations, floats and the language specific keyboards (

text/chinese/

,

text/cyrillic/

, …).

math/

Mathematics: the large mathematical keyboard, brackets, scripts, equations and the semantic editing mode.

table/

Tables and cells.

dynamic/

Folding, switches, overlays and slides; sessions and programs; scripts, plots and converters; spreadsheets; animations.

texmacs/keyboard/

Keyboard prefixes and wildcards common to all modes (

prefix-kbd.scm

) and the LaTeX style shortcuts (

latex-kbd.scm

).

init-texmacs.scm

The lazy declarations which tell when each mode module is loaded.

Other modes follow the same pattern and are not described here, notably the source mode (source/), the programming languages (

prog/

, see syntax highlighting and programming languages), graphics (graphics/, see the graphics editor) and the bibliographic database (database/, see the database and bibliographies).

4.Contents of this chapter

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