Do not use backslash-b to select backspaces.
[mp-5.x.git] / mp_build.mpsl
blobdc974b4554b31509b74dee71a125a60fe9b6c216
1 /*
3     Minimum Profit 5.x
4     A Programmer's Text Editor
6     A simple IDE-like build system.
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['build']     = sub(doc) {
32     local t, target;
34     if ((t = mp.build_get_targets()) == NULL)
35         mp.alert(L("No Makefile targets found."));
36     else {
37         /* more than one target? ask user to pick one */
38         if (size(t) > 1) {
39             local r = mp.form(
40                 [
41                     {
42                         label:  L("Makefile target") ~ ':',
43                         type:   'list',
44                         list:   t,
45                         value:  mp.makefile_target
46                     }
47                 ]
48             );
50             if (r != NULL) {
51                 mp.makefile_target = r[0];
53                 if (mp.makefile_target == 0)
54                     target = '';
55                 else
56                     target = t[mp.makefile_target];
57             }
58         }
60         if (target != NULL)
61             mp.long_op(mp.build_execute, target);
62     }
66 mp.actions['insert_next_item'] = sub(doc) {
67     local n = 0;
69     foreach (l, doc.txt.lines) {
70         local r = regex(l, ['/^ \* /', '/[0-9]+/', '/: /']);
72         if (r[1] > n)
73             n = r[1];
74     }
76     mp.store_undo(doc);
77     mp.insert(doc, ' * ' ~ (n + 1) ~ ': ');
80 /** Default key bindings **/
82 mp.keycodes['f2'] = "build";
84 /** action descriptions **/
86 mp.actdesc['build']             = LL("Build project...");
87 mp.actdesc['insert_next_item']  = LL("Insert next item");
90 /** code **/
92 sub mp.build_get_targets
94     local r, f;
96     if ((f = open('Makefile', 'r')) != NULL) {
97         local l;
99         r = [ '<default>' ];
101         while (l = read(f)) {
102             local t;
104             if (t = regex(l, '/^[A-Za-z0-9_\.-]+:/'))
105                 push(r, sregex(t, '/:/', ''));
106         }
108         close(f);
109     }
111     return r;
115 sub mp.build_execute(target)
117     local log = mp.open('<make output>');
119     log.txt.lines = [];
120     log.txt.y = 0;
122     /* pipe through make */
123     local p;
124     if ((p = popen('make ' ~ target, 'r')) != NULL) {
125         local l;
127         while (l = read(p))
128             mp.insert(log, l);
130         pclose(p);
132         log.txt.mod = 0;
133         log.read_only = 1;
135         log.syntax = mp.syntax.make_output;
137         mp.move_bof(log);
139         /* set the last search regex to match file:line strings,
140             so that calling seek-next and seek-prev moves there */
141         mp.last_search = '/^[a-z\.\_0-9\/-]+:[0-9]+:/m';
143         mp.redraw();
144     }