vis
a vi-like editor based on Plan 9's structural regular expressions
git clone https://9o.is/git/vis.git
commit c8f82c7e0511c33d0a6abb3a7b2f4a64a446d4dd parent 9b4df12b156fd879a6118c8c92ae495e2468d3e1 Author: Evan Gates <evan.gates@gmail.com> Date: Fri, 25 Sep 2020 11:31:15 -0700 text: add text_object_find_next/prev Add two new text-object functions to search forwards/backwards for a string literal (not a regex) with the same signature as text_object_word_find_next/prev. This allows them to be used interchangeably with the word based variant through function pointers. Diffstat:
| M | text-objects.c | | | 14 | ++++++++++++++ |
| M | text-objects.h | | | 3 | +++ |
2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/text-objects.c b/text-objects.c @@ -137,6 +137,20 @@ Filerange text_object_word_find_prev(Text *txt, size_t pos, const char *word) { } } +Filerange text_object_find_next(Text *txt, size_t pos, const char *search) { + size_t start = text_find_next(txt, pos, search); + if (start == pos) + return text_range_empty(); + return text_range_new(start, start+strlen(search)); +} + +Filerange text_object_find_prev(Text *txt, size_t pos, const char *search) { + size_t start = text_find_prev(txt, pos, search); + if (start == pos) + return text_range_empty(); + return text_range_new(start, start+strlen(search)); +} + Filerange text_object_line(Text *txt, size_t pos) { Filerange r; r.start = text_line_begin(txt, pos); diff --git a/text-objects.h b/text-objects.h @@ -19,6 +19,9 @@ Filerange text_object_word_outer(Text*, size_t pos); /* find next occurance of `word' (as word not substring) in forward/backward direction */ Filerange text_object_word_find_next(Text*, size_t pos, const char *word); Filerange text_object_word_find_prev(Text*, size_t pos, const char *word); +/* find next occurance of a literal string (not regex) in forward/backward direction */ +Filerange text_object_find_next(Text *txt, size_t pos, const char *search); +Filerange text_object_find_prev(Text *txt, size_t pos, const char *search); /* same semantics as above but for a longword (i.e. delimited by white spaces) */ Filerange text_object_longword(Text*, size_t pos); Filerange text_object_longword_outer(Text*, size_t pos);