From ab35f6618bc8beb4543cbc7c62332f82d7d5699c Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sat, 22 Mar 2025 15:19:53 +0300 Subject: added `P` command as a reverse form of `W` * All the movement commands have shortcuts for their negative forms: `R` instead of `-C`, `B` instead of `-L`. Therefore there was always the need for a `-W` shortcut as well. * `P` is a good choice because it is a file IO command in TECO-11, that does not make sense supporting. In Video TECO it toggles between display windows (ie. split screens) and I do not plan to support multiple windows in SciTECO. * Added to the cheat sheet. --- src/move-commands.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'src/move-commands.c') diff --git a/src/move-commands.c b/src/move-commands.c index 8abd8ca..5339f24 100644 --- a/src/move-commands.c +++ b/src/move-commands.c @@ -316,7 +316,7 @@ teco_find_words(gsize *pos, teco_int_t n) } /*$ W word - * [n]W -- Move dot by words + * [n]W -- Move dot words forwards * -W * [n]:W -> Success|Failure * @@ -337,7 +337,7 @@ teco_find_words(gsize *pos, teco_int_t n) * If colon-modified it instead returns a condition code. */ void -teco_state_start_word(teco_machine_main_t *ctx, GError **error) +teco_state_start_words(teco_machine_main_t *ctx, GError **error) { teco_int_t v; if (!teco_expressions_pop_num_calc(&v, teco_num_sign, error)) @@ -360,6 +360,38 @@ teco_state_start_word(teco_machine_main_t *ctx, GError **error) teco_expressions_push(TECO_SUCCESS); } +/*$ P + * [n]P -- Move dot words backwards + * -P + * [n]:P -> Success|Failure + * + * Move dot to the beginning of preceding words. + * It is equivalent to \(lq-nW\(rq. + */ +void +teco_state_start_words_back(teco_machine_main_t *ctx, GError **error) +{ + teco_int_t v; + if (!teco_expressions_pop_num_calc(&v, teco_num_sign, error)) + return; + sptr_t pos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); + + gsize word_pos = pos; + if (!teco_find_words(&word_pos, -v)) { + if (!teco_machine_main_eval_colon(ctx)) + teco_error_move_set(error, "P"); + else + teco_expressions_push(TECO_FAILURE); + return; + } + + if (teco_current_doc_must_undo()) + undo__teco_interface_ssm(SCI_GOTOPOS, pos, 0); + teco_interface_ssm(SCI_GOTOPOS, word_pos, 0); + if (teco_machine_main_eval_colon(ctx) > 0) + teco_expressions_push(TECO_SUCCESS); +} + static gboolean teco_delete_words(teco_int_t n) { -- cgit v1.2.3