summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2025-12-31 06:09:54 -0500
committerWormHeamer2025-12-31 06:09:54 -0500
commit13d6d4034def80a739d0e99175d1a26bfba51cea (patch)
tree3e2ebf586cff37305ab5f9f3256abf6a465313b8
parent83df7c5a4bed79c53357fd91c393071de1eb60a2 (diff)
use ; to repeat char-find commands
-rw-r--r--main.c76
1 files changed, 57 insertions, 19 deletions
diff --git a/main.c b/main.c
index cee28a8..d2d5dff 100644
--- a/main.c
+++ b/main.c
@@ -53,9 +53,14 @@ typedef struct {
Txt *txt_free;
EditMode mode;
u32 count;
+
Str input_line, input_prompt;
+
Str search;
int search_dir;
+ u32 search_char;
+ int search_char_dir;
+ int search_char_incl;
} Editor;
Editor e = { 0 };
@@ -96,6 +101,7 @@ void ed_fini(Editor *e) {
for (u32 i = 0; i < e->bufn; i++) {
ed_buf_free(&e->buf[i]);
}
+ if (e->search.s) free(e->search.s);
}
u32 ed_buf_close(Editor *e, u32 i) {
@@ -683,31 +689,63 @@ loop:
}
break;
- case 'f': {
- u32 k = vui_key();
- TxtLoc t = cnext(l);
- for (TxtLoc n = l;;) {
- u32 x = txt_chr_next(&n);
- if (x == '\n' || x == 0) break;
- if (x == k) {
- l = t;
- break;
+ case 'f':
+ e.search_char_incl = 1;
+ e.search_char_dir = 1;
+ e.search_char = vui_key();
+ goto repeat_char_search;
+
+ case 'F':
+ e.search_char_incl = 1;
+ e.search_char_dir = -1;
+ e.search_char = vui_key();
+ goto repeat_char_search;
+
+ case 't':
+ e.search_char_incl = 0;
+ e.search_char_dir = 1;
+ e.search_char = vui_key();
+ goto repeat_char_search;
+
+ case 'T':
+ e.search_char_incl = 0;
+ e.search_char_dir = -1;
+ e.search_char = vui_key();
+ goto repeat_char_search;
+
+ case ';': {
+repeat_char_search:;
+ int found = 0;
+ TxtLoc t = l;
+ if (!e.search_char_incl) {
+ if (e.search_char_dir < 0) {
+ if (at_start(t)) break;
+ t = cprev(t);
+ } else {
+ if (at_end(t)) break;
+ t = cnext(t);
}
- t = n;
}
- } break;
- case 'F': {
- u32 k = vui_key();
- TxtLoc t = cprev(l);
for (;;) {
- u32 x = txt_chr(l);
- if (x == '\n') break;
- if (x == k) {
- l = t;
+ TxtLoc p = t;
+ if (e.search_char_dir < 0) {
+ if (at_start(t)) break;
+ t = cprev(t);
+ } else {
+ if (at_end(t)) break;
+ t = cnext(t);
+ }
+ u32 x = txt_chr(t);
+ if (x == '\n' || x == 0) break;
+ if (x == e.search_char) {
+ found = 1;
+ if (e.search_char_incl) l = t;
+ else l = p;
break;
}
- t = bprev(t);
+
}
+ if (!found) return 0;
} break;
case '/':