summaryrefslogtreecommitdiff
path: root/macro.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-03-23 14:18:26 -0400
committerpommicket <pommicket@gmail.com>2023-03-23 14:18:26 -0400
commitf338c3937686c4297daa1d24aacce719aa549ec7 (patch)
tree9b91859f3462b4f6ade85dfb55d19f49bdaa775d /macro.c
parenteb088ebd059ba00735723fb394d3bfe1b3530026 (diff)
macros are working!
Diffstat (limited to 'macro.c')
-rw-r--r--macro.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/macro.c b/macro.c
index 81f1898..14ec016 100644
--- a/macro.c
+++ b/macro.c
@@ -1,9 +1,26 @@
#include "ted.h"
+static void macro_clear(Macro *macro) {
+ arr_foreach_ptr(macro->actions, Action, act) {
+ free((char *)act->argument.string);
+ }
+ arr_free(macro->actions);
+
+ memset(macro, 0, sizeof *macro);
+}
+
void macro_start_recording(Ted *ted, u32 index) {
if (index >= TED_MACRO_MAX) return;
if (ted->executing_macro) return;
+ if (ted->recording_macro) {
+ macro_stop_recording(ted);
+ return;
+ }
+
+ command_execute(ted, CMD_CLEAR_SELECTION, 0);
+
ted->recording_macro = &ted->macros[index];
+ macro_clear(ted->recording_macro);
}
void macro_stop_recording(Ted *ted) {
@@ -43,9 +60,6 @@ void macro_execute(Ted *ted, u32 index) {
void macros_free(Ted *ted) {
for (int i = 0; i < TED_MACRO_MAX; ++i) {
Macro *macro = &ted->macros[i];
- arr_foreach_ptr(macro->actions, Action, act) {
- free((char *)act->argument.string);
- }
- arr_free(macro->actions);
+ macro_clear(macro);
}
}