aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core-commands.c4
-rw-r--r--src/parser.c20
-rw-r--r--src/parser.h1
-rw-r--r--src/qreg-commands.c45
4 files changed, 61 insertions, 9 deletions
diff --git a/src/core-commands.c b/src/core-commands.c
index 752a8e8..4523923 100644
--- a/src/core-commands.c
+++ b/src/core-commands.c
@@ -1253,7 +1253,9 @@ teco_state_start_input(teco_machine_main_t *ctx, gunichar chr, GError **error)
case '@':
/*
* @ modifier has syntactic significance, so set it even
- * in PARSE_ONLY* modes
+ * in PARSE_ONLY* modes.
+ * Unfortunately, it means that it must be evaluated and cleared
+ * everywhere, even where it has no syntactic significance.
*/
if (ctx->parent.must_undo)
teco_undo_guint(ctx->__flags);
diff --git a/src/parser.c b/src/parser.c
index 729fe42..e1bf576 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -332,6 +332,18 @@ teco_machine_main_eval_colon(teco_machine_main_t *ctx)
return TRUE;
}
+gboolean
+teco_machine_main_eval_at(teco_machine_main_t *ctx)
+{
+ if (!ctx->modifier_at)
+ return FALSE;
+
+ if (ctx->parent.must_undo)
+ teco_undo_guint(ctx->__flags);
+ ctx->modifier_at = FALSE;
+ return TRUE;
+}
+
teco_state_t *
teco_machine_main_transition_input(teco_machine_main_t *ctx,
teco_machine_main_transition_t *transitions,
@@ -935,11 +947,9 @@ teco_state_expectstring_input(teco_machine_main_t *ctx, gunichar chr, GError **e
* String termination handling
*/
if (ctx->modifier_at) {
- if (current->expectstring.last) {
- if (ctx->parent.must_undo)
- teco_undo_guint(ctx->__flags);
- ctx->modifier_at = FALSE;
- }
+ if (current->expectstring.last)
+ /* also clears the "@" modifier flag */
+ teco_machine_main_eval_at(ctx);
/*
* FIXME: Exclude setting at least whitespace characters as the
diff --git a/src/parser.h b/src/parser.h
index 3d69013..1127dcd 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -504,6 +504,7 @@ void teco_machine_main_init(teco_machine_main_t *ctx,
gboolean must_undo);
gboolean teco_machine_main_eval_colon(teco_machine_main_t *ctx);
+gboolean teco_machine_main_eval_at(teco_machine_main_t *ctx);
gboolean teco_machine_main_step(teco_machine_main_t *ctx,
const gchar *macro, gsize stop_pos, GError **error);
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.
*/