A fragment object describes part of a text_buffer object. Fragments are maintained by the text_buffer they are associated with and move along with edit operations, so they keep pointing to the same text.
Fragments have been implemented to allow for annotation of textual information. Besides defining a range of characters, fragments define their visual appearance when displayed by an editor. The location of fragments in a text can be visualised by a text_margin object associated with an editor object. This visualisation is done using icons (image objects).
Fragments may be used to realise multiple fonts, styles and colours
in
editor objects.
Another use for fragments is to make fragments of the text active, e.g.
allow the user to follow a link from the specified fragment
(hyper-text). Finally, fragments may be used as text-markers.
The following fragment turns the selection of an editor into bold font:
demo :-
send(new(V, view), open),
send(V, style, bold, style(bold := @on)),
send(V, key_binding, '\C-b',
message(@prolog, make_bold, V?editor)).
make_bold(E) :-
get(E, selection_start, Start),
get(E, selection_end, End),
Len is End - Start,
new(_, fragment(E, Start, Len, bold)).
<-first_fragment
and
text_buffer<-last_fragment
define the double linked list of fragments that is sorted on fragment<-start.
These methods are normally not used to analyse the available
fragments. See text_buffer<-find_all_fragments
and text_buffer<-find_fragment
for locating fragments.
->style
the user specifies how fragments of this style are visualised.
<-endWhat defaults to both (include both start and
end).
include defaults to @on.
Initially neither of the ends is included. See also fragment->insert.
<-start
and is fragment<-length (may be 0)
characters long.
fragment<-style
is a logical indicating the category of the fragment (e.g.
title, example, glossary, refers_to, ...). The visual implication of a
style-name is determined using editor->style
and/or list_browser->style.->insert’with
the properly translated arguments. If the index is
@default, the
text is appended to the fragment. For example, the PceEmacs shell mode
uses a fragment to insert the output of the sub-process. See xpce/prolog/lib/emacs/shell_mode.pl.|fragment|point<-x
to
point<-y.
Often used in combination with text_buffer<-find
to find a fragment overlapping the caret.move_end equals @off,
the end-point is not moved. Otherwise the end-point is moved by the same
amount (fragment<-length is not changed).<-text_buffer
and inform the possible related editors of the change.
<-end
is defined as fragment<-start + fragment<-length.
Modifying the fragment<-end
modifies the fragment<-length of the
fragment.<-text_buffer.
If no fragment can be found in the indicated direction, these methods fail.