aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2024-10-18 14:28:08 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-10-18 14:40:13 +0300
commit8fedd523deb07a33fc6ef786d57fd904ffecc8f5 (patch)
tree07cf57385ffc3f06fb328a2e9b827813773a6fb3
parent70019f624a8d188cf30dcc8b1eb9440a6cffb49c (diff)
downloadsciteco-8fedd523deb07a33fc6ef786d57fd904ffecc8f5.tar.gz
fixed the "Editing local registers in macro calls" check
* The previous check could result in false positives if you are editing a local Q-Register, that will be destroyed at the end of the current macro frame, and call another non-colon modified macro. * It must instead be invalid to keep the register edited only if it belongs to the local Q-Registers that are about to be freed. In other words, the table that the currently edited Q-Register belongs to, must be the one we're about to destroy. * This fixes the solarized.toggle (F5) macro when using the Solarized color scheme.
-rw-r--r--src/qreg-commands.c4
-rw-r--r--src/qreg.c6
-rw-r--r--src/qreg.h6
-rw-r--r--src/ring.c2
-rw-r--r--tests/testsuite.at1
5 files changed, 13 insertions, 6 deletions
diff --git a/src/qreg-commands.c b/src/qreg-commands.c
index cff4c84..5b80d15 100644
--- a/src/qreg-commands.c
+++ b/src/qreg-commands.c
@@ -658,8 +658,8 @@ teco_state_macro_got_register(teco_machine_main_t *ctx, teco_qreg_t *qreg,
if (!teco_qreg_execute(qreg, &table, error))
return NULL;
- if (teco_qreg_current && !teco_qreg_current->must_undo) {
- /* currently editing local Q-Register */
+ if (teco_qreg_table_current == &table) {
+ /* currently editing local Q-Register that's about to be freed */
teco_error_editinglocalqreg_set(error, teco_qreg_current->head.name.data,
teco_qreg_current->head.name.len);
return NULL;
diff --git a/src/qreg.c b/src/qreg.c
index c337dbe..a0e5415 100644
--- a/src/qreg.c
+++ b/src/qreg.c
@@ -47,6 +47,8 @@
* Initialized in main.c after the interface.
*/
teco_view_t *teco_qreg_view = NULL;
+/** Table of currently edited Q-Register */
+const teco_qreg_table_t *teco_qreg_table_current = NULL;
/** Currently edited Q-Register */
teco_qreg_t *teco_qreg_current = NULL;
@@ -1234,8 +1236,8 @@ teco_ed_hook(teco_ed_hook_t type, GError **error)
if (!teco_qreg_execute(qreg, &locals, error))
goto error_add_frame;
- if (teco_qreg_current && !teco_qreg_current->must_undo) {
- /* currently editing local Q-Register */
+ if (teco_qreg_table_current == &locals) {
+ /* currently editing local Q-Register that's about to be freed */
teco_error_editinglocalqreg_set(error, teco_qreg_current->head.name.data,
teco_qreg_current->head.name.len);
goto error_add_frame;
diff --git a/src/qreg.h b/src/qreg.h
index 85da898..f5866e7 100644
--- a/src/qreg.h
+++ b/src/qreg.h
@@ -93,11 +93,11 @@ struct teco_qreg_t {
teco_int_t integer;
teco_doc_t string;
- /*
+ /**
* Whether to generate undo tokens (unnecessary for registers
* in local qreg tables in macro invocations).
*
- * FIXME: Every QRegister has this field, but it only differs
+ * @fixme Every QRegister has this field, but it only differs
* between local and global QRegisters. This wastes space.
* Or by deferring any decision about undo token creation to a layer
* that knows which table it is accessing.
@@ -129,6 +129,7 @@ teco_qreg_free(teco_qreg_t *qreg)
g_free(qreg);
}
+extern const teco_qreg_table_t *teco_qreg_table_current;
extern teco_qreg_t *teco_qreg_current;
/** @extends teco_rb3str_tree_t */
@@ -170,6 +171,7 @@ teco_qreg_table_edit(teco_qreg_table_t *table, teco_qreg_t *qreg, GError **error
{
if (!qreg->vtable->edit(qreg, error))
return FALSE;
+ teco_qreg_table_current = table;
teco_qreg_current = qreg;
return TRUE;
}
diff --git a/src/ring.c b/src/ring.c
index 6a4eae5..d6fadda 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -264,6 +264,7 @@ teco_ring_edit_by_name(const gchar *filename, GError **error)
{
teco_buffer_t *buffer = teco_ring_find(filename);
+ teco_qreg_table_current = NULL;
teco_qreg_current = NULL;
if (buffer) {
teco_ring_current = buffer;
@@ -310,6 +311,7 @@ teco_ring_edit_by_id(teco_int_t id, GError **error)
return FALSE;
}
+ teco_qreg_table_current = NULL;
teco_qreg_current = NULL;
teco_ring_current = buffer;
teco_buffer_edit(buffer);
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 676ca59..7769cb7 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -97,6 +97,7 @@ AT_CLEANUP
AT_SETUP([Editing local registers in macro calls])
AT_CHECK([$SCITECO -e '@^Ua{@EQ.x//} :Ma @^U.x/FOO/'], 0, ignore, ignore)
AT_CHECK([$SCITECO -e '@^Ua{@EQ.x//} Ma @^U.x/FOO/'], 1, ignore, ignore)
+AT_CHECK([$SCITECO -e '@^Ua{@EQ.x// Mb Q*U*} Ma'], 0, ignore, ignore)
AT_CLEANUP
AT_SETUP([Loading files into Q-Registers])