aboutsummaryrefslogtreecommitdiff
path: root/text-objects.c
diff options
context:
space:
mode:
authorEvan Gates <evan.gates@gmail.com>2020-09-25 11:31:15 -0700
committerMarc André Tanner <mat@brain-dump.org>2020-10-10 10:03:17 +0200
commit25414c4796291e4b20ef72c92df9f08544976cb3 (patch)
treedc455fca9ed99e804b7d1b4fd91d56d531f0f7e8 /text-objects.c
parent7e57c8023dd347eac0fce1188a16de276c47e003 (diff)
downloadvis-25414c4796291e4b20ef72c92df9f08544976cb3.tar.gz
vis-25414c4796291e4b20ef72c92df9f08544976cb3.tar.xz
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 (limited to 'text-objects.c')
-rw-r--r--text-objects.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/text-objects.c b/text-objects.c
index fb5adc2..69ea91c 100644
--- 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);