vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit aa59a58d144bd725ec25fa73b4c19e81aef980c7
parent 47efd51f1f73689d107f2ab3e25a5d9c48e27d4c
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Fri,  1 Apr 2016 19:49:57 +0200

sam: implement r (read) command in terms of < cat

It replaces current range with the file content. However in the common
case the range is actually defaults to the whole file which is probably
not what is expected.

Diffstat:
Msam.c | 14+++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/sam.c b/sam.c @@ -964,7 +964,19 @@ static bool cmd_write(Vis *vis, Win *win, Command *cmd, Filerange *range) { } static bool cmd_read(Vis *vis, Win *win, Command *cmd, Filerange *range) { - return false; + + bool ret = false; + Buffer buf; + buffer_init(&buf); + + if (!buffer_put0(&buf, "cat ") || !buffer_append0(&buf, cmd->text)) + goto out; + + Command pipe_cmd = { .text = buf.data }; // FIXME + ret = cmd_pipein(vis, win, &pipe_cmd, range); +out: + buffer_release(&buf); + return ret; } static ssize_t read_stdout(void *context, char *data, size_t len) {