ed

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

commit 38188ef19073b17473e208dbd791c19caf3fcee3
parent 42ee42246a0dbf6b224d3a26e53d96644b3cb57a
Author: Byron Torres <b@torresjrjr.com>
Date:   Mon, 12 Dec 2022 23:50:15 +0000

add cmd_mark()

Diffstat:
Mcommand.ha | 35++++++++++++++++++++++++++++++++++-
Mparse.ha | 4+++-
2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/command.ha b/command.ha @@ -3,6 +3,7 @@ use fmt; use fs; use io; use os; +use strings; type command = struct { addrs: []address, @@ -206,7 +207,39 @@ fn cmd_insert(s: *session, cmd: *command) (void | error) = void; fn cmd_join(s: *session, cmd: *command) (void | error) = void; -fn cmd_mark(s: *session, cmd: *command) (void | error) = void; +fn cmd_mark(s: *session, cmd: *command) (void | error) = { + const n = get_linenum(cmd.linenums, s.buf.cursor); + assert_nonzero(s, n)?; + + const mark = strings::runes(cmd.arg)[0]; // TODO: check len, etc... + debug("cmd_mark(): mark={}", mark); + + :search { + debug("cmd_mark(): search A"); + for (let i = 0z; i < len(s.buf.trash); i += 1) { + debug("cmd_mark(): search A i={}", i); + if (s.buf.trash[i].mark == mark) { + debug("cmd_mark(): search A i={} true", i); + s.buf.trash[i].mark = '\x00'; + yield :search; + }; + }; + debug("cmd_mark(): search B"); + for (let i = 0z; i < len(s.buf.lines); i += 1) { + debug("cmd_mark(): search B i={}", i); + if (s.buf.lines[i].mark == mark) { + debug("cmd_mark(): search B i={} true", i); + s.buf.lines[i].mark = '\x00'; + yield :search; + }; + }; + debug("cmd_mark(): search C"); + }; + + debug("cmd_mark(): search D"); + + s.buf.lines[n].mark = mark; +}; fn cmd_list(s: *session, cmd: *command) (void | error) = void; diff --git a/parse.ha b/parse.ha @@ -15,6 +15,7 @@ fn parse(cmd: *command, input: str) bool = { cmd.addrs = scan_addrs(&iter); cmd.cmdfn = scan_cmdfn(&iter); cmd.arg = scan_arg(&iter); + debug("parse(): cmd.arg={}", cmd.arg); return true; }; @@ -219,7 +220,7 @@ fn scan_cmdfn(iter: *strings::iterator) commandfn = { case 'h' => return &cmd_help; // case 'i' => return &cmd_insert; // case 'j' => return &cmd_join; -// case 'k' => return &cmd_mark; + case 'k' => return &cmd_mark; // case 'l' => return &cmd_list; // case 'm' => return &cmd_move; case 'n' => return &cmd_number; @@ -239,6 +240,7 @@ fn scan_cmdfn(iter: *strings::iterator) commandfn = { fn scan_arg(iter: *strings::iterator) str = { + // TODO: just use [[strings::iterstr]]? let rs: []rune = []; for (true) { match (strings::next(iter)) {