summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorWormHeamer2026-01-02 00:50:35 -0500
committerWormHeamer2026-01-02 00:50:35 -0500
commitdf49050cf32373ea2679ae71a659d0cdc5663e04 (patch)
tree2acfdcfa3ff08236047f3296c818422efa4fa4f8 /main.c
parent7e9411ee791915b77f857bc574040e7506b21478 (diff)
allow jumping to functions with opening bracket on separate line
Diffstat (limited to 'main.c')
-rw-r--r--main.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/main.c b/main.c
index 39f2fd6..9efe3ee 100644
--- a/main.c
+++ b/main.c
@@ -290,9 +290,17 @@ int empty_line(TxtLoc l) {
/* TODO: support having a newline before the open brace */
+static inline int func_end_to_start(TxtLoc l, TxtLoc *out) {
+ if (!match_bracket(l, &l, '}')) return 0;
+ if (txt_chr(cprev(l)) == '\n')
+ l = start_of_line(cprev(l));
+ *out = l;
+ return 1;
+}
+
int prev_func(TxtLoc start, TxtLoc *out) {
TxtLoc l;
- if (prev_func_end(start, &l) && match_bracket(l, &l, '}')) {
+ if (prev_func_end(start, &l) && func_end_to_start(l, &l)) {
*out = l;
return 1;
}
@@ -300,13 +308,11 @@ int prev_func(TxtLoc start, TxtLoc *out) {
}
int next_func(TxtLoc start, TxtLoc *out) {
- TxtLoc l = start;
- match_bracket(l, &l, '{');
- if (next_func_end(l, &l) && match_bracket(l, &l, '}')) {
- *out = l;
- return 1;
- }
- return 0;
+ start = end_of_line(start);
+ TxtLoc l, k;
+ if (!next_func_end(start, &l)) return 0;
+ if (!func_end_to_start(l, &k) || (!txt_before(start, k) && !next_func_end(l, &l))) return 0;
+ return func_end_to_start(l, out);
}
TxtLoc next_par(TxtLoc l) {
@@ -1322,7 +1328,7 @@ int select_func(Txt *t, TxtLoc *out) {
for (u32 i = 0; i < loc.n; i++) {
opt[i] = txt_collect_range(start_of_line(loc.v[i]), end_of_line(loc.v[i]), &e.scratch);
ASSERT(opt[i].n > 0);
- opt[i].n--;
+ if (opt[i].s[opt[i].n-1] == '{') opt[i].n--;
while (opt[i].n > 0 && is_space(opt[i].s[opt[i].n - 1])) opt[i].n--;
opt[i].s[opt[i].n++] = ';';
}