As mentioned before the editor has a text buffer in which it stores its text, and the video page just provides a window onto part of this buffer. Text is stored in the buffer on a line oriented basis. Each line has a three byte line header containing certain flags and margin information. This is followed by the text of the line itself stored in ASCII. The line is terminated by a special character which indicates whether it is the last line in a paragraph and whether it is the last line in the buffer.
The lines are stored with variable length so if a line only has four characters on it, followed by 36 spaces then the 36 spaces are not stored. This improves buffer usage very significantly since in general short lines are quite common. There is no limit to the number of lines in the buffer other than the total size of the buffer.
The buffer is arranged as a circular buffer so the start of the text may be anywhere in the buffer, and the end of the buffer may occur at any point in the text with the text continuing again at the start of the buffer. This avoids ever having to move the whole text up or down in the buffer.
When new text is entered into the buffer, either at the end or into the middle of the buffer this clearly uses up buffer space. Eventually the buffer may become full. In fact it is generally the case when using BASIC that the buffer is nearly full most of the time, as it contains previous commands and so on which have scrolled off the screen.
Whenever there are less than 100 bytes spare in the buffer the editor displays a number on the right hand side of the status line indicating the number of free bytes. As characters are typed in, this number will get smaller until it eventually reaches zero. This number is only displayed when waiting for keyboard input from the user, so for example the number cannot be seen when BASIC is listing a program even though the buffer may be full.
When the buffer is full and another character is typed in (or written by the applications program), the editor has to delete some of the existing text to make room. It always deletes a whole line of text and it generally deletes the first line since this will normally be the oldest and least useful one. If the first line of text is displayed on the video page then it deletes the last line instead, to avoid deleting text which is displayed.
If the editor buffer is very small or there are some very long lines, then every line may be displayed at once, so the editor has no choice but to delete a line which is displayed. In this case the editor deletes the last line unless the cursor is on the last line, in which case it deletes the first line and scrolls the page up.
Note that because the editor buffer is circular, deleting this line of text does not involve moving the whole text up to fill the gap (at least not usually).
Each line in the buffer has its own individual left margin position. When a new line is created it will be given a left margin equal to the current left margin setting which can be displayed on a ruler line at the top of the video page. There is also a right margin which is displayed on the ruler line. In general text can only be entered in between these margin settings although there is the facility of temporarily releasing the margins.
Lines in the editor's buffer are grouped together in paragraphs. When the
user presses Enter (or a CR
is received from the
applications program) this marks the current line as the end of a
paragraph. It also moves the cursor to the start of the next line which
will be the start of a new paragraph (and may have the side effect of
sending text to the applications program - see later).
If the user types a very long line then the editor will split the line at a sensible point (using a process called word wrap described in the next section) to give two lines. The first line will be terminated by a soft carriage return marker to indicate that is not the end of a paragraph. In this way long paragraph lines can be built up.
There is no indication on the screen of where paragraphs start and end but some of the editing functions operate on paragraphs, and the paragraph is the basic unit for sending text back to the applications program.
Word wrap is the process which decides where to split a line which is too long. When a character is typed outside the margins (assuming that margins are not released) then the editor searches back to find the start of the word which contained that character and moves the whole of that word onto the start of a new line.
This process is done with all text received from the applications program as well as that typed at the keyboard from the user. Thus BASIC listings are subject to word wrap do keywords and variable names etc. will not be split in half.
Although a very long line which is typed in will be split by word wrap,
it is possible to create a long line by inserting characters into the
middle of a line, which will push the rest of the line to the right. In
this way it is possible to create a line which is too long to be all
displayed on the video page. This fact is marked by a red right angle
bracket (">"
) on the extreme right hand end of the line
on the video page. This is an overflow marker.
The part of the line which has gone off the page cannot be accessed although it is remembered by the editor. The line can only be accessed by reformatting it to bring it back onto the page. There are various editing commands which can do this described later on.
The EXOS video driver which the editor uses only provides a static nonflashing cursor display, although this can be turned on and off. The editor implements a flashing cursor by simply turning the video page's cursor on and off regularly while it is waiting for input from the user. It always ensures that the cursor is switched off when it is doing any editing functions, since these can result in the cursor having to move the screen and it is rather messy if the cursor can be seen doing this.
The editor also switches the cursor off whenever it returns to the applications program and it remains off when the applications program is writing characters to the editor. This results in a nice clean cursor display, where the flashing cursor always means that the editor is waiting for the user to type some input.