From df5873b1e2edf8e2631db236546618cb3431e3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Fri, 11 Mar 2016 19:04:17 +0100 Subject: 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 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. --- sam.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 sam.h (limited to 'sam.h') diff --git a/sam.h b/sam.h new file mode 100644 index 0000000..fb4f314 --- /dev/null +++ b/sam.h @@ -0,0 +1,21 @@ +#ifndef SAM_H +#define SAM_H + +#include "vis.h" + +enum SamError { + SAM_ERR_OK, + SAM_ERR_MEMORY, + SAM_ERR_ADDRESS, + SAM_ERR_NO_ADDRESS, + SAM_ERR_UNMATCHED_BRACE, + SAM_ERR_REGEX, + SAM_ERR_TEXT, + SAM_ERR_COMMAND, + SAM_ERR_EXECUTE, +}; + +enum SamError sam_cmd(Vis *vis, const char *cmd); +const char *sam_error(enum SamError); + +#endif -- cgit v1.2.3