src/swipl-devel/packages/xpce/man/refmanual/md/fragment.md

class fragment {#class-fragment}

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

@see editor-selected_fragment @see editor-margin @see class style @see editor-selected_fragment_style @see editor-styles @see editor->selected_fragment @see text_buffer<-find_all_fragments @see class font @see class editor @see class text_buffer @see class text_margin

Instance variables {#class-fragment-instvars}

Send methods {#class-fragment-send}

Get methods {#class-fragment-get}



Try the rswipl package in your browser

Any scripts or data that you put into this service are public.

rswipl documentation built on June 16, 2026, 5:07 p.m.