4 A Programmer's Text Editor
6 Miscellaneous editor actions.
8 Copyright (C) 1991-2007 Angel Ortega <angel@triptico.com>
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 http://www.triptico.com
28 /** editor actions **/
30 mp.actions['eval'] = sub (d) {
32 { 'label' => L("Code to execute:"),
40 if (! regex('/;\s*$/', t))
46 mp.alert(L("Error: ") ~ ERROR);
51 mp.alert(L("Exit value:\n") ~ t);
55 mp.actions['eval_doc'] = sub (d) {
56 local t = join("\n", d.txt.lines);
62 mp.alert(L("Error: ") ~ ERROR);
64 /* try to move the cursor to the line
65 where the error was */
68 if ((l = regex( [ '/, line /', '/[0-9]+/' ], ERROR)) != NULL)
76 mp.actions['encoding'] = sub (d) {
78 { 'label' => L("Encoding (utf-8, iso8859-1, etc.; empty, current locale)") ~ ':',
80 'history' => 'encoding' }
84 if (encoding(t[0]) == -1)
85 mp.alert(L("Invalid encoding ") ~ t[0]);
88 mp.actions['zoom_in'] = sub (d) {
90 mp.config.font_size++;
94 mp.actions['zoom_out'] = sub (d) {
96 if (mp.config.font_size > 4) {
97 mp.config.font_size--;
102 mp.actions['word_count'] = sub (d) {
105 local c = mp.word_count(d);
108 mp.alert(sprintf(L("Lines: %d Words: %d"),
109 size(mp.get_active_area(d)), c));
112 mp.actions['about'] = sub (d) {
114 "\nMinimum Profit %s - Programmer Text Editor\n\n"\
115 "Components: MPDM %s, MPSL %s\n\n"\
116 "Copyright (C) 1991-2007 Angel Ortega <angel@triptico.com>\n"\
118 "This program is free software; you can redistribute it and/or\n"\
119 "modify it under the terms of the GNU General Public License\n"\
120 "as published by the Free Software Foundation; either version 2\n"\
121 "of the License, or (at your option) any later version.\n"\
123 "This program is distributed in the hope that it will be useful,\n"\
124 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"\
125 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"\
126 "See the GNU General Public License for more details.\n"\
128 "You should have received a copy of the GNU General Public License\n"\
129 "along with this program; if not, write to the Free Software Foundation,\n"\
130 "Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n"\
132 "Home page: http://www.triptico.com/software/mp.html\n"\
133 "Mailing list: mp-subscribe@lists.triptico.com\n");
136 msg = sprintf(msg, mp.VERSION, mpdm.version, MPSL.VERSION);
138 d = mp.open("<about>");
140 if (size(d.txt.lines) == 1) {
147 /** default key bindings **/
149 mp.keycodes['escape'] = 'eval';
150 mp.keycodes['f12'] = 'zoom_in';
151 mp.keycodes['ctrl-kp-plus' ] = 'zoom_in';
152 mp.keycodes['f11'] = 'zoom_out';
153 mp.keycodes['ctrl-kp-minus' ] = 'zoom_out';
155 /** action descriptions **/
157 mp.actdesc['eval'] = LL("Execute MPSL code...");
158 mp.actdesc['eval_doc'] = LL("Execute document as MPSL");
159 mp.actdesc['encoding'] = LL("Set charset encoding...");
160 mp.actdesc['zoom_in'] = LL("Bigger font");
161 mp.actdesc['zoom_out'] = LL("Smaller font");
162 mp.actdesc['word_count'] = LL("Count words");
163 mp.actdesc['about'] = LL("About...");
168 /* overwrite of the MPSL dump() function, dumping over a text document */
170 local d = mp.open("<dump>");
173 mp.insert(d, dumper(v));
179 sub mp.word_count(doc)
180 /* counts the number of words in doc */
184 foreach (l, mp.get_active_area(doc))
185 w += size(mp.split_by_words(l));