diff options
| author | WormHeamer | 2026-01-02 05:31:54 -0500 |
|---|---|---|
| committer | WormHeamer | 2026-01-02 05:31:54 -0500 |
| commit | 70b086db3eacc38d22c3e7b25f82492a1450da04 (patch) | |
| tree | 2c7b78b1e6bf2cd2ecdd203e787d0acf935cff73 | |
| parent | 0031e70953bccc81eadb3d99960094b3d76138b2 (diff) | |
dont match brackets for function navigation
| -rw-r--r-- | main.c | 31 |
1 files changed, 17 insertions, 14 deletions
@@ -227,29 +227,19 @@ static inline int bracket_dir(u32 c) { } } +/* TODO: reintroduce match_func_end_to-start */ int match_bracket(TxtLoc l, TxtLoc *out, u32 c) { u32 depth = 1; u32 o = bracket_opp(c); if (txt_chr(l) != c) return 0; int dir = bracket_dir(c); if (!dir) return 0; - int in_str = 0, in_chr = 0; while (depth > 0) { if (dir < 0 && at_start(l)) break; if (dir > 0 && at_end(l)) break; l = dir < 0 ? cprev(l) : cnext(l); u32 x = txt_chr(l); - int bs = (txt_chr(cprev(l)) == '\\') && (txt_chr(cprev(cprev(l))) != '\\'); - if (in_chr) { - if (!bs && x == '\'') in_chr = 0; - } else if (in_str) { - if (!bs && x == '"') in_str = 0; - } else { - if (x == '\'') in_chr = 1; - else if (x == '"') in_str = 1; - else if (x == c) depth++; - else if (x == o) depth--; - } + depth += (x == c) - (x == o); } if (depth == 0) { *out = l; @@ -259,6 +249,17 @@ int match_bracket(TxtLoc l, TxtLoc *out, u32 c) { } } +static inline TxtLoc inner_line_end(TxtLoc l) { + l = end_of_line(l); + if (txt_chr(cprev(l)) != '\n') l = cprev(l); + return l; +} + +static inline int is_func_start(TxtLoc l) { + return txt_chr(inner_line_end(l)) == '{' + && !is_space(txt_chr(start_of_line(l))); +} + static inline int is_func_end(TxtLoc l) { TxtLoc n = cnext(l); return txt_chr(l) == '}' && (txt_chr(n) == '\n' || at_end(n)); @@ -299,9 +300,11 @@ 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') + while (!at_start(l) && !is_func_start(l)) + l = prev_line_start(l); + if (txt_chr(start_of_line(l)) == '{') l = start_of_line(cprev(l)); + l = end_of_line(l); *out = l; return 1; } |
