From 48308687979f26a3498e7af94eacc8fe34307a78 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Wed, 4 Dec 2024 16:43:51 +0300 Subject: the command now supports the @ modifier for cutting into the register * Can be freely combined with the colon-modifier as well. :@Xq cut-appends to register q. * This simply deletes the given buffer range after the copy or append operation as if followed by another command. * This has indeed been a very annoying missing feature, as you often have to retype the range for a K or D command. At the same time, this cannot be reasonably solved with a macro since macros do not accept Q-Register arguments -- so we would have to restrict ourselves to one or a few selected registers. I was also considering to solve this with a special stack operation that duplicates the top values, so that Xq leaves arguments for K, but this couldn't work for cutting lines and would also be longer to type. * It's the first non-string command that accepts @. Others may follow in the future. We're approaching ITS TECO madness levels. --- src/qreg-commands.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'src/qreg-commands.c') diff --git a/src/qreg-commands.c b/src/qreg-commands.c index 9f22de9..c36a6b7 100644 --- a/src/qreg-commands.c +++ b/src/qreg-commands.c @@ -746,6 +746,14 @@ teco_state_copytoqreg_got_register(teco_machine_main_t *ctx, teco_qreg_t *qreg, { teco_state_expectqreg_reset(ctx); + /* + * NOTE: "@" has syntactic significance in most contexts, so it's set + * in parse-only mode. + * Therefore, it must also be evaluated in parse-only mode, even though + * it has no syntactic significance for Xq. + */ + gboolean modifier_at = teco_machine_main_eval_at(ctx); + if (ctx->mode > TECO_MODE_NORMAL) return &teco_state_start; @@ -806,16 +814,42 @@ teco_state_copytoqreg_got_register(teco_machine_main_t *ctx, teco_qreg_t *qreg, return NULL; } + if (!modifier_at || len == 0) + return &teco_state_start; + + /* + * If @-modified, cut into the register + */ + if (teco_current_doc_must_undo()) { + sptr_t pos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); + undo__teco_interface_ssm(SCI_GOTOPOS, pos, 0); + undo__teco_interface_ssm(SCI_UNDO, 0, 0); + } + + /* + * Should always generate an undo action. + */ + teco_interface_ssm(SCI_BEGINUNDOACTION, 0, 0); + teco_interface_ssm(SCI_DELETERANGE, from, len); + teco_interface_ssm(SCI_ENDUNDOACTION, 0, 0); + teco_ring_dirtify(); + return &teco_state_start; } /*$ X Xq - * [lines]Xq -- Copy into or append to Q-Register + * [lines]Xq -- Copy into or append or cut to Q-Register * -Xq * from,toXq * [lines]:Xq * -:Xq * from,to:Xq + * [lines]@Xq + * -@Xq + * from,to@Xq + * [lines]:@Xq + * -:@Xq + * from,to:@Xq * * Copy the next or previous number of from the buffer * into the Q-Register string. @@ -823,10 +857,15 @@ teco_state_copytoqreg_got_register(teco_machine_main_t *ctx, teco_qreg_t *qreg, * If two arguments are specified, the characters beginning * at position up to the character at position * are copied. - * The semantics of the arguments is analogous to the K + * The semantics of the arguments is analogous to the \fBK\fP * command's arguments. - * If the command is colon-modified, the characters will be + * + * If the command is colon-modified (\fB:\fP), the characters will be * appended to the end of register instead. + * If the command is at-modified (\fB@\fP), the text will be + * removed from the buffer after copying or appending to the + * Q-Register, thus performing a cut operation. + * The order of modifiers is as always insignificant. * * Register will be created if it is undefined. */ -- cgit v1.2.3