vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 52302b353cafc80c54fd6d7534df3d021c14b3c8
parent a4194b1efbf7d230fcb11ba8fd452e27e9e84f92
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Wed,  3 Feb 2016 12:45:48 +0100

text-motion: export custom word motion functions

Diffstat:
Mtext-motions.c | 8++++----
Mtext-motions.h | 7+++++++
2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/text-motions.c b/text-motions.c @@ -277,7 +277,7 @@ size_t text_range_line_prev(Text *txt, Filerange *r, size_t pos) { return newpos != pos && r->start <= newpos ? newpos : EPOS; } -static size_t text_customword_start_next(Text *txt, size_t pos, int (*isboundry)(int)) { +size_t text_customword_start_next(Text *txt, size_t pos, int (*isboundry)(int)) { char c; Iterator it = text_iterator_get(txt, pos); if (!text_iterator_byte_get(&it, &c)) @@ -290,7 +290,7 @@ static size_t text_customword_start_next(Text *txt, size_t pos, int (*isboundry) return it.pos; } -static size_t text_customword_start_prev(Text *txt, size_t pos, int (*isboundry)(int)) { +size_t text_customword_start_prev(Text *txt, size_t pos, int (*isboundry)(int)) { char c; Iterator it = text_iterator_get(txt, pos); while (text_iterator_char_prev(&it, &c) && isspace((unsigned char)c)); @@ -301,7 +301,7 @@ static size_t text_customword_start_prev(Text *txt, size_t pos, int (*isboundry) return pos; } -static size_t text_customword_end_next(Text *txt, size_t pos, int (*isboundry)(int)) { +size_t text_customword_end_next(Text *txt, size_t pos, int (*isboundry)(int)) { char c; Iterator it = text_iterator_get(txt, pos); while (text_iterator_char_next(&it, &c) && isspace((unsigned char)c)); @@ -312,7 +312,7 @@ static size_t text_customword_end_next(Text *txt, size_t pos, int (*isboundry)(i return pos; } -static size_t text_customword_end_prev(Text *txt, size_t pos, int (*isboundry)(int)) { +size_t text_customword_end_prev(Text *txt, size_t pos, int (*isboundry)(int)) { char c; Iterator it = text_iterator_get(txt, pos); if (!text_iterator_byte_get(&it, &c)) diff --git a/text-motions.h b/text-motions.h @@ -76,6 +76,13 @@ size_t text_word_end_next(Text*, size_t pos); size_t text_word_end_prev(Text*, size_t pos); size_t text_word_start_next(Text*, size_t pos); size_t text_word_start_prev(Text*, size_t pos); +/* + * More general versions of the above, define your own word boundaries. + */ +size_t text_customword_start_next(Text*, size_t pos, int (*isboundry)(int)); +size_t text_customword_start_prev(Text*, size_t pos, int (*isboundry)(int)); +size_t text_customword_end_next(Text*, size_t pos, int (*isboundry)(int)); +size_t text_customword_end_prev(Text*, size_t pos, int (*isboundry)(int)); /* TODO: implement the following semantics * A sentence is defined as ending at a '.', '!' or '?' followed by either the * end of a line, or by a space or tab. Any number of closing ')', ']', '"'