aboutsummaryrefslogtreecommitdiff
path: root/text-objects.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-08-25 18:47:00 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-08-25 18:47:00 +0200
commitb5d121dc1ca4edc0cfff888ba411f0837e6e0ebc (patch)
tree35a3aef6d494c93674922f6b5500e0d273cb0848 /text-objects.c
parentbc0f09dce9fb9420ea1d5c10ebfacf50916b10af (diff)
downloadvis-b5d121dc1ca4edc0cfff888ba411f0837e6e0ebc.tar.gz
vis-b5d121dc1ca4edc0cfff888ba411f0837e6e0ebc.tar.xz
Move motion related stuff into own file
Diffstat (limited to 'text-objects.c')
-rw-r--r--text-objects.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/text-objects.c b/text-objects.c
new file mode 100644
index 0000000..d6ac4a3
--- /dev/null
+++ b/text-objects.c
@@ -0,0 +1,38 @@
+#include <ctype.h>
+#include "text-motions.h"
+#include "text-objects.h"
+
+static Filerange empty = {
+ .start = -1,
+ .end = -1,
+};
+
+// TODO: fix problems with inclusive / exclusive
+Filerange text_object_word(Text *txt, size_t pos) {
+ char c;
+ Filerange r;
+ if (!text_byte_get(txt, pos, &c))
+ return empty;
+ if (!isspace(c)) {
+ r.start = text_word_start_prev(txt, pos);
+ r.end = text_word_end_next(txt, pos);
+ } else {
+ r.start = text_word_end_prev(txt, pos);
+ r.end = text_word_start_next(txt, pos);
+ }
+ return r;
+}
+
+Filerange text_object_sentence(Text *txt, size_t pos) {
+ Filerange r;
+ r.start = text_sentence_prev(txt, pos);
+ r.end = text_sentence_next(txt, pos);
+ return r;
+}
+
+Filerange text_object_paragraph(Text *txt, size_t pos) {
+ Filerange r;
+ r.start = text_paragraph_prev(txt, pos);
+ r.end = text_paragraph_next(txt, pos);
+ return r;
+}