aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core-commands.h
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2024-12-04 02:22:36 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-12-04 11:43:18 +0300
commit3a823fb43ba0abe52f3152d337675e9ed9a3f175 (patch)
treef63143368fe15b4fbf88f9646a0a913eb46717fd /src/core-commands.h
parent11054d94a99e8c11d6010b117c84ee88b4fa1a73 (diff)
downloadsciteco-3a823fb43ba0abe52f3152d337675e9ed9a3f175.tar.gz
implemented ^Y/^S commands for receiving pattern match/insertion ranges and lengths (refs #27)
* Allows storing pattern matches into Q-Registers (^YXq). * You can also refer to subpatterns marked by ^E[...] by passing a number > 0. This is equivalent to \0-9 references in many programming languages. * It's especially useful for supporting TECO's equivalent of structural regular expressions. This will be done with additional macros. * You can also simply back up to the beginning of an insertion or search. So I...$^SC leaves dot at the beginning of the insertion. S...$^SC leaves dot before the found pattern. This has been previously requested by users. * Perhaps there should be ^Y string building characters as well to backreference in search-replacement commands (TODO). This means that the search commands would have to store the matched text itself in teco_range_t structures since FR deletes the matched text before processing the replacement string. It could also be made into a FR/FS-specific construct, so we don't fetch the substrings unnecessarily. * This differs from DEC TECO in always returning the same range even after dot movements, since we are storing start/end byte positions instead of only the length. Also DEC TECO does not support fetching subpattern ranges.
Diffstat (limited to 'src/core-commands.h')
-rw-r--r--src/core-commands.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/core-commands.h b/src/core-commands.h
index e30770d..fbb67fa 100644
--- a/src/core-commands.h
+++ b/src/core-commands.h
@@ -38,9 +38,18 @@ TECO_DECLARE_STATE(teco_state_ascii);
TECO_DECLARE_STATE(teco_state_escape);
TECO_DECLARE_STATE(teco_state_ecommand);
+typedef struct {
+ gsize from; /*< start position in bytes */
+ gsize to; /*< end position in bytes */
+} teco_range_t;
+
+extern guint teco_ranges_count;
+extern teco_range_t *teco_ranges;
+
gboolean teco_state_insert_initial(teco_machine_main_t *ctx, GError **error);
gboolean teco_state_insert_process(teco_machine_main_t *ctx, const teco_string_t *str,
gsize new_chars, GError **error);
+teco_state_t *teco_state_insert_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error);
/* in cmdline.c */
gboolean teco_state_insert_process_edit_cmd(teco_machine_main_t *ctx, teco_machine_t *parent_ctx, gunichar chr, GError **error);
@@ -57,7 +66,7 @@ gboolean teco_state_insert_process_edit_cmd(teco_machine_main_t *ctx, teco_machi
static teco_state_t * \
NAME##_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error) \
{ \
- return &teco_state_start; /* nothing to be done when done */ \
+ return teco_state_insert_done(ctx, str, error); \
} \
TECO_DEFINE_STATE_EXPECTSTRING(NAME, \
.initial_cb = (teco_state_initial_cb_t)teco_state_insert_initial, \