From e82dc6639e829490cb11267fa4a49ef97c6459ae Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sat, 30 Aug 2025 20:38:57 +0300 Subject: the computed go-to command (O) is now 0-indexed and all invalid indexes and empty labels are ignored * This has long been a TECO-11 incompatibility. * The first label in a list has index 0, i.e. `1Ofoo,bar$` jumps to label `!bar!`. Consequently 0 is also implied, so `Olabel$` continues to do what you expect. * `0Ofoo$` was previously also jumping to `!foo!` which was inconsistent: All invalid indexes should do nothing, i.e. execution continues after the go-to command. * Fixed handling of empty labels as in `1Ofoo,,bar$` - execution should also continue after the command. This eases writing "default" clauses immediately after the go-to. * The ED hook values now also begin at 0, so most existing ED hook macros should continue to work. * Similarily, the mouse events returned by -EJ also begin at 0 now, so fnkeys.tes continues to work as expected. * It's still very possible of course that this breaks existing code. --- src/core-commands.c | 8 ++++---- src/goto-commands.c | 31 +++++++++++++++++++++++-------- src/interface.h | 2 +- src/qreg.c | 8 ++++---- src/qreg.h | 2 +- 5 files changed, 33 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/core-commands.c b/src/core-commands.c index 6d0a3dc..5fe960b 100644 --- a/src/core-commands.c +++ b/src/core-commands.c @@ -2142,13 +2142,13 @@ teco_state_ecommand_flags(teco_machine_main_t *ctx, GError **error) * Type of the last mouse event (\fBread-only\fP). * One of the following values will be returned: * .RS - * . IP 1: 4 + * . IP 0: 4 * Some button has been pressed - * . IP 2: + * . IP 1: * Some button has been released - * . IP 3: + * . IP 2: * Scroll up - * . IP 4: + * . IP 3: * Scroll down * .RE * .IP -2: diff --git a/src/goto-commands.c b/src/goto-commands.c index d95886d..ac98b70 100644 --- a/src/goto-commands.c +++ b/src/goto-commands.c @@ -24,6 +24,7 @@ #include #include "sciteco.h" +#include "error.h" #include "string-utils.h" #include "expressions.h" #include "parser.h" @@ -110,15 +111,22 @@ teco_state_goto_done(teco_machine_main_t *ctx, const teco_string_t *str, GError if (ctx->flags.mode > TECO_MODE_NORMAL) return &teco_state_start; + if (!str->len) { + /* you can still write @O/,/, though... */ + g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED, + "No labels given for "); + return NULL; + } + teco_int_t value; - if (!teco_expressions_pop_num_calc(&value, 1, error)) + if (!teco_expressions_pop_num_calc(&value, 0, error)) return NULL; /* * Find the comma-separated substring in str indexed by `value`. */ teco_string_t label = {NULL, 0}; - while (value > 0) { + while (value >= 0) { label.data = label.data ? label.data+label.len+1 : str->data; const gchar *p = label.data ? memchr(label.data, ',', str->len - (label.data - str->data)) : NULL; label.len = p ? p - label.data : str->len - (label.data - str->data); @@ -129,7 +137,7 @@ teco_state_goto_done(teco_machine_main_t *ctx, const teco_string_t *str, GError break; } - if (value == 0) { + if (value < 0 && label.len > 0) { gssize pc = teco_goto_table_find(&ctx->goto_table, label.data, label.len); if (pc >= 0) { @@ -156,19 +164,22 @@ gboolean teco_state_goto_insert_completion(teco_machine_main_t *ctx, const teco_ /*$ "O" goto * Olabel$ -- Go to label - * [n]Olabel1[,label2,...]$ + * [n]Olabel0[,label1,...]$ * * Go to