From df49050cf32373ea2679ae71a659d0cdc5663e04 Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Fri, 2 Jan 2026 00:50:35 -0500 Subject: allow jumping to functions with opening bracket on separate line --- main.c | 24 +++++++++++++++--------- 1 file 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++] = ';'; } -- cgit v1.2.3