| Did you know ... | Search Documentation: |
| Multiple fonts |
Using multiple fonts in an editor
The following example show multiple fonts can be used in an editor. Suppose want to have an editor that displays descriptions in the proportional helvetica font family and code fragments in a screen font.
The editor will be given an additional key-binding for \C-c\C-c
to convert the selection into a code fragment.
% Create a view that that allows mixing two fonts: one
% for normal text and one for program-text.
make_code_view :-
new(V, view('Code Editor Demo')),
send(V, font, normal),
send(V, style, code, style(font := fixed)),
send(V, key_binding, '\\C-c', prefix),
send(V, key_binding, '\\C-c\\C-c',
message(@prolog, make_fragment, V, code)),
send(V, open).
% make_fragment(+View, +Kind)
% Create a fragment for the region (caret, mark) of
% kind `Kind'.
% Note that mark and caret may be in any order.
make_fragment(V, Kind) :-
get(V, selection_start, Start),
get(V, selection_end, End),
Length is End - Start,
new(_, fragment(V?text_buffer, Start, Length, Kind)).
% Start the demo
:- make_code_view.