aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/goto-commands.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/goto-commands.c')
-rw-r--r--src/goto-commands.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/goto-commands.c b/src/goto-commands.c
index 2035277..99288c1 100644
--- a/src/goto-commands.c
+++ b/src/goto-commands.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012-2024 Robin Haberkorn
+ * Copyright (C) 2012-2025 Robin Haberkorn
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -30,6 +30,7 @@
#include "lexer.h"
#include "core-commands.h"
#include "undo.h"
+#include "interface.h"
#include "goto.h"
#include "goto-commands.h"
@@ -62,15 +63,20 @@ teco_state_label_input(teco_machine_main_t *ctx, gunichar chr, GError **error)
}
if (chr == '!') {
- /*
- * NOTE: If the label already existed, its PC will be restored
- * on rubout.
- * Otherwise, the label will be removed (PC == -1).
- */
gssize existing_pc = teco_goto_table_set(&ctx->goto_table, ctx->goto_label.data,
ctx->goto_label.len, ctx->macro_pc);
+ if (existing_pc == ctx->macro_pc)
+ /* encountered the same label again */
+ return &teco_state_start;
+ if (existing_pc >= 0) {
+ g_autofree gchar *label_printable = teco_string_echo(ctx->goto_label.data,
+ ctx->goto_label.len);
+ teco_interface_msg(TECO_MSG_WARNING, "Ignoring goto label \"%s\" redefinition",
+ label_printable);
+ return &teco_state_start;
+ }
if (ctx->parent.must_undo)
- teco_goto_table_undo_set(&ctx->goto_table, ctx->goto_label.data, ctx->goto_label.len, existing_pc);
+ teco_goto_table_undo_remove(&ctx->goto_table, ctx->goto_label.data, ctx->goto_label.len);
if (teco_goto_skip_label.len > 0 &&
!teco_string_cmp(&ctx->goto_label, teco_goto_skip_label.data, teco_goto_skip_label.len)) {
@@ -151,7 +157,10 @@ teco_state_goto_done(teco_machine_main_t *ctx, const teco_string_t *str, GError
}
/* in cmdline.c */
-gboolean teco_state_goto_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *parent_ctx, gunichar chr, GError **error);
+gboolean teco_state_goto_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *parent_ctx,
+ gunichar chr, GError **error);
+gboolean teco_state_goto_insert_completion(teco_machine_main_t *ctx, const teco_string_t *str,
+ GError **error);
/*$ O
* Olabel$ -- Go to label
@@ -180,7 +189,8 @@ gboolean teco_state_goto_process_edit_cmd(teco_machine_main_t *ctx, teco_machine
* terminate the command-line.
*/
TECO_DEFINE_STATE_EXPECTSTRING(teco_state_goto,
- .process_edit_cmd_cb = (teco_state_process_edit_cmd_cb_t)teco_state_goto_process_edit_cmd
+ .process_edit_cmd_cb = (teco_state_process_edit_cmd_cb_t)teco_state_goto_process_edit_cmd,
+ .insert_completion_cb = (teco_state_insert_completion_cb_t)teco_state_goto_insert_completion
);
/*