aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--TODO4
-rw-r--r--src/parser.h3
-rw-r--r--src/ring.c41
-rw-r--r--tests/testsuite.at3
4 files changed, 29 insertions, 22 deletions
diff --git a/TODO b/TODO
index 2a18d78..234275c 100644
--- a/TODO
+++ b/TODO
@@ -764,10 +764,6 @@ Features:
To format a hex byte, you would write 16^R 2,Qa\ ^D.
The same extension might be useful for =/==/===.
* OpenVMS port. Just for the fun of it.
- * If nEB...$ with a non-empty string argument is disallowed for n != 0,
- we should already throw in the process callback, to give immediate
- feedback. Otherwise, the user might type an entire file name just
- to find out he has to rub out everything and retype.
Optimizations:
* Use SC_DOCUMENTOPTION_STYLES_NONE in batch mode.
diff --git a/src/parser.h b/src/parser.h
index 095f523..2308925 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -494,6 +494,9 @@ struct teco_machine_main_t {
* This is tracked even in parse-only mode.
*/
guint modifier_at : 1;
+
+ /** whether <EB> command accepts a filename */
+ guint allow_filename : 1;
} flags;
/** The nesting level of braces */
diff --git a/src/ring.c b/src/ring.c
index d389e52..0dbe911 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -405,13 +405,6 @@ teco_ring_cleanup(void)
* Command states
*/
-/*
- * FIXME: Should be part of the teco_machine_main_t?
- * Unfortunately, we cannot just merge initial() with done(),
- * since we want to react immediately to xEB without waiting for $.
- */
-static gboolean allow_filename = FALSE;
-
static gboolean
teco_state_edit_file_initial(teco_machine_main_t *ctx, GError **error)
{
@@ -422,7 +415,7 @@ teco_state_edit_file_initial(teco_machine_main_t *ctx, GError **error)
if (!teco_expressions_pop_num_calc(&id, -1, error))
return FALSE;
- allow_filename = TRUE;
+ ctx->flags.allow_filename = TRUE;
if (id == 0) {
for (teco_buffer_t *cur = teco_ring_first(); cur; cur = teco_buffer_next(cur)) {
@@ -433,7 +426,7 @@ teco_state_edit_file_initial(teco_machine_main_t *ctx, GError **error)
teco_interface_popup_show(0);
} else if (id > 0) {
- allow_filename = FALSE;
+ ctx->flags.allow_filename = FALSE;
if (!teco_current_doc_undo_edit(error) ||
!teco_ring_edit(id, error))
return FALSE;
@@ -442,20 +435,31 @@ teco_state_edit_file_initial(teco_machine_main_t *ctx, GError **error)
return TRUE;
}
+gboolean
+teco_state_edit_file_process(teco_machine_main_t *ctx, const teco_string_t *str,
+ gsize new_chars, GError **error)
+{
+ g_assert(new_chars > 0);
+
+ if (!ctx->flags.allow_filename) {
+ g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED,
+ "If a buffer is selected by id, the <EB> "
+ "string argument must be empty");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static teco_state_t *
teco_state_edit_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GError **error)
{
if (ctx->flags.mode > TECO_MODE_NORMAL)
return &teco_state_start;
- if (!allow_filename) {
- if (str->len > 0) {
- g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED,
- "If a buffer is selected by id, the <EB> "
- "string argument must be empty");
- return NULL;
- }
-
+ if (!ctx->flags.allow_filename) {
+ /* process_cb() already throws error if str->len > 0 */
+ g_assert(str->len == 0);
return &teco_state_start;
}
@@ -536,7 +540,8 @@ teco_state_edit_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GE
* ecetera.
*/
TECO_DEFINE_STATE_EXPECTGLOB(teco_state_edit_file,
- .initial_cb = (teco_state_initial_cb_t)teco_state_edit_file_initial
+ .initial_cb = (teco_state_initial_cb_t)teco_state_edit_file_initial,
+ .expectstring.process_cb = teco_state_edit_file_process
);
static teco_state_t *
diff --git a/tests/testsuite.at b/tests/testsuite.at
index be064cd..38035a8 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -332,6 +332,9 @@ AT_SETUP([Opening/closing buffers])
TE_CHECK([[@EB/foo/ @I/XXX/ -EF :Q*"N(0/0)']], 0, ignore, ignore)
TE_CHECK([[@EB/foo/ @I/XXX/ :EF :Q*"N(0/0)' @EB/foo/ Z-3"N(0/0)']], 0, ignore, ignore)
TE_CHECK([[@EB/foo/ 1EF :Q*"=(0/0)']], 0, ignore, ignore)
+# Open by id
+TE_CHECK([[1@EB//]], 0, ignore, ignore)
+TE_CHECK([[1@EB/foo/]], 1, ignore, ignore)
AT_CLEANUP
AT_SETUP([Read file into current buffer])