vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 47efd51f1f73689d107f2ab3e25a5d9c48e27d4c parent 92733c298f04ded348ae4841baa8652966bc44f5 Author: Marc André Tanner <mat@brain-dump.org> Date: Fri, 1 Apr 2016 20:05:07 +0200 sam: implement < command in terms of | with an empty range Diffstat:
| M | sam.c | | | 14 | +++++++++++++- |
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/sam.c b/sam.c @@ -79,6 +79,7 @@ static bool cmd_select(Vis*, Win*, Command*, Filerange*); static bool cmd_print(Vis*, Win*, Command*, Filerange*); static bool cmd_files(Vis*, Win*, Command*, Filerange*); static bool cmd_shell(Vis*, Win*, Command*, Filerange*); +static bool cmd_pipein(Vis*, Win*, Command*, Filerange*); static bool cmd_filter(Vis*, Win*, Command*, Filerange*); static bool cmd_substitute(Vis*, Win*, Command*, Filerange*); static bool cmd_write(Vis*, Win*, Command*, Filerange*); @@ -99,7 +100,7 @@ static const CommandDef cmds[] = { { { "X" }, CMD_CMD|CMD_REGEX|CMD_REGEX_DEFAULT, NULL, cmd_files }, { { "Y" }, CMD_CMD|CMD_REGEX|CMD_REGEX_DEFAULT, NULL, cmd_files }, { { ">" }, CMD_SHELL, NULL, cmd_shell }, - { { "<" }, CMD_SHELL, NULL, cmd_shell }, + { { "<" }, CMD_SHELL, NULL, cmd_pipein }, { { "|" }, CMD_SHELL, NULL, cmd_filter }, { { "w" }, CMD_ARGV|CMD_FORCE, NULL, cmd_write }, { { "r" }, CMD_FILE, NULL, cmd_read }, @@ -1031,3 +1032,14 @@ static bool cmd_filter(Vis *vis, Win *win, Command *cmd, Filerange *range) { return !vis->cancel_filter && status == 0; } + +static bool cmd_pipein(Vis *vis, Win *win, Command *cmd, Filerange *range) { + Filerange filter_range = text_range_new(range->end, range->end); + Command filter_cmd = { .text = cmd->text }; // FIXME + bool ret = cmd_filter(vis, win, &filter_cmd, &filter_range); + if (ret) { + text_delete_range(win->file->text, range); + range->end = range->start + text_range_size(&filter_range); + } + return ret; +}