diff options
-rw-r--r-- | src/core-commands.c | 3 | ||||
-rw-r--r-- | src/qreg-commands.c | 17 | ||||
-rw-r--r-- | tests/testsuite.at | 1 |
3 files changed, 17 insertions, 4 deletions
diff --git a/src/core-commands.c b/src/core-commands.c index 8e31ae3..ae51ecc 100644 --- a/src/core-commands.c +++ b/src/core-commands.c @@ -639,7 +639,8 @@ teco_state_start_input(teco_machine_main_t *ctx, gunichar chr, GError **error) .modifier_at = TRUE, .modifier_colon = 1}, ['['] = {&teco_state_pushqreg}, - [']'] = {&teco_state_popqreg}, + [']'] = {&teco_state_popqreg, + .modifier_colon = 1}, ['G'] = {&teco_state_getqregstring}, ['Q'] = {&teco_state_queryqreg, .modifier_colon = 1}, diff --git a/src/qreg-commands.c b/src/qreg-commands.c index 9407e6c..1d2766f 100644 --- a/src/qreg-commands.c +++ b/src/qreg-commands.c @@ -99,18 +99,29 @@ teco_state_popqreg_got_register(teco_machine_main_t *ctx, teco_qreg_t *qreg, { teco_state_expectqreg_reset(ctx); - return ctx->flags.mode == TECO_MODE_NORMAL && - !teco_qreg_stack_pop(qreg, error) ? NULL : &teco_state_start; + if (ctx->flags.mode > TECO_MODE_NORMAL) + return &teco_state_start; + + if (!teco_machine_main_eval_colon(ctx)) + return !teco_qreg_stack_pop(qreg, error) ? NULL : &teco_state_start; + teco_expressions_push(teco_bool(teco_qreg_stack_pop(qreg, NULL))); + return &teco_state_start; } -/*$ "]" "]q" pop +/*$ "]" "]q" ":]q" pop * ]q -- Restore Q-Register + * :]q -> Success|Failure * * Restore Q-Register <q> by replacing its contents * with the contents of the register saved on top of * the Q-Register push-down stack. * The stack entry is popped. * + * When colon-modified, \fB]\fP returns a success boolean + * (-1) if there was a register to pop. + * If the stack was empty, a failure boolean (0) is returned + * instead of throwing an error. + * * In interactive mode, the original contents of <q> * are not immediately reclaimed but are kept in memory * to support rubbing out the command. diff --git a/tests/testsuite.at b/tests/testsuite.at index a5fa98e..8c6dcc8 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -146,6 +146,7 @@ TE_CHECK([[ [a 23Ub ]b Qb"N(0/0)']], 0, ignore, ignore) # FG will temporarily change the working directory to tests/testsuite.dir. TE_CHECK([[ [$ @FG'..' ]$ :Q$-1Q$-^^r"=(0/0)']], 0, ignore, ignore) TE_CHECK([[ [: @I/XXX/ ]: ."N(0/0)']], 0, ignore, ignore) +TE_CHECK([[ [a :]a"F(0/0)' ![! :]a"S(0/0)']], 0, ignore, ignore) AT_CLEANUP m4_define([TE_MAXINT32], [2147483647]) |