vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit 69d72c44be81c55ba6abea7a70d21bdcc853275f parent 6f69d706402b6ec3d35b86e299661606cebfeb09 Author: Marc André Tanner <mat@brain-dump.org> Date: Thu, 22 Dec 2016 14:36:20 +0100 text: introduce EMARK to denote an invalid mark Technically this macro name is in the reserved namespace of errno.h. The same is true for EPOS. Maybe we should rename them at some point, but for now the short names are convenient. Fix #443 Close #444 Diffstat:
| M | text.c | | | 4 | ++-- |
| M | text.h | | | 4 | +++- |
| M | vis-operators.c | | | 4 | ++-- |
3 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/text.c b/text.c @@ -1634,14 +1634,14 @@ Mark text_mark_set(Text *txt, size_t pos) { return (Mark)&txt->end; Location loc = piece_get_extern(txt, pos); if (!loc.piece) - return (Mark)NULL; + return EMARK; return (Mark)(loc.piece->data + loc.off); } size_t text_mark_get(Text *txt, Mark mark) { size_t cur = 0; - if (!mark) + if (mark == EMARK) return EPOS; if (mark == (Mark)&txt->begin) return 0; diff --git a/text.h b/text.h @@ -9,6 +9,9 @@ #include <sys/types.h> #include <sys/stat.h> +typedef uintptr_t Mark; + +#define EMARK ((Mark)0) /* invalid mark */ #define EPOS ((size_t)-1) /* invalid position */ typedef size_t Filepos; @@ -100,7 +103,6 @@ bool text_iterator_codepoint_prev(Iterator *it, char *c); bool text_iterator_char_next(Iterator*, char *c); bool text_iterator_char_prev(Iterator*, char *c); -typedef uintptr_t Mark; /* mark position `pos', the returned mark can be used to later retrieve * the same text segment */ Mark text_mark_set(Text*, size_t pos); diff --git a/vis-operators.c b/vis-operators.c @@ -185,7 +185,7 @@ static size_t op_cursor(Vis *vis, Text *txt, OperatorContext *c) { static size_t op_join(Vis *vis, Text *txt, OperatorContext *c) { size_t pos = text_line_begin(txt, c->range.end), prev_pos; - Mark mark = NULL; + Mark mark = EMARK; /* if operator and range are both linewise, skip last line break */ if (c->linewise && text_range_is_linewise(txt, &c->range)) { @@ -208,7 +208,7 @@ static size_t op_join(Vis *vis, Text *txt, OperatorContext *c) { if (text_byte_get(txt, pos-1, &prev) && !isspace((unsigned char)prev) && text_byte_get(txt, pos, &next) && next != '\r' && next != '\n') text_insert(txt, pos, c->arg->s, len); - if (!mark) + if (mark == EMARK) mark = text_mark_set(txt, pos); } while (pos != prev_pos);