ed

[hare] The standard editor
Log | Files | Refs | README | LICENSE

commit 001cb7ccdde7bff7d48911fe53bfd4aa2fa799eb
parent a18cebf58eb8362115170f97262e9c56a14f57fe
Author: Byron Torres <b@torresjrjr.com>
Date:   Sun,  7 Jan 2024 20:02:24 +0000

tidy address.ha

Diffstat:
Maddress.ha | 35+++++++++++++++++------------------
1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/address.ha b/address.ha @@ -27,23 +27,23 @@ type InvalidAddress = !void; type NoMatch = !void; fn addr_nextline(buf: *Buffer, n: size) size = { - if (len(buf.lines) - 1 == n) { + if (len(buf.lines) - 1 == n) return n; - }; + return n + 1; }; fn addr_prevline(buf: *Buffer, n: size) size = { - if (n == 0 || n == 1) { + if (n == 0 || n == 1) return n; - }; + return n - 1; }; fn addr_linenum(buf: *Buffer, n: size) (size | InvalidAddress) = { - if (n >= len(buf.lines)) { + if (n >= len(buf.lines)) return InvalidAddress; - }; + return n; }; @@ -53,11 +53,11 @@ fn addr_lastline(buf: *Buffer) size = { fn addr_mark(buf: *Buffer, mark: rune) (size | InvalidAddress) = { for (let n = 1z; n < len(buf.lines); n += 1) { - const l = buf.lines[n]; - if (l.mark == mark) { + const line = buf.lines[n]; + if (line.mark == mark) return n; - }; }; + return InvalidAddress; }; @@ -71,18 +71,17 @@ fn addr_regex( const re = regex::compile(rad.expr)?; defer regex::finish(&re); for (let x = 1z; x <= length; x += 1) { - const n = if (rad.direction) { - yield (start + x) % length; - } else { - yield (start - x) % length; - }; - if (n == 0) { + const n = + if (rad.direction) + (start + x) % length + else + (start - x) % length; + + if (n == 0) continue; - }; - if (regex::test(&re, buf.lines[n].text)) { + if (regex::test(&re, buf.lines[n].text)) return n; - }; }; return NoMatch;