summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/main.c b/main.c
index 729594d..ba30adf 100644
--- a/main.c
+++ b/main.c
@@ -182,7 +182,19 @@ static inline int is_space(u32 c) {
return c <= 0x20 && c != 0;
}
+static inline int is_word_chr(u32 c) {
+ return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
+}
+
TxtLoc next_word(TxtLoc l) {
+ while (!at_end(l) && !is_word_chr(txt_chr(l)))
+ l = cnext(l);
+ while (!at_end(l) && is_word_chr(txt_chr(l)))
+ l = cnext(l);
+ return l;
+}
+
+TxtLoc next_bigword(TxtLoc l) {
while (!at_end(l) && is_space(txt_chr(l)))
l = cnext(l);
while (!at_end(l) && !is_space(txt_chr(l)))
@@ -193,6 +205,20 @@ TxtLoc next_word(TxtLoc l) {
TxtLoc prev_word(TxtLoc l) {
while (!at_start(l)) {
TxtLoc n = bprev(l);
+ if (is_word_chr(txt_chr(n))) break;
+ l = n;
+ }
+ while (!at_start(l)) {
+ TxtLoc n = bprev(l);
+ if (!is_word_chr(txt_chr(n))) break;
+ l = n;
+ }
+ return l;
+}
+
+TxtLoc prev_bigword(TxtLoc l) {
+ while (!at_start(l)) {
+ TxtLoc n = bprev(l);
if (!is_space(txt_chr(n))) break;
l = n;
}
@@ -204,6 +230,30 @@ TxtLoc prev_word(TxtLoc l) {
return l;
}
+TxtLoc word_start(TxtLoc l) {
+ while (!at_start(l) && is_word_chr(txt_chr(l))) l = cprev(l);
+ while (!at_start(l) && !is_word_chr(txt_chr(l))) l = cnext(l);
+ return l;
+}
+
+TxtLoc word_end(TxtLoc l) {
+ while (!at_start(l) && is_word_chr(txt_chr(l))) l = cnext(l);
+ while (!at_start(l) && !is_word_chr(txt_chr(l))) l = cprev(l);
+ return l;
+}
+
+TxtLoc bigword_start(TxtLoc l) {
+ while (!at_start(l) && !is_space(txt_chr(l))) l = cprev(l);
+ while (!at_start(l) && is_space(txt_chr(l))) l = cnext(l);
+ return l;
+}
+
+TxtLoc bigword_end(TxtLoc l) {
+ while (!at_start(l) && !is_space(txt_chr(l))) l = cnext(l);
+ while (!at_start(l) && is_space(txt_chr(l))) l = cprev(l);
+ return l;
+}
+
static inline u32 bracket_opp(u32 c) {
switch (c) {
case '{': return '}';
@@ -863,6 +913,20 @@ loop:
l = prev_line(l);
break;
+ case 'K': {
+ TxtLoc a = word_start(l);
+ TxtLoc b = word_end(l);
+ TxtRange r = txt_range_incl(a, b);
+ Str s = txt_collect_range(
+ (TxtLoc) { r.t, r.p0, r.i0 },
+ (TxtLoc) { r.t, r.p1, r.i1 },
+ &e.scratch
+ );
+ Str cmd = S("man ");
+ str_cat(&cmd, s, &e.scratch);
+ shell_run_no_prompt(str_to_cstr(cmd, &e.scratch));
+ } break;
+
case KEY_LEFT | KEY_CTRL_BIT:
case 'b':
l = prev_word(l);
@@ -872,6 +936,20 @@ loop:
l = next_word(l);
break;
+ case 'B':
+ l = prev_bigword(l);
+ break;
+ case 'W':
+ l = next_bigword(l);
+ break;
+
+ case 'e':
+ l = word_end(l);
+ break;
+ case 'E':
+ l = bigword_end(l);
+ break;
+
case KEY_UP | KEY_CTRL_BIT:
case '{':
l = prev_par(l);