aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2024-10-16 11:40:52 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-10-16 11:40:52 +0300
commitd714bb48a4b8629f6345a28bc21a24537207176b (patch)
treed605b57c182741590377edae8ced7e693000523d /src
parentd556aee67e615b48c25861741d28d103109235e3 (diff)
downloadsciteco-d714bb48a4b8629f6345a28bc21a24537207176b.tar.gz
fixup: use teco_machine_t::must_undo instead of trying to identify the current state machine
* The previous solution was not wrong, but unnecessarily complex. We already have a flag for exactly this purpose. * Avoid redundancies by introducing teco_machine_stringbuilding_set_codepage().
Diffstat (limited to 'src')
-rw-r--r--src/core-commands.c7
-rw-r--r--src/parser.c13
-rw-r--r--src/parser.h13
-rw-r--r--src/qreg-commands.c11
-rw-r--r--src/search.c21
-rw-r--r--src/spawn.c8
6 files changed, 30 insertions, 43 deletions
diff --git a/src/core-commands.c b/src/core-commands.c
index befb6e8..0cde7e0 100644
--- a/src/core-commands.c
+++ b/src/core-commands.c
@@ -2759,12 +2759,9 @@ teco_state_insert_initial(teco_machine_main_t *ctx, GError **error)
/*
* Current document's encoding determines the behaviour of
* string building constructs.
- *
- * NOTE: This is not safe to undo in macro calls.
*/
- if (ctx == &teco_cmdline.machine)
- teco_undo_guint(ctx->expectstring.machine.codepage);
- ctx->expectstring.machine.codepage = teco_interface_get_codepage();
+ teco_machine_stringbuilding_set_codepage(&ctx->expectstring.machine,
+ teco_interface_get_codepage());
if (!teco_expressions_eval(FALSE, error))
return FALSE;
diff --git a/src/parser.c b/src/parser.c
index 4e42833..b1aa06e 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -35,7 +35,6 @@
#include "ring.h"
#include "glob.h"
#include "error.h"
-#include "cmdline.h"
#include "core-commands.h"
#include "goto-commands.h"
#include "parser.h"
@@ -907,15 +906,9 @@ teco_machine_stringbuilding_clear(teco_machine_stringbuilding_t *ctx)
gboolean
teco_state_expectstring_initial(teco_machine_main_t *ctx, GError **error)
{
- if (ctx->mode > TECO_MODE_NORMAL)
- return TRUE;
-
- /*
- * NOTE: This is not safe to undo in macro calls.
- */
- if (ctx == &teco_cmdline.machine)
- teco_undo_guint(ctx->expectstring.machine.codepage);
- ctx->expectstring.machine.codepage = teco_default_codepage();
+ if (ctx->mode == TECO_MODE_NORMAL)
+ teco_machine_stringbuilding_set_codepage(&ctx->expectstring.machine,
+ teco_default_codepage());
return TRUE;
}
diff --git a/src/parser.h b/src/parser.h
index 29b96b6..88de830 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -23,6 +23,7 @@
#include "sciteco.h"
#include "string-utils.h"
#include "goto.h"
+#include "undo.h"
#include "qreg.h"
/*
@@ -282,6 +283,8 @@ struct teco_machine_t {
* Whether side effects must be reverted on rubout.
* State machines created within macro calls don't have to
* even in interactive mode.
+ * In fact you MUST not revert side effects if this is FALSE
+ * as the data no longer exists on the call stack at undo-time.
*/
gboolean must_undo;
};
@@ -361,6 +364,16 @@ typedef struct teco_machine_stringbuilding_t {
void teco_machine_stringbuilding_init(teco_machine_stringbuilding_t *ctx, gunichar escape_char,
teco_qreg_table_t *locals, gboolean must_undo);
+static inline void
+teco_machine_stringbuilding_set_codepage(teco_machine_stringbuilding_t *ctx,
+ guint codepage)
+{
+ /* NOTE: This is not safe to undo in macro calls. */
+ if (ctx->parent.must_undo)
+ teco_undo_guint(ctx->codepage);
+ ctx->codepage = codepage;
+}
+
void teco_machine_stringbuilding_reset(teco_machine_stringbuilding_t *ctx);
/**
diff --git a/src/qreg-commands.c b/src/qreg-commands.c
index f8bb4cb..cff4c84 100644
--- a/src/qreg-commands.c
+++ b/src/qreg-commands.c
@@ -29,7 +29,6 @@
#include "interface.h"
#include "ring.h"
#include "parser.h"
-#include "cmdline.h"
#include "core-commands.h"
#include "qreg.h"
#include "qreg-commands.h"
@@ -493,12 +492,12 @@ teco_state_setqregstring_building_initial(teco_machine_main_t *ctx, GError **err
/*
* The expected codepage of string building constructs is determined
* by the Q-Register.
- *
- * NOTE: This is not safe to undo in macro calls.
*/
- if (ctx == &teco_cmdline.machine)
- teco_undo_guint(ctx->expectstring.machine.codepage);
- return qreg->vtable->get_string(qreg, NULL, NULL, &ctx->expectstring.machine.codepage, error);
+ guint codepage;
+ if (!qreg->vtable->get_string(qreg, NULL, NULL, &codepage, error))
+ return FALSE;
+ teco_machine_stringbuilding_set_codepage(&ctx->expectstring.machine, codepage);
+ return TRUE;
}
static teco_state_t *
diff --git a/src/search.c b/src/search.c
index 22dc726..0d04895 100644
--- a/src/search.c
+++ b/src/search.c
@@ -35,7 +35,6 @@
#include "parser.h"
#include "core-commands.h"
#include "error.h"
-#include "cmdline.h"
#include "search.h"
typedef struct {
@@ -61,12 +60,8 @@ teco_state_search_initial(teco_machine_main_t *ctx, GError **error)
if (ctx->mode > TECO_MODE_NORMAL)
return TRUE;
- /*
- * NOTE: This is not safe to undo in macro calls.
- */
- if (ctx == &teco_cmdline.machine)
- teco_undo_guint(ctx->expectstring.machine.codepage);
- ctx->expectstring.machine.codepage = teco_interface_get_codepage();
+ teco_machine_stringbuilding_set_codepage(&ctx->expectstring.machine,
+ teco_interface_get_codepage());
if (G_UNLIKELY(!teco_search_qreg_machine))
teco_search_qreg_machine = teco_machine_qregspec_new(TECO_QREG_REQUIRED, ctx->qreg_table_locals,
@@ -1052,15 +1047,9 @@ TECO_DEFINE_STATE_SEARCH(teco_state_search_delete);
static gboolean
teco_state_replace_insert_initial(teco_machine_main_t *ctx, GError **error)
{
- if (ctx->mode > TECO_MODE_NORMAL)
- return TRUE;
-
- /*
- * NOTE: This is not safe to undo in macro calls.
- */
- if (ctx == &teco_cmdline.machine)
- teco_undo_guint(ctx->expectstring.machine.codepage);
- ctx->expectstring.machine.codepage = teco_interface_get_codepage();
+ if (ctx->mode == TECO_MODE_NORMAL)
+ teco_machine_stringbuilding_set_codepage(&ctx->expectstring.machine,
+ teco_interface_get_codepage());
return TRUE;
}
diff --git a/src/spawn.c b/src/spawn.c
index cb1ef75..e6d620c 100644
--- a/src/spawn.c
+++ b/src/spawn.c
@@ -43,7 +43,6 @@
#include "core-commands.h"
#include "qreg-commands.h"
#include "error.h"
-#include "cmdline.h"
#include "spawn.h"
/*
@@ -168,12 +167,9 @@ teco_state_execute_initial(teco_machine_main_t *ctx, GError **error)
/*
* Command-lines and file names are always assumed to be UTF-8,
* unless we set TECO_ED_DEFAULT_ANSI.
- *
- * NOTE: This is not safe to undo in macro calls.
*/
- if (ctx == &teco_cmdline.machine)
- teco_undo_guint(ctx->expectstring.machine.codepage);
- ctx->expectstring.machine.codepage = teco_default_codepage();
+ teco_machine_stringbuilding_set_codepage(&ctx->expectstring.machine,
+ teco_default_codepage());
if (!teco_expressions_eval(FALSE, error))
return FALSE;