This document describes all the MPSL data structures that build the Minimum Profit Text Editor, with examples showing how to change or update its behaviour.
Each open document is a hash, containing all the information about it,
including its text, position, name and the list of changes. A new document
is created by calling mp.new() or mp.open(). The keys stored in each
document are the following:
mp.syntax hash, may be NULL or undefined).
txt. Every time the user changes a document (inserting or deleting text, etc.), the previous value of txt is pushed here. Every time the 'undo' action is executed, the last value is popped from here and stored in the txt key and the redo list.
undo key.
mp.config.keep_eol is set.
mp.post_paint.
The txt component contains the current state of the document:
size(txt.lines) - 1).
size(txt.lines[txt.y]) - 1).
The list of open documents in stored in the mp.docs array. The subscript
to the active one (the one returned by mp.active()) is stored in the
mp.active_i variable. Setting this value effectively changes the active
document (obviously, in the 0 .. size(mp. range).
docs()) - 1
The configuration is stored in the mp.config hash. Information about this
structure can be found in the included document
Minimum Profit Configuration Directives.
Colors are defined in the mp.colors hash. The keys contain the name of
the color in a syntax highlighting context (i.e. comments for the text
inside source code comments, quotes for the text inside quotes, and so
on), and the values are hashes containing the definition for that color in
the different driver types. For now, only gui and text drivers exist,
with another special key, flags, for special effects.
The color keys are:
For each key, the value is a hash containing the following keys:
black, red, green, yellow, blue, magenta, cyan and white. Another special value, default, skips setting a color.
reverse, bright and underline (not all drivers accept all these keywords).
The syntax highlight definitions are stored in the mp.syntax hash. Each
key is the name of the syntax highlight (for example, html), and they
value is the definition hash. This definition set can be assigned to a
document syntax key and will be immediately applied.
The keys in the definition hash are:
perl or html.
f1 over a word in a document. It must contain a %s as a placeholder of the word (for example, "man %s" or "perldoc -f %s").
section_list action form.
The syntax highlight definitions is a list containing color names (keys to
the mp.colors hash) and an array. The array can contain single strings
of regular expressions (matching string will have the color set), or an
array of two regular expressions (setting the start and the end of the
block to be coloured).
This is a snippet for the comments definition in the C language syntax
highlight. The first definition is a two array of regular expressions,
matching the start and the end of a C style comment; all text between these
marks will be coloured as a comment. The following one, a single string, is
a regular expression that matches from two slashes to the end of the line:
/* more code above... */ 'comments', [ [ '|/\*|', '|\*/|' ], /* C style */ '|//.*$|m', /* C++ style */ ]
See the mp_syntax.mpsl for details and examples.
Keycodes are defined in the mp.keycodes hash. Each key contain the name
of the keycode, as ctrl-f or f3. The value can be an executable value
(that will be directly executed with the current document as only
argument), a string containing the name of an action (that must be a key to
the mp.actions hash), or another hash, that will contain itself keycodes
as keys and executable values or action names as values (this mechanism can
be nested ad infinitum), to implement keystroke chains in the Emacs style.
Examples:
/* bind ctrl-f to the 'seek' action */
mp.keycodes['ctrl-f'] = 'seek';
/* bind F5 to an anonymous subroutine */
mp.keycodes['f5'] = sub (d) {
mp.insert(d, "<form action = 'post'></form>");
};
/* bind Ctrl-x Ctrl-f to 'open', and
Ctrl-x Ctrl-s to 'save' */
mp.keycodes['ctrl-x'] = {
'ctrl-f' => 'open',
'ctrl-s' => 'save'
};
Actions are defined in the mp.actions hash. Each key contain the name of
the action, as seek or move_up. Each value contain an executable
value that accepts a document as the only argument.
mp.actions['sync'] = sub (d) {
/* save all modified documents */
foreach (local d, grep(sub (e) { e.txt.mod; }, mp.docs))
mp.actions.save(d);
};
Action descriptions are strings stored in the mp.actdesc hash. Each key
contain the name of the action and each value the translatable string for
human consuming and will be used in the menu.
Examples:
mp.actdesc['seek'] = LL("Search text...");
mp.actdesc['seek_next'] = LL("Search next");
mp.actdesc['sync'] = LL("Save modified texts");
The menu is stored in the mp.menu structure. The menu is an array of
dropdown menu definitions. Each dropdown menu is a two-element array
containing a string for the label (File, Edit, etc.) and another array of
action names (keys to mp.actions). See the mp_core.mpsl source file
where it's defined.
If a non-obstrusive message must be notified to the user, the mp.message
can be set and the message will be shown in the status line until a
specified time is reached. This structure is a hash containing:
Example:
/* show a message for 4 seconds */
mp.message = {
'string' => "Unknown keystroke",
'timeout' => time() + 4
};
The clipboard is stored in the mp.clipboard array, and it's a simple
array of lines. Each copy and paste operation manipulates this.