GNU TeXmacsUser manualReferenceAboutEnglish
Structured editing, search and automatic content

1.Introduction

Almost every editing command of TeXmacs, from typing a character to inserting a table column or regenerating the index, ends up in one of the C++ classes of the directories

Edit/Modify/

,

Edit/Replace/

and

Edit/Process/

. These classes implement the structured editing operations: they know how text, formulas, tables and macro applications are represented as trees, and turn a request such as “delete backwards” or “make a fraction” into a short sequence of elementary tree modifications that keeps the document well-formed.

This chapter describes these operations. It does not repeat the parts that are documented elsewhere:

All file names below are relative to

src/src/

unless stated otherwise; Scheme files are relative to

src/TeXmacs/progs/

.

2.Overview

An editing command usually goes through four layers:

  1. A Scheme command, bound to a key or a menu entry. Keyboard commands are mostly generic dispatchers defined with tm-define, which are overloaded for particular tags with :require clauses; for instance kbd-backspace calls (kbd-remove (focus-tree) #f), and kbd-remove has specialized definitions for sessions, folding environments, databases, … before falling back on remove-text (

    generic/generic-edit.scm

    ). Thin wrappers such as insert, make, make-fraction or clipboard-paste are defined in

    utils/library/cpp-wrap.scm

    .

  2. A glue routine of

    Scheme/Glue/build-glue-editor.scm

    , such as cpp-insert (insert_tree), remove-text (remove_text), cpp-make (make_compound) or table-insert-column (table_insert_column), which calls the corresponding method of the current editor.

  3. The structured operation itself, a method of one of the classes edit_text_rep, edit_math_rep, edit_table_rep, edit_dynamic_rep, edit_select_rep, edit_replace_rep or edit_process_rep, all of which derive virtually from editor_rep and are combined in edit_main_rep. Since the classes only see each other through the pure virtual methods of editor_rep, any operation can call any other: the deletion code of edit_text_rep calls the table code for cells and the math code for brackets, and almost every constructor ends with insert_tree.

  4. Elementary modifications: assign, insert, remove, split, join, assign_node, insert_node and remove_node on absolute paths in the global edit tree. These are the only functions which change the document. They notify the observers, so that the typesetter, the undo history, position observers and the other views are updated automatically (see the modification pipeline).

Two consequences of this design are worth keeping in mind. First, the structured operations work directly on the global tree et with paths starting with the root path rp of the buffer, and they re-read subtree (et, p) after each elementary modification, since a local copy would be stale. Second, after a sequence of modifications the cursor tp is corrected by the editor itself (in post_notify), so the operations only need to move it explicitly with go_to when the natural correction is not what the user expects.

3.Source files

Edit/Modify/edit_text.hpp
,
edit_text.cpp
,
edit_delete.cpp

The class edit_text_rep: insertion of trees and paragraphs, normalization of concat nodes, spaces, images, and the general deletion algorithm (

edit_delete.cpp

).

Edit/Modify/edit_math.hpp
,
edit_math.cpp

The class edit_math_rep: constructors for fractions, roots, scripts, primes, wide accents, negations and trees, and the deletion rules for brackets, primes, wide accents and trees.

Edit/Modify/edit_dynamic.hpp
,
edit_dynamic.cpp

The class edit_dynamic_rep: insertion of arbitrary tags (make_compound), activation of inactive tags, insertion and removal of arguments, with and style-with, hybrid commands and LaTeX-like commands, and the general deletion rules for macro applications.

Edit/Modify/edit_table.hpp
,
edit_table.cpp

The class edit_table_rep: everything about tables.

Edit/Modify/edit_modify.hpp
,
edit_modify.cpp

The class edit_modify_rep, which receives the modifications and implements undo and redo; see undo and redo.

Edit/Replace/edit_select.hpp
,
edit_select.cpp

The class edit_select_rep: the selection, semantic selections, the clipboard, cutting, the focus and alternative selections.

Edit/Replace/edit_replace.hpp
,
edit_search.cpp
,
edit_spell.cpp

The class edit_replace_rep: structural searches upwards from the cursor, the keyboard driven search and replace mode, and the spell checking mode.

Data/Tree/tree_search.cpp

The pattern matcher used by the search and replace tools (tree-search-tree-at).

Edit/Process/edit_process.hpp
,
edit_process.cpp

The class edit_process_rep: generation of bibliographies, tables of contents, indexes, glossaries and lists of figures and tables.

utils/library/cpp-wrap.scm

The Scheme wrappers insert, make, make-with, the math constructors and the clipboard commands.

generic/generic-edit.scm

The generic keyboard dispatchers (kbd-remove, kbd-enter, kbd-variant, structured-insert-horizontal, …).

generic/search-widgets.scm

The search and replace tools and toolbars.

generic/document-edit.scm

The update-document command behind Document\(\rightarrow\)Update.

packages/standard/std-automatic.ts

(relative to

src/TeXmacs/

) The macros which record entries for the automatic content with the write primitive.

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