A text_buffer forms the storage component of an editor object. It represents a text, possible with fragment objects defined on it.
Class text_buffer defines the primitive operations that can be done on text. The more user-oriented behaviour of an editor is defined with class editor. Among the operations are inserting text, deleting text, scanning for units such as words, lines and paragraphs, saving and loading, etc.
A text_buffer maintains a changes record that supports the
implementation of text_buffer->undo.
A text_buffer can simultaneously be visualised by any number of editor objects.
<-modified,
the editor objects in
text_buffer<-editors
will be informed.
This variable is managed by text_buffer->attach
and text_buffer->detach,
called from
editor->initialise, editor->unlink
and editor->text_buffer.
The methods text_buffer->attach
and text_buffer->detach
may be redefined to monitor attachments/detachments of editors. The
redefinition must use
object->send_super
and may not fail.
<-start.
See also
fragment<-next
and fragment<-previous.<->modified
flag for that purpose as this reflects whether the content is different
from the file or not.
Please note that this counter is only incremented; text_buffer->undo
actions increment it too.
-first_fragment<-modified_message
with the following arguments:
@receiver editor <-master@arg1 New value of text_buffer <-modified.
See also text_buffer<-generation.
<-length
is available to avoid a conflict with editor<->size.->syntax
for details.
Initially this slot is filled with the built-in syntax_table
object named default.
The text_buffer's text_buffer<-syntax
table is used by many methods on class text_buffer
and class editor to
recognise words, matching braces, comment, etc. Syntax tables are used
extensively by PceEmacs.
See also text_buffer<-scan, text_buffer->in_comment, text_buffer<-skip_comment,
and
text_buffer->for_all_comments
->insert and text_buffer->format.-editorsno-change checkpoint in the undo buffer. If text_buffer->undo
reverts back to this point, text_buffer<-modified
will be reset to @off.<-contents
of the text_buffer
object. In addition, it resets the text_buffer->undo
system and deletes all associated
fragment objects.
See also text_buffer->insert_file.
Defaults:
By default, 1 character is deleted.
-editors<-find_fragment
and text_buffer<-find_all_fragments.
Arguments:
@arg1 The fragment object
->append
formatted text. See string->format
for the definition of the format string and its arguments.start is specified it will start scanning from
this index, assuming that the given index is not in a string or comment.
See
syntax_table->syntax
for defining the comment syntax.<->newline_mode
if it is set to detect at entry to simplify Windows/Unix interaction.
This is exploited by PceEmacs.
See also text_buffer->save, text_buffer->contents
and class editor.
See also file->encoding.
head
of the undo buffer. A subsequent undo will text_buffer->undo
all changes back to this mark. Normally set by editor->event.<-editors.
See editor->report
and‘visual
text_buffer->report’.from is 0 and the size will save to the end of
the buffer. If both
from and size are omitted, text_buffer<-modified
will be set to @off.
See also
editor->save
and editor->save_buffer.Bugs: Not very flexible and doubtfful, whether this is the right level for implementing this method.
->undo_mark.
If this is a text_buffer->reset_undo
checkpoint, reset text_buffer->modified
to @off.
Changes are stored in a buffer of size text_buffer<-undo_buffer_size.
Changes that exhaust the size of this buffer are lost.->lost_text_buffer
to all related text_buffer<-editors
and returns all alien resources to the system.
<-contents
and
text_buffer<-sub
only differ in the interface. text_buffer<-sub
is compatible to char_array<-sub
and the preferred interface.
from: Start the search from this index for: Search for this string times (1): Return the nth occurrence return (start): start: first character,end: last characterexactcase (@on): @off: case does not matter wordmode (@off): @on: find whole words only
Fails silently if the requested string cannot be found. See also class regex.
<-find_all.
This method is commonly used to find fragments with a certain attribute overlapping the caret position:
...
get(TextBuffer, find_all_fragments,
and(message(@arg1, overlap, Caret),
@arg1?style == active),
Fragments),
...
See also text_buffer->for_all_fragments, text_buffer<-find_fragment.
<-find_all_fragments,
text_buffer->for_all_fragments.-size.from holds a text_buffer<-character bracket.
If no bracket is specified, the text_buffer<-character
at from is used. Specifying the bracket is useful to find the start of
the bracketed environment point is in.
start_of_compound_statement(TB, Here, Start) :-
get(TB, matching_bracket, Here, '}', Start).
If this method traps -while scanning-, a bracket mismatch (e.g.
(hello}) it will generate a mismatched_bracket error. See class error
and the predicate pce_catch_error/2.
See class syntax_table for defining brackets.
This method deals with string and comment. See text_buffer->in_string,
text_buffer->in_comment
and text_buffer<-scan.
from, scanning in the
indicated direction. Class syntax_table
defines quotes and escape sequences for quotes.->forward_word,
editor->transpose_terms,
etc. Arguments:
from Index to start scanning unit Unit to scan for times Number of units to skip (<0: backwards) return start: start of unit, end: end of unit
For example,
get(TextBuffer, scan, 200, word, 2, start, Index)
will scan two words from index 200 and return the start of the 2nd word.
The definitions of the units is determined by the associated text_buffer<-syntax.
See also text_buffer<-matching_bracket.
<-syntax
object. Scanning starts at from, which is assumed to be
outside comment and strings. The return-value is a tuple
object, whose first part is a name indicating the syntactical category
at to and whose second part denotes the start-position of
this syntactical object.
Returned syntactical categories:
See also class syntax_table, text_buffer<-skip_comment, text_buffer<-skip_layout,
text_buffer<-matching_bracket.
-sizefrom points to a layout character or the start of a
comment. Return the first location not in a comment and not whitespace.
If
skip_layout is @off,
just comment will be skipped.
See also text_buffer->in_comment
and text_buffer<-skip_layout
and class syntax_table.
See also text_buffer<-skip_comment, text_buffer<-scan, text_buffer<-find, regex->search.