1 Minimum Profit Data Model
2 =========================
4 This document describes all the MPSL data structures that build the Minimum
5 Profit Text Editor, with examples showing how to change or update its
11 Each open document is a hash, containing all the information about it,
12 including its text, position, name and the list of changes. A new document
13 is created by calling mp.new() or mp.open(). The keys stored in each
14 document are the following:
16 * name: The name of the document (<unnamed> for unnamed documents).
17 * syntax: The optional syntax highlight definition that applies to it
18 (a value in the `mp.syntax' hash, may be NULL or undefined).
19 * txt: The _state_ of the document (see below).
20 * undo: A list of different values of `txt'. Every time the user changes
21 a document (inserting or deleting text, etc.), the previous value of
22 `txt' is pushed here. Every time the 'undo' action is executed, the
23 last value is popped from here and stored in the `txt' key and the
25 * redo: A list of values popped from the `undo' key.
26 * read_only: If set to nonzero, the document is read-only and cannot
28 * encoding: The encoding that was autodetected when loading the
29 document. If it's NULL or an empty string, no special encoding
30 was detected. If this field is set and the global encoding is not,
31 it's used as the file encoding when saving.
33 The `txt' component contains the current state of the document:
35 * lines: The array of lines that form the document (the document itself).
36 * y: The Y position (line, from 0 to `size(txt.lines) - 1').
37 * x: The X position (column, from 0 to `size(txt.lines[txt.y]) - 1').
38 * mod: A modifier flag. If it's nonzero, the document has unsaved changes.
39 * vx: The first column (from 0) that is visible on screen.
40 * vy: The first line (from 0) that is visible on screen.
45 The list of open documents in stored in the `mp.docs' array. The subscript
46 to the active one (the one returned by mp.active()) is stored in the
47 `mp.active_i' variable. Setting this value effectively changes the active
48 document (obviously, in the 0 .. `size(mp.docs()) - 1' range).
53 The configuration is stored in the `mp.config' hash. Information about this
54 structure can be found in the included document
55 ./mp_configuration.html (Minimum Profit Configuration Directives).
60 Colors are defined in the `mp.colors' hash. The keys contain the name of
61 the color in a syntax highlighting context (i.e. `comments' for the text
62 inside source code comments, `quotes' for the text inside quotes, and so
63 on), and the values are hashes containing the definition for that color in
64 the different driver types. For now, only `gui' and `text' drivers exist,
65 with another special key, `flags', for special effects.
69 * cursor: The color of the cursor.
70 * selection: The color of the selected block.
71 * comments: Text inside programming language comments.
72 * documentation: Text inside documentation marks.
73 * quotes: Text between quotes.
74 * matching: The color of the matching brace (if the cursor is over one).
75 * word1: 1st definition for special words (i.e. tokens).
76 * word2: 2nd definiton for special words (i.e. variables).
77 * tag: Color for tags (symbol names).
78 * spell: Color for mis-spelled words (if spelling is on).
79 * search: Color for the last matched string in searches.
80 * normal: Text outside any other context, or the base color if no syntax
81 highlight is selected.
83 For each key, the value is a hash containing the following keys:
85 * text: a two element array containing the color names for background
86 and foreground. These strings match the colors in Curses terminal modes
87 and must be one of `black', `red', `green', `yellow', `blue',
88 `magenta', `cyan' and `white'. Another special value, `default', skips
90 * gui: A two element array containing the RGB color for background and
91 foreground. It's handy to set this values as hexadecimal numbers,
92 having 0x000000 for black and 0xffffff for white.
93 * flags: This is an optional array containing keywords for special
94 effects in colors. Acceptable values are `reverse', `bright' and
95 `underline' (not all drivers accept all these keywords).
100 The syntax highlight definitions are stored in the `mp.syntax' hash. Each
101 key is the name of the syntax highlight (for example, `html'), and they
102 value is the definition hash. This definition set can be assigned to a
103 document `syntax' key and will be immediately applied.
105 The keys in the definition hash are:
107 * id: The same as the key, as `perl' or `html'.
108 * name: A human-consuming name, that will be shown in the status line
109 (for example, "C / C++" or "Shell script").
110 * filenames: An array of regular expressions to be applied to the
111 document name for syntax detection.
112 * help: An array of system commands to be executed when the help system
113 is invoked by pressing `f1' over a word in a document. It must contain
114 a %s as a placeholder of the word (for example, "man %s" or
116 * defs: An array of definitions.
117 * detect: An optional subroutine that accepts a document as the only
118 argument and that must return a boolean value. This subroutine will be
119 called when auto-detecting the syntax highlight.
120 * section: An array of regular expressions that defines a _section_ inside
121 a document. A section is a special area in the document, as a function
122 definition, for example. Lines matching this regexes will be shown
123 in the `section_list' action form.
125 The syntax highlight definitions is a list containing color names (keys to
126 the `mp.colors' hash) and an array. The array can contain single strings
127 of regular expressions (matching string will have the color set), or an
128 array of two regular expressions (setting the start and the end of the
129 block to be coloured).
131 This is a snippet for the `comments' definition in the C language syntax
132 highlight. The first definition is a two array of regular expressions,
133 matching the start and the end of a C style comment; all text between these
134 marks will be coloured as a comment. The following one, a single string, is
135 a regular expression that matches from two slashes to the end of the line:
137 /* more code above... */
139 [ '|/\*|', '|\*/|' ], /* C style */
140 '|//.*$|m', /* C++ style */
143 See the `mp_syntax.mpsl' for details and examples.
148 Keycodes are defined in the `mp.keycodes' hash. Each key contain the name
149 of the keycode, as `ctrl-f' or `f3'. The value can be an executable value
150 (that will be directly executed with the current document as only
151 argument), a string containing the name of an action (that must be a key to
152 the `mp.actions' hash), or another hash, that will contain itself keycodes
153 as keys and executable values or action names as values (this mechanism can
154 be nested ad infinitum), to implement keystroke chains in the Emacs style.
158 /* bind ctrl-f to the 'seek' action */
159 mp.keycodes['ctrl-f'] = 'seek';
161 /* bind F5 to an anonymous subroutine */
162 mp.keycodes['f5'] = sub (d) {
163 mp.insert(d, "<form action = 'post'></form>");
166 /* bind Ctrl-x Ctrl-f to 'open', and
167 Ctrl-x Ctrl-s to 'save' */
168 mp.keycodes['ctrl-x'] = {
176 Actions are defined in the `mp.actions' hash. Each key contain the name of
177 the action, as `seek' or `move_up'. Each value contain an executable
178 value that accepts a document as the only argument.
180 mp.actions['sync'] = sub (d) {
181 /* save all modified documents */
182 foreach (local d, grep(sub (e) { e.txt.mod; }, mp.docs))
189 Action descriptions are strings stored in the `mp.actdesc' hash. Each key
190 contain the name of the action and each value the translatable string for
191 human consuming and will be used in the menu.
195 mp.actdesc['seek'] = LL("Search text...");
196 mp.actdesc['seek_next'] = LL("Search next");
197 mp.actdesc['sync'] = LL("Save modified texts");
202 The menu is stored in the `mp.menu' structure. The menu is an array of
203 dropdown menu definitions. Each dropdown menu is a two-element array
204 containing a string for the label (File, Edit, etc.) and another array of
205 action names (keys to `mp.actions'). See the `mp_core.mpsl' source file
211 If a non-obstrusive message must be notified to the user, the `mp.message'
212 can be set and the message will be shown in the status line until a
213 specified time is reached. This structure is a hash containing:
215 * string: The string to be shown in the status line.
216 * timeout: The time when the string will stop being showed.
220 /* show a message for 4 seconds */
222 'string' => "Unknown keystroke",
223 'timeout' => time() + 4
229 The clipboard is stored in the `mp.clipboard' array, and it's a simple
230 array of lines. Each copy and paste operation manipulates this.
233 Angel Ortega <angel@triptico.com>