diff options
| -rw-r--r-- | sam.c | 46 |
1 files changed, 21 insertions, 25 deletions
@@ -52,19 +52,20 @@ struct Command { }; struct CommandDef { - const char *name[3]; /* name and optional alias for the command */ + const char *name[3]; /* name and optional alias for the command */ enum { - CMD_CMD = 1 << 0, /* does the command take a sub/target command? */ - CMD_REGEX = 1 << 1, /* regex after command? */ - CMD_REGEX_DEFAULT = 1 << 2, /* is the regex optional i.e. can we use a default? */ - 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_ALL = 1 << 6, /* if no address is given, use the whole file */ - CMD_SHELL = 1 << 7, /* command needs a shell command as argument */ - CMD_FILE = 1 << 8, /* does the command take a file name */ - CMD_FORCE = 1 << 9, /* can the command be forced with ! */ - CMD_ARGV = 1 << 10, /* whether shell like argument splitted is desired */ + CMD_CMD = 1 << 0, /* does the command take a sub/target command? */ + CMD_REGEX = 1 << 1, /* regex after command? */ + CMD_REGEX_DEFAULT = 1 << 2, /* is the regex optional i.e. can we use a default? */ + 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 */ } flags; const char *defcmd; /* name of a default target command */ bool (*func)(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*); /* command implementation */ @@ -124,12 +125,12 @@ static const CommandDef cmds[] = { { { "y" }, CMD_CMD|CMD_REGEX|CMD_REGEX_DEFAULT, "p", cmd_extract }, { { "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_pipeout }, - { { "<" }, CMD_SHELL, NULL, cmd_pipein }, - { { "|" }, CMD_SHELL, NULL, cmd_filter }, + { { ">" }, 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, NULL, cmd_launch }, { { "w" }, CMD_ARGV|CMD_FORCE, NULL, cmd_write }, - { { "r" }, CMD_FILE, NULL, cmd_read }, + { { "r" }, CMD_FILE|CMD_ADDRESS_AFTER, NULL, cmd_read }, { { "{" }, 0, NULL, NULL }, { { "}" }, 0, NULL, NULL }, { { "e" }, CMD_FILE|CMD_FORCE, NULL, cmd_edit }, @@ -593,14 +594,6 @@ static Command *command_parse(Vis *vis, const char **s, int level, enum SamError } } - if (!cmd->address) { - if (cmddef->flags & CMD_ADDRESS_ALL) { - if (!(cmd->address = address_new())) - goto fail; - cmd->address->type = '%'; - } - } - return cmd; fail: command_free(cmd); @@ -931,8 +924,11 @@ static bool cmd_select(Vis *vis, Win *win, Command *cmd, const char *argv[], Cur } } sel = text_range_new(pos, text_char_next(txt, pos)); - } else if (multiple_cursors) { + } else if (multiple_cursors || (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 { sel = text_range_new(0, text_size(txt)); } |
