vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit dc58a1f89ddd2eb0c3dff7494bc2e191f4715f31 parent c0b51594f2edbcbd14da396607abdc2ef57de2ce Author: Marc André Tanner <mat@brain-dump.org> Date: Fri, 5 Sep 2014 07:29:27 +0200 Add helper function which finds the start of the next line Diffstat:
| M | text-motions.c | | | 10 | ++++++++++ |
| M | text-motions.h | | | 5 | +++-- |
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/text-motions.c b/text-motions.c @@ -98,6 +98,16 @@ size_t text_line_end(Text *txt, size_t pos) { return text_find_char_next(txt, pos, "\n", 1); } +size_t text_line_next(Text *txt, size_t pos) { + char c; + Iterator it = text_iterator_get(txt, pos); + while (text_iterator_byte_get(&it, &c) && c != '\n') + text_iterator_byte_next(&it, NULL); + if (text_iterator_byte_next(&it, &c) && c == '\r') + text_iterator_byte_next(&it, NULL); + return it.pos; +} + size_t text_word_boundry_start_next(Text *txt, size_t pos, int (*isboundry)(int)) { char c; Iterator it = text_iterator_get(txt, pos); diff --git a/text-motions.h b/text-motions.h @@ -13,8 +13,8 @@ size_t text_char_prev(Text*, size_t pos); size_t text_find_char_next(Text*, size_t pos, const char *s, size_t len); size_t text_find_char_prev(Text*, size_t pos, const char *s, size_t len); -/* begin finish - * v v +/* begin finish next + * v v v * \n[\r] I am a line! \n[\r] * ^ ^ * start end @@ -23,6 +23,7 @@ size_t text_line_begin(Text*, size_t pos); size_t text_line_start(Text*, size_t pos); size_t text_line_finish(Text*, size_t pos); size_t text_line_end(Text*, size_t pos); +size_t text_line_next(Text*, size_t pos); /* * A word consists of a sequence of non-blank characters, separated with white space. * TODO?: An empty line is also considered to be a word. This is equivalant to a WORD