diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-03-11 19:04:17 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-04-03 13:22:14 +0200 |
| commit | df5873b1e2edf8e2631db236546618cb3431e3c5 (patch) | |
| tree | f467ce4b93218d9b3fe8e39ef3c122d620e35a91 /vis-cmds.c | |
| parent | 6f3703737a97c3704d19f43156a8a9a86b495214 (diff) | |
| download | vis-df5873b1e2edf8e2631db236546618cb3431e3c5.tar.gz vis-df5873b1e2edf8e2631db236546618cb3431e3c5.tar.xz | |
Support sam's structural regular expression based command language
For those not familiar with sam(1) more information can be found at
http://sam.cat-v.org/
For now sam commands can be entered from the vis prompt via :sam <cmd>
A command behaves differently depending on the mode in which it is issued:
- in visual mode it behaves as if an implicit extract x command
matching the current selection(s) would be preceding it. That is
the command is executed once for each selection.
- in normal mode:
* if an address for the command was provided it is evaluated starting
from the current cursor position(s) i.e. dot is set to the current
cursor position.
* if no address was supplied to the command then:
+ if multiple cursors exist, the command is executed once for every
cursor with dot set to the current line of the cursor
+ otherwise if there is only 1 cursor then the command is executed
with dot set to the whole file
The command syntax was slightly tweaked to accpet more terse commands.
- When specifiying text or regular expressions the trailing delimiter can
be elided if the meaning is unambigious.
- If only an address is provided the print command will be executed.
- The print command creates a selection matching its range.
- In text entry \t inserts a literal tab character (sam only recognizes \n).
Hence the sam command ,x/pattern/ can be abbreviated to x/pattern
If a command is successful vis switches to normal mode (and hence removes
any selections), otherwise the editor is kept in visual mode. The print
command "fails" by definition.
Diffstat (limited to 'vis-cmds.c')
| -rw-r--r-- | vis-cmds.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -16,6 +16,7 @@ #include "text-motions.h" #include "text-objects.h" #include "util.h" +#include "sam.h" enum CmdOpt { /* option flags for command definitions */ CMD_OPT_NONE, /* no option (default value) */ @@ -91,6 +92,7 @@ static bool cmd_map(Vis*, Filerange*, enum CmdOpt, const char *argv[]); static bool cmd_unmap(Vis*, Filerange*, enum CmdOpt, const char *argv[]); /* set language specific key bindings */ static bool cmd_langmap(Vis*, Filerange*, enum CmdOpt, const char *argv[]); +static bool cmd_sam(Vis*, Filerange*, enum CmdOpt, const char *argv[]); /* command recognized at the ':'-prompt. commands are found using a unique * prefix match. that is if a command should be available under an abbreviation @@ -124,6 +126,7 @@ static const Command cmds[] = { { { "later" }, cmd_earlier_later, CMD_OPT_NONE }, { { "!", }, cmd_filter, CMD_OPT_NONE }, { { "|", }, cmd_pipe, CMD_OPT_NONE }, + { { "sam" }, cmd_sam, CMD_OPT_NONE }, { { NULL, }, NULL, CMD_OPT_NONE }, }; @@ -1152,6 +1155,13 @@ static bool cmd_unmap(Vis *vis, Filerange *range, enum CmdOpt opt, const char *a return vis_mode_unmap(vis, mode, lhs); } +static bool cmd_sam(Vis *vis, Filerange *range, enum CmdOpt opt, const char *argv[]) { + enum SamError err = sam_cmd(vis, argv[1]); + if (err != SAM_ERR_OK) + vis_info_show(vis, "%s", sam_error(err)); + return err == SAM_ERR_OK; +} + static Filepos parse_pos(Win *win, char **cmd) { size_t pos = EPOS; View *view = win->view; |
