
\chapter{TeXmacs buffer management}

\section{Main data types}

The file ¤Server/tm_buffer.gen.h¤ defines the classes ¤tm_buffer¤,
¤tm_view¤ and ¤tm_window¤, with representation classes
\begin{verbatim}
    class tm_buffer_rep {
    public:
      string name;
      string abbr;
      array<tm_view> vws;
      tree t, style, init;
      bool modification_flag;
      bool not_saved_flag;
      bool read_only;
    };

    class tm_view_rep {
    public:
      tm_buffer buf;
      editor    ed;
      tm_window win;
    };

    class tm_window_rep {
    public:
      window    win;
      tm_widget wid;
    };
\end{verbatim}
An instance of ¤tm_buffer¤ corresponds to a \TeXmacs\ buffer and
a unique location somewhere on a storage medium.
Several views of the same buffer may be active at the same time.
Each such view ¤vw¤ is an instance of ¤tm_view¤,
and a unique editor ¤vw->ed¤ is associated to each view.
Each editor has a private style, environment, cursor, etc.
Finally, each active view should be attached to a unique window,
i.e. to an instance of ¤tm_window¤.

\section{States of the data}

Buffers, views, editors and windows can be in different states
during their manipulation, some of which are ``instable'',
i.e. not all data are initialized.

Instances of ¤editor¤ can be in the following states:
\begin{itemize}
  \item
    Uninitialized: this is the case, just after the creation of an editor.
    At this time, the editor is not yet attached to a window and
    the edit tree has not been typesetted.
  \item
    Suspended: this is the state of the editor after detaching
    it from a window, for instance by switching to another buffer.
    No window is attached to the editor in this state,
    but the edit tree might have been partially typeset.
  \item
    Active: the editor has been attached to a window and
    the edit tree has been typeset. But the editor is not necessarily
    in focus (i.e. server editor events may be sent to another editor).
  \item
    In focus: the editor is active and has keyboard focus.
    All server editor events are dispatched to the editor.
\end{itemize}
