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 */
47 mp.macro.process_event = NULL;
48 mp.macro.keycodes = NULL;
52 sub mp.process_event_and_record(k)
53 /* patched version of mp.process_event() */
56 push(mp.macro.keycodes, k);
58 /* calls the real mp.process_event() function */
59 mp.macro.process_event(k);
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 = [];
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);
89 /* if it's recording, stop now */
90 if (mp.macro.process_event != NULL)
93 /* process all stored keycodes */
94 foreach (k, mp.macro.keycodes)