aboutsummaryrefslogtreecommitdiff
path: root/text-motions.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-09-25 19:19:05 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-09-25 19:19:05 +0200
commit62682f0d351890f3050b3251d5d26448bf922109 (patch)
treeea2b813f71abe6713308fe1a4675520b79e1247b /text-motions.c
parent334e7f278f18889582c51bd9aceb469e716cddea (diff)
downloadvis-62682f0d351890f3050b3251d5d26448bf922109.tar.gz
vis-62682f0d351890f3050b3251d5d26448bf922109.tar.xz
Add infrastructure for word (lowercase) motions
This unfortunately doesn't work as is which is why it is not actually hooked up to key bindings.
Diffstat (limited to 'text-motions.c')
-rw-r--r--text-motions.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/text-motions.c b/text-motions.c
index bee4a34..0d121fd 100644
--- a/text-motions.c
+++ b/text-motions.c
@@ -18,6 +18,13 @@
#include "text-motions.h"
#include "util.h"
+// TODO: specify this per file type?
+static int is_word_boundry(int c) {
+ return !(('0' <= c && c <= '9') ||
+ ('a' <= c && c <= 'z') ||
+ ('A' <= c && c <= 'Z'));
+}
+
// TODO: consistent usage of iterators either char or byte based where appropriate.
size_t text_begin(Text *txt, size_t pos) {
@@ -154,6 +161,7 @@ size_t text_line_next(Text *txt, size_t 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);
+ text_iterator_byte_next(&it, NULL);
while (text_iterator_byte_get(&it, &c) && !isboundry(c))
text_iterator_byte_next(&it, NULL);
while (text_iterator_byte_get(&it, &c) && isboundry(c))
@@ -202,6 +210,23 @@ size_t text_longword_start_prev(Text *txt, size_t pos) {
return text_word_boundry_start_prev(txt, pos, isspace);
}
+// TODO: this actually doesn't work that way -> rewrite
+size_t text_word_end_next(Text *txt, size_t pos) {
+ return text_word_boundry_end_next(txt, pos, is_word_boundry);
+}
+
+size_t text_word_end_prev(Text *txt, size_t pos) {
+ return text_word_boundry_end_prev(txt, pos, is_word_boundry);
+}
+
+size_t text_word_start_next(Text *txt, size_t pos) {
+ return text_word_boundry_start_next(txt, pos, is_word_boundry);
+}
+
+size_t text_word_start_prev(Text *txt, size_t pos) {
+ return text_word_boundry_start_prev(txt, pos, is_word_boundry);
+}
+
static size_t text_paragraph_sentence_next(Text *txt, size_t pos, bool sentence) {
char c;
bool content = false, paragraph = false;