diff options
| author | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-11-22 16:53:08 +0100 |
|---|---|---|
| committer | Robin Haberkorn <rhaberkorn@fmsbw.de> | 2026-11-22 19:51:04 +0100 |
| commit | 910d8a61772570198eb12f752c5b7f8fcd006dc2 (patch) | |
| tree | 13fcd9805c3a82e8b39691a1e6b5d2e81662f784 /src/ring.c | |
| parent | b283996b6ecffc3a1d05c52df02c89ec86cafa96 (diff) | |
implemented the FQq (free Q-register) command and extended EF
Since Q-registers can be dynamically allocated, we must have
a command for freeing them as well. This is especially important
when using long Q-register names to implement arrays and other complex
data structures. To ease freeing entire arrays, the :FQ[array.]
modification can be used -- this will free all registers with the given
prefix efficiently.
There is currently no variant that tells you whether the register
actually existed -- you can first check with :Qq if that is important.
EF has also been extended to free the currently edited register -
which is also what Video TECO appeared to do.
If the currently edited register is freed, we edit the current
buffer again.
Diffstat (limited to 'src/ring.c')
| -rw-r--r-- | src/ring.c | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -794,7 +794,7 @@ TECO_DEFINE_STATE_EXPECTFILE(teco_state_read_file, ); /*$ "EF" ":EF" close - * [n]EF -- Remove buffer from ring + * [n]EF -- Remove buffer from ring or free current Q-register * -EF * [n]:EF * @@ -802,6 +802,8 @@ TECO_DEFINE_STATE_EXPECTFILE(teco_state_read_file, * closing it. * The optional argument <n> specifies the id of the buffer * to close -- by default the current buffer will be closed. + * If <n> is omitted and you are currently editing a Q-register, + * this register <q> will be freed as by \fBFQ\fIq\fR. * If the selected buffer is dirty (modified), \fBEF\fP will yield * an error. * If <n> is negative (success boolean), buffer <-n> will be closed @@ -828,6 +830,8 @@ teco_state_ecommand_close(teco_machine_main_t *ctx, GError **error) if (!teco_expressions_eval(FALSE, error)) return; + gboolean colon_modified = teco_machine_main_eval_colon(ctx) > 0; + /* * This is like implying teco_num_sign*teco_ring_get_id(teco_ring_current) * but avoids the O(n) ring iterations. @@ -843,13 +847,7 @@ teco_state_ecommand_close(teco_machine_main_t *ctx, GError **error) } force = id < 0; } else if (teco_qreg_current) { - /* - * TODO: Should perhaps remove the register like FQq. - */ - const teco_string_t *name = &teco_qreg_current->head.name; - g_autofree gchar *name_printable = teco_string_echo(name->data, name->len); - g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Q-Register \"%s\" currently edited", name_printable); + teco_qreg_table_remove(teco_qreg_table_current, teco_qreg_current, error); return; } else { buffer = teco_ring_current; @@ -857,7 +855,7 @@ teco_state_ecommand_close(teco_machine_main_t *ctx, GError **error) teco_set_num_sign(1); } - if (teco_machine_main_eval_colon(ctx) > 0) { + if (colon_modified) { if (!teco_buffer_save(buffer, NULL, error)) return; } else if (!force && buffer->state > TECO_BUFFER_CLEAN) { |
