Call mp.test_mtime() from inside mp.process_event().
[mp-5.x.git] / mp_misc.mpsl
blobb52913b3287ed71140574a1a39681b4e0433014f
1 /*
3     Minimum Profit 5.x
4     A Programmer's Text Editor
6     Miscellaneous editor actions.
8     Copyright (C) 1991-2011 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) { 
31     local t = mp.form(
32         [
33             {
34                 label:      L("Code to execute:"),
35                 type:       'text',
36                 history:    'eval'
37             }
38         ]
39     );
41     if (t != NULL) {
42         t = t[0];
44         if (! regex(t, '/;\s*$/'))
45             t = t ~ ';';
47         t = eval(t);
49         if (ERROR != NULL) {
50             mp.alert(L("Error: ") ~ ERROR);
51             ERROR = NULL;
52         }
53         else
54         if (t != NULL)
55             mp.alert(L("Exit value:\n") ~ t);
56     }
59 mp.actions['eval_doc']  = sub (d) {
60         local t = join(mp.get_active_area(d), "\n");
62         if (t != NULL) {
63                 t = eval(t);
65                 if (ERROR != NULL) {
66                         mp.alert(L("Error: ") ~ ERROR);
68                         /* try to move the cursor to the line
69                            where the error was */
70                         local l = regex(ERROR, [ '/, line /', '/[0-9]+/' ]);
72                         if (size(l) == 2)
73                                 mp.set_y(d, l[1]);
75                         ERROR = NULL;
76                 }
77         }
80 mp.actions['exec_action'] = sub(d) {
81     local l = mp.actions->keys()->sort();
83     l = map(l, sub (e) { e ~ ' - ' ~ L(mp.actdesc[e] || ''); });
85     local r = mp.form(
86         [
87             {
88                 label:  L("Select action to execute:"),
89                 type:   'list',
90                 list:   l
91             }
92         ]
93     );
95     if (r != NULL) {
96         local a = regex(l[r[0]], '/^[^ ]+/');
98         mp.active()->mp.actions[a]();
99     }
102 mp.actions['encoding']  = sub (d) {
103     local t = mp.form(
104         [
105             {
106                 label:   L("Encoding (utf-8, iso8859-1, etc.; empty, current locale)") ~ ':',
107                 type:    'text',
108                 history: 'encoding'
109             }
110         ]
111     );
113     if (t != NULL)
114         if (encoding(t[0]) == -1)
115             mp.alert(L("Invalid encoding ") ~ t[0]);
118 mp.actions['zoom_in']   = sub (d) {
120         mp.config.font_size++;
121         mp.update_ui();
124 mp.actions['zoom_out']  = sub (d) {
126         if (mp.config.font_size > 4) {
127                 mp.config.font_size--;
128                 mp.update_ui();
129         }
132 mp.actions['about'] = sub (d) {
133         local msg = L(
134         "Minimum Profit %s (%s) - Programmer Text Editor\n\n"\
135         "Components: MPDM %s, MPSL %s\n\n"\
136         "Copyright (C) 1991-2011 Angel Ortega <angel@triptico.com> and others\n"\
137         "\n"\
138         "This program is free software; you can redistribute it and/or\n"\
139         "modify it under the terms of the GNU General Public License\n"\
140         "as published by the Free Software Foundation; either version 2\n"\
141         "of the License, or (at your option) any later version.\n"\
142         "\n"\
143         "This program is distributed in the hope that it will be useful,\n"\
144         "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"\
145         "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"\
146         "See the GNU General Public License for more details.\n"\
147         "\n"\
148         "You should have received a copy of the GNU General Public License\n"\
149         "along with this program; if not, write to the Free Software Foundation,\n"\
150         "Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n"\
151         "\n"\
152         "Home page: http://triptico.com/software/mp.html\n"\
153         "Mailing list: mp-subscribe@lists.triptico.com\n");
155         local mpdm = MPDM();
156         msg = sprintf(msg, mp.VERSION, (mp.drv.id || 'unknown'), mpdm.version, MPSL.VERSION);
158         d = mp.open("<about>");
160         if (size(d.txt.lines) == 1) {
161                 mp.insert(d, msg);
162                 d.txt.mod = 0;
163                 d.read_only = 1;
164         }
167 /** default key bindings **/
169 mp.keycodes['escape']           = 'eval';
170 mp.keycodes['f12']              = 'zoom_in';
171 mp.keycodes['ctrl-kp-plus' ]    = 'zoom_in';
172 mp.keycodes['f11']              = 'zoom_out';
173 mp.keycodes['ctrl-kp-minus' ]   = 'zoom_out';
175 /** action descriptions **/
177 mp.actdesc['eval']          = LL("Execute MPSL code...");
178 mp.actdesc['eval_doc']      = LL("Execute document as MPSL");
179 mp.actdesc['exec_action']   = LL("Execute action on document...");
180 mp.actdesc['encoding']      = LL("Set charset encoding...");
181 mp.actdesc['zoom_in']       = LL("Bigger font");
182 mp.actdesc['zoom_out']      = LL("Smaller font");
183 mp.actdesc['about']         = LL("About...");
185 /** code **/
187 sub dump(v)
188 /* overwrite of the MPSL dump() function, dumping over a text document */
190         local d = mp.open("<dump>");
192         mp.move_eof(d);
193         mp.insert(d, dumper(v));
194         d.txt.mod = 0;
195         d.read_only = 1;