From fbab5e252f22de37d42cc6c2a014d690a9312565 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Sun, 13 Jul 2025 18:35:32 +0300 Subject: implemented command for reading a file into the current buffer * This command exists in Video TECO. In Video TECO it also supports reading multiple files with a glob pattern -- we do not support that as I am not convinced of its usefulness. * teco_view_load() has been extended, so it can read into dot without discarding the existing document. --- src/ring.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'src/ring.c') diff --git a/src/ring.c b/src/ring.c index 1c9a2cd..afda650 100644 --- a/src/ring.c +++ b/src/ring.c @@ -77,7 +77,7 @@ teco_buffer_undo_edit(teco_buffer_t *ctx) static gboolean teco_buffer_load(teco_buffer_t *ctx, const gchar *filename, GError **error) { - if (!teco_view_load(ctx->view, filename, error)) + if (!teco_view_load(ctx->view, filename, TRUE, error)) return FALSE; #if 0 /* NOTE: currently buffer cannot be dirty */ @@ -595,6 +595,40 @@ teco_state_save_file_done(teco_machine_main_t *ctx, const teco_string_t *str, GE */ TECO_DEFINE_STATE_EXPECTFILE(teco_state_save_file); +static teco_state_t * +teco_state_read_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; + + sptr_t pos = teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0); + + g_autofree gchar *filename = teco_file_expand_path(str->data); + /* FIXME: Add wrapper to interface.h? */ + if (!teco_view_load(teco_interface_current_view, filename, FALSE, error)) + return NULL; + + if (teco_interface_ssm(SCI_GETCURRENTPOS, 0, 0) != pos) { + teco_ring_dirtify(); + + if (teco_current_doc_must_undo()) + undo__teco_interface_ssm(SCI_UNDO, 0, 0); + } + + return &teco_state_start; +} + +/*$ ER read + * ER$ -- Read and insert file into current buffer + * + * Reads and inserts the given into the current buffer or Q-Register at dot. + * Dot is left immediately after the given file. + */ +/* + * NOTE: Video TECO allows glob patterns as an argument. + */ +TECO_DEFINE_STATE_EXPECTFILE(teco_state_read_file); + /*$ EF close * [n]EF -- Remove buffer from ring * -EF -- cgit v1.2.3