vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit b8eb15bb6f0ff0453a257483fb6e280a10c1be3e parent fb02705a2cafebe74b42077550d27ffd905a6e4f Author: Marc André Tanner <mat@brain-dump.org> Date: Fri, 8 Apr 2016 12:57:39 +0200 sam: change default address of < and | commands If no address is provided these commands no longer apply to the whole line, but instead will insert the output of the external program at the current cursor location. Diffstat:
| M | sam.c | | | 27 | ++++++++++++++++----------- |
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/sam.c b/sam.c @@ -61,13 +61,14 @@ struct CommandDef { CMD_COUNT = 1 << 3, /* does the command support a count as in s2/../? */ CMD_TEXT = 1 << 4, /* does the command need a text to insert? */ CMD_ADDRESS_NONE = 1 << 5, /* is it an error to specify an address for the command? */ - CMD_ADDRESS_LINE = 1 << 6, /* if no address is given, use the current line */ - CMD_ADDRESS_AFTER = 1 << 7, /* if no address is given, begin at the start of the next line */ - CMD_SHELL = 1 << 8, /* command needs a shell command as argument */ - CMD_FILE = 1 << 9, /* does the command take a file name */ - CMD_FORCE = 1 << 10, /* can the command be forced with ! */ - CMD_ARGV = 1 << 11, /* whether shell like argument splitted is desired */ - CMD_ONCE = 1 << 12, /* command should only be executed once, not for every selection */ + CMD_ADDRESS_POS = 1 << 6, /* no address implies an empty range at current cursor position */ + CMD_ADDRESS_LINE = 1 << 7, /* if no address is given, use the current line */ + CMD_ADDRESS_AFTER = 1 << 8, /* if no address is given, begin at the start of the next line */ + CMD_SHELL = 1 << 9, /* command needs a shell command as argument */ + CMD_FILE = 1 << 10, /* does the command take a file name */ + CMD_FORCE = 1 << 11, /* can the command be forced with ! */ + CMD_ARGV = 1 << 12, /* whether shell like argument splitted is desired */ + CMD_ONCE = 1 << 13, /* command should only be executed once, not for every selection */ } flags; const char *defcmd; /* name of a default target command */ bool (*func)(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*); /* command implementation */ @@ -128,8 +129,8 @@ static const CommandDef cmds[] = { { { "X" }, CMD_CMD|CMD_REGEX|CMD_REGEX_DEFAULT, NULL, cmd_files }, { { "Y" }, CMD_CMD|CMD_REGEX, NULL, cmd_files }, { { ">" }, CMD_SHELL|CMD_ADDRESS_LINE, NULL, cmd_pipeout }, - { { "<" }, CMD_SHELL|CMD_ADDRESS_LINE, NULL, cmd_pipein }, - { { "|" }, CMD_SHELL|CMD_ADDRESS_LINE, NULL, cmd_filter }, + { { "<" }, CMD_SHELL|CMD_ADDRESS_POS, NULL, cmd_pipein }, + { { "|" }, CMD_SHELL|CMD_ADDRESS_POS, NULL, cmd_filter }, { { "!" }, CMD_SHELL|CMD_ONCE, NULL, cmd_launch }, { { "w" }, CMD_ARGV|CMD_FORCE, NULL, cmd_write }, { { "r" }, CMD_FILE|CMD_ADDRESS_AFTER, NULL, cmd_read }, @@ -936,12 +937,16 @@ static bool cmd_select(Vis *vis, Win *win, Command *cmd, const char *argv[], Cur break; } } - sel = text_range_new(pos, text_char_next(txt, pos)); - } else if (multiple_cursors || (cmd->cmd->cmddef->flags & CMD_ADDRESS_LINE)) { + sel = text_range_new(pos, pos); + } else if (cmd->cmd->cmddef->flags & CMD_ADDRESS_POS) { + sel = text_range_new(pos, pos); + } else if (cmd->cmd->cmddef->flags & CMD_ADDRESS_LINE) { sel = text_object_line(txt, pos); } else if (cmd->cmd->cmddef->flags & CMD_ADDRESS_AFTER) { size_t next_line = text_line_next(txt, pos); sel = text_range_new(next_line, next_line); + } else if (multiple_cursors) { + sel = text_object_line(txt, pos); } else { sel = text_range_new(0, text_size(txt)); }