diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-11-22 16:59:07 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-11-23 02:33:49 +0300 |
commit | 1cfe37610253c20a4fcb0d937c29e70894ecc4f5 (patch) | |
tree | ac05844c25fc0918e8fd451d8912fd7f1964acb7 /src/qreg.c | |
parent | 07b52f78680858683acb4e40b158f8926285cae4 (diff) | |
download | sciteco-1cfe37610253c20a4fcb0d937c29e70894ecc4f5.tar.gz |
the search mode and current radix are mapped to __local__ Q-Registers ^X and ^R now (refs #17)
* This way the search mode and radix are local to the current macro frame,
unless the macro was invoked with :Mq.
If colon-modified, you can reproduce the same effect by calling
[.^X 0^X ... ].^X
* The radix register is cached in the Q-Reg table as an optimization.
This could be done with the other "special" registers as well, but at the
cost of larger stack frames.
* In order to allow constructs like [.^X typed with upcarets,
the Q-Register specification syntax has been extended:
^c is the corresponding control code instead of the register "^".
Diffstat (limited to 'src/qreg.c')
-rw-r--r-- | src/qreg.c | 43 |
1 files changed, 39 insertions, 4 deletions
@@ -893,6 +893,7 @@ teco_qreg_clipboard_new(const gchar *name) void teco_qreg_table_init(teco_qreg_table_t *table, gboolean must_undo) { + memset(table, 0, sizeof(*table)); rb3_reset_tree(&table->tree); table->must_undo = must_undo; @@ -903,6 +904,20 @@ teco_qreg_table_init(teco_qreg_table_t *table, gboolean must_undo) teco_qreg_table_insert(table, teco_qreg_plain_new(&q, sizeof(q))); } +/** @memberof teco_qreg_table_t */ +void +teco_qreg_table_init_locals(teco_qreg_table_t *table, gboolean must_undo) +{ + teco_qreg_table_init(table, must_undo); + + /* search mode ("^X") */ + teco_qreg_table_insert(table, teco_qreg_plain_new("\x18", 1)); + /* numeric radix ("^R") */ + table->radix = teco_qreg_plain_new("\x12", 1); + table->radix->vtable->set_integer(table->radix, 10, NULL); + teco_qreg_table_insert(table, table->radix); +} + static inline void teco_qreg_table_remove(teco_qreg_t *reg) { @@ -1208,7 +1223,7 @@ teco_ed_hook(teco_ed_hook_t type, GError **error) * since it runs all destructors. */ g_auto(teco_qreg_table_t) locals; - teco_qreg_table_init(&locals, FALSE); + teco_qreg_table_init_locals(&locals, FALSE); teco_qreg_t *qreg = teco_qreg_table_find(&teco_qreg_table_globals, "ED", 2); if (!qreg) { @@ -1297,6 +1312,7 @@ struct teco_machine_qregspec_t { */ TECO_DECLARE_STATE(teco_state_qregspec_start); TECO_DECLARE_STATE(teco_state_qregspec_start_global); +TECO_DECLARE_STATE(teco_state_qregspec_caret); TECO_DECLARE_STATE(teco_state_qregspec_firstchar); TECO_DECLARE_STATE(teco_state_qregspec_secondchar); TECO_DECLARE_STATE(teco_state_qregspec_string); @@ -1364,10 +1380,10 @@ TECO_DEFINE_STATE(teco_state_qregspec_start, static teco_state_t * teco_state_qregspec_start_global_input(teco_machine_qregspec_t *ctx, gunichar chr, GError **error) { - /* - * FIXME: Disallow space characters? - */ switch (chr) { + case '^': + return &teco_state_qregspec_caret; + case '#': return &teco_state_qregspec_firstchar; @@ -1397,6 +1413,25 @@ TECO_DEFINE_STATE(teco_state_qregspec_start_global, ); static teco_state_t * +teco_state_qregspec_caret_input(teco_machine_qregspec_t *ctx, gunichar chr, GError **error) +{ + chr = teco_ascii_toupper(chr); + if (chr < '@' || chr > '_') { + teco_error_syntax_set(error, chr); + return NULL; + } + + if (!ctx->parse_only) { + if (ctx->parent.must_undo) + undo__teco_string_truncate(&ctx->name, ctx->name.len); + teco_string_append_wc(&ctx->name, TECO_CTL_KEY(chr)); + } + return teco_state_qregspec_done(ctx, error); +} + +TECO_DEFINE_STATE_CASEINSENSITIVE(teco_state_qregspec_caret); + +static teco_state_t * teco_state_qregspec_firstchar_input(teco_machine_qregspec_t *ctx, gunichar chr, GError **error) { /* |