diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-12-04 16:43:51 +0300 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2024-12-04 16:43:51 +0300 |
commit | 48308687979f26a3498e7af94eacc8fe34307a78 (patch) | |
tree | afc05823788bc2985f29e33c667e631be2554cad /src/qreg-commands.c | |
parent | 3a823fb43ba0abe52f3152d337675e9ed9a3f175 (diff) | |
download | sciteco-48308687979f26a3498e7af94eacc8fe34307a78.tar.gz |
the <Xq> 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 <K> 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.
Diffstat (limited to 'src/qreg-commands.c')
-rw-r--r-- | src/qreg-commands.c | 45 |
1 files changed, 42 insertions, 3 deletions
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 <lines> from the buffer * into the Q-Register <q> 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 <from> up to the character at position <to> * 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 <q> 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 <q> will be created if it is undefined. */ |