aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ring.c
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2025-07-13 18:35:32 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2025-07-13 18:35:32 +0300
commitfbab5e252f22de37d42cc6c2a014d690a9312565 (patch)
tree9552e56a343e5b9e273021ab53c376d773486447 /src/ring.c
parent8c6de6cc718debf44f6056a4c34c4fbb13bc5020 (diff)
downloadsciteco-fbab5e252f22de37d42cc6c2a014d690a9312565.tar.gz
implemented <ER> 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.
Diffstat (limited to 'src/ring.c')
-rw-r--r--src/ring.c36
1 files changed, 35 insertions, 1 deletions
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<file>$ -- Read and insert file into current buffer
+ *
+ * Reads and inserts the given <file> 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