Do not use backslash-b to select backspaces.
[mp-5.x.git] / mp_macro.mpsl
blob7ee08b1134ef12cc0994cc38c4b3df6092610708
1 /*
3     Minimum Profit 5.x
4     A Programmer's Text Editor
6     Macro recording (learning mode).
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['record_macro']      = sub (d) { mp.record_macro(); };
31 mp.actions['play_macro']        = sub (d) { mp.play_macro(); };
33 /** default key bindings **/
35 mp.keycodes['f10']      = "record_macro";
36 mp.keycodes['ctrl-f10'] = "record_macro";
37 mp.keycodes['f7']       = "play_macro";
39 /** action descriptions **/
41 mp.actdesc['record_macro']      = LL("Record macro");
42 mp.actdesc['play_macro']        = LL("Play macro");
44 /* learning/recording data */
46 mp.macro = {};
47 mp.macro.process_event = NULL;
48 mp.macro.keycodes = NULL;
50 /** code **/
52 sub mp.process_event_and_record(k)
53 /* patched version of mp.process_event() */
55         /* records */
56         push(mp.macro.keycodes, k);
58         /* calls the real mp.process_event() function */
59         mp.macro.process_event(k);
63 sub mp.record_macro
64 /* start recording a macro */
66         if (mp.macro.process_event == NULL) {
67                 /* if still not recording, store the real mp.process_event()
68                    function and replace it by ours */
69                 mp.macro.process_event = mp.process_event;
70                 mp.process_event = mp.process_event_and_record;
72                 /* reset keycode list */
73                 mp.macro.keycodes = [];
74         }
75         else {
76                 /* unpatch mp.process_event() */
77                 mp.process_event = mp.macro.process_event;
78                 mp.macro.process_event = NULL;
80                 /* drop the last keycode (that triggered mp.record_macro()) */
81                 if (mp.keycodes[mp.macro.keycodes[-1]] eq 'record_macro')
82                         pop(mp.macro.keycodes);
83         }
86 sub mp.play_macro
87 /* play a macro */
89         /* if it's recording, stop now */
90         if (mp.macro.process_event != NULL)
91                 mp.record_macro();
93         /* process all stored keycodes */
94         foreach (k, mp.macro.keycodes)
95                 mp.process_event(k);