From 0ea082b74414696a7800455a437656fca2886f6d Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sat, 26 Jul 2025 16:30:17 +0300 Subject: properly document some functions in expressions.c and simplified code * Practically all calls to teco_expressions_args() must be preceded by teco_expressions_eval(). * In code paths where we know that teco_expressions_args() > 0, it is safe to call teco_expressions_pop_num(0) instead of teco_expressions_pop_num_calc(). This is both easier and faster. * teco_expressions_pop_num_calc() is for simple applications where you just want to get a command argument with default (implied) values. Since it includes teco_expressions_eval(), we can avoid superfluous calls. * -EC...$ turned out to be broken and is fixed now. A test case has been added. --- src/move-commands.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/move-commands.c') diff --git a/src/move-commands.c b/src/move-commands.c index 5c2159e..cf5d6b0 100644 --- a/src/move-commands.c +++ b/src/move-commands.c @@ -620,21 +620,16 @@ teco_state_start_delete_chars(teco_machine_main_t *ctx, GError **error) void teco_state_control_lines2glyphs(teco_machine_main_t *ctx, GError **error) { - if (!teco_expressions_eval(FALSE, error)) - return; - if (teco_machine_main_eval_colon(ctx)) { gssize pos; + if (!teco_expressions_eval(FALSE, error)) + return; + if (!teco_expressions_args()) { pos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); } else { - teco_int_t v; - - if (!teco_expressions_pop_num_calc(&v, 0, error)) - return; - - pos = teco_interface_glyphs2bytes(v); + pos = teco_interface_glyphs2bytes(teco_expressions_pop_num(0)); if (pos < 0) { teco_error_range_set(error, "^Q"); return; -- cgit v1.2.3