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. --- doc/cheat-sheet.mm | 13 ++++++++++--- src/core-commands.c | 3 ++- src/move-commands.c | 36 ++++++++++++++++++++++++++++++++++-- src/move-commands.h | 3 ++- tests/testsuite.at | 3 +-- 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/doc/cheat-sheet.mm b/doc/cheat-sheet.mm index ab404e3..60104ff 100644 --- a/doc/cheat-sheet.mm +++ b/doc/cheat-sheet.mm @@ -419,12 +419,12 @@ Read \fIfile\fP into Q-Register \fIq\fP. . TD . CI C . TD -Move one character forward. +Move to next character. . TRX . TD . CI "" n C . TD -Move \fIn\fP characters forward. +Move \fIn\fP characters forwards. . TRX . TD . CI R @@ -439,17 +439,24 @@ Move \fIn\fP characters backwards (reverse). . TD . CI W . TD -Move to the beginning of next word. +Move to next word. +. TRX +. TD +. CI P +. TD +Move to previous word. . TRX . TD . CI L . TD Move to the beginning of next line. +.ig END . TRX . TD . CI "" n L . TD Move forward \fIn\fP lines. +.END . TRX . TD . CI 0L diff --git a/src/core-commands.c b/src/core-commands.c index f39f6f9..4abf38b 100644 --- a/src/core-commands.c +++ b/src/core-commands.c @@ -659,7 +659,8 @@ teco_state_start_input(teco_machine_main_t *ctx, gunichar chr, GError **error) ['R'] = {&teco_state_start, teco_state_start_reverse}, ['L'] = {&teco_state_start, teco_state_start_line}, ['B'] = {&teco_state_start, teco_state_start_back}, - ['W'] = {&teco_state_start, teco_state_start_word}, + ['W'] = {&teco_state_start, teco_state_start_words}, + ['P'] = {&teco_state_start, teco_state_start_words_back}, ['V'] = {&teco_state_start, teco_state_start_delete_words}, ['Y'] = {&teco_state_start, teco_state_start_delete_words_back}, ['='] = {&teco_state_start, teco_state_start_print}, 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) { diff --git a/src/move-commands.h b/src/move-commands.h index 36acec8..9dddc8d 100644 --- a/src/move-commands.h +++ b/src/move-commands.h @@ -28,7 +28,8 @@ void teco_state_start_reverse(teco_machine_main_t *ctx, GError **error); void teco_state_start_line(teco_machine_main_t *ctx, GError **error); void teco_state_start_back(teco_machine_main_t *ctx, GError **error); -void teco_state_start_word(teco_machine_main_t *ctx, GError **error); +void teco_state_start_words(teco_machine_main_t *ctx, GError **error); +void teco_state_start_words_back(teco_machine_main_t *ctx, GError **error); void teco_state_start_delete_words(teco_machine_main_t *ctx, GError **error); void teco_state_start_delete_words_back(teco_machine_main_t *ctx, GError **error); diff --git a/tests/testsuite.at b/tests/testsuite.at index c76c4c5..7c3cf97 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -116,8 +116,7 @@ AT_CLEANUP AT_SETUP([Moving by words]) AT_CHECK([$SCITECO -e "Z= 3J 2W .-18\"N(0/0)'" "$WORDS_EXAMPLE"], 0, ignore, ignore) AT_CHECK([$SCITECO -e "@I/foo ^J bar/ JW .-6\"N(0/0)'"], 0, ignore, ignore) -# FIXME: Sooner or later, there will be a shortcut for -W. -AT_CHECK([$SCITECO -e "Z-4J -3W .-12\"N(0/0)'" "$WORDS_EXAMPLE"], 0, ignore, ignore) +AT_CHECK([$SCITECO -e "Z-4J 3P .-12\"N(0/0)'" "$WORDS_EXAMPLE"], 0, ignore, ignore) AT_CLEANUP AT_SETUP([Deleting words]) -- cgit v1.2.3