From 71262efa24013d45023dc2406b046768828c8ad7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sun, 27 Nov 2016 23:46:17 +0100 Subject: sam: introduce `m as an address refering to mark m --- README.md | 5 +++++ sam.c | 15 +++++++++++++++ sam.h | 1 + 3 files changed, 21 insertions(+) diff --git a/README.md b/README.md index ab8d3dc..e07e4ec 100644 --- a/README.md +++ b/README.md @@ -358,6 +358,11 @@ Operators can be forced to work line wise by specifying `V`. Other differences compared to sam include: + - New addresses: + + * `%` as an alias for `,` or `0,$` + * `` `m `` refers to mark `m` + - The following commands are deliberately not implemented: * move `m` diff --git a/sam.c b/sam.c index 7499242..2c4fcb6 100644 --- a/sam.c +++ b/sam.c @@ -405,6 +405,7 @@ const char *sam_error(enum SamError err) { [SAM_ERR_COMMAND] = "Unknown command", [SAM_ERR_EXECUTE] = "Error executing command", [SAM_ERR_NEWLINE] = "Newline expected", + [SAM_ERR_MARK] = "Invalid mark", }; return err < LENGTH(error_msg) ? error_msg[err] : NULL; @@ -581,6 +582,14 @@ static Address *address_parse_simple(Vis *vis, const char **s, enum SamError *er addr.type = 'l'; addr.number = parse_number(s); break; + case '`': + (*s)++; + if ((addr.number = vis_mark_from(vis, **s)) == VIS_MARK_INVALID) { + *err = SAM_ERR_MARK; + return NULL; + } + (*s)++; + break; case '/': /* regexp forwards */ case '?': /* regexp backwards */ addr.regex = parse_regex(vis, s); @@ -882,6 +891,12 @@ static Filerange address_evaluate(Address *addr, File *file, Filerange *range, i case 'g': ret = address_line_evaluate(addr, file, range, sign); break; + case '`': + { + size_t pos = text_mark_get(file->text, file->marks[addr->number]); + ret = text_range_new(pos, pos); + break; + } case '?': sign = sign == 0 ? -1 : -sign; /* fall through */ diff --git a/sam.h b/sam.h index 7d063f4..717f5a4 100644 --- a/sam.h +++ b/sam.h @@ -15,6 +15,7 @@ enum SamError { SAM_ERR_COMMAND, SAM_ERR_EXECUTE, SAM_ERR_NEWLINE, + SAM_ERR_MARK, }; bool sam_init(Vis*); -- cgit v1.2.3