Make % address work with @ mode

- add `d` function.
This commit is contained in:
2026-08-30 14:56:08 +01:00
parent 4a87a1a834
commit 41049b1ab6
5 changed files with 53 additions and 26 deletions
+17 -17
View File
@@ -35,21 +35,21 @@ void Buffer::load(BEd &, vase::Shard *text) {
}
void Buffer::append(BEd &ctx, vase::Shard *text, uint64_t line) {
ctx.prev.buffername = name;
ctx.prev.start = line + 1;
ctx.prev.end = line + text->lines + 1;
ctx.prev().buffername = name;
ctx.prev().start = line + 1;
ctx.prev().end = line + text->lines + 1;
root = vase::insert(&ctx.append, root, text, line);
ctx.marks.insert(name, ctx.prev.start, ctx.prev.end);
ctx.marks.insert(name, ctx.prev().start, ctx.prev().end);
if (parser)
parser->insert(root, ctx.prev.start, ctx.prev.end);
parser->insert(root, ctx.prev().start, ctx.prev().end);
state = Modified;
}
void Buffer::remove(BEd &ctx, uint64_t start_line, uint64_t end_line) {
root = vase::erase(root, start_line, end_line);
ctx.prev.buffername = name;
ctx.prev.start = lines() ? 1 : 0;
ctx.prev.end = lines();
ctx.prev().buffername = name;
ctx.prev().start = lines() ? 1 : 0;
ctx.prev().end = lines();
ctx.marks.erase(name, start_line, end_line - start_line + 1);
if (parser)
parser->erase(root, start_line, end_line - start_line + 1);
@@ -58,9 +58,9 @@ void Buffer::remove(BEd &ctx, uint64_t start_line, uint64_t end_line) {
void Buffer::join(BEd &ctx, uint64_t start_line, uint64_t end_line) {
root = vase::join(root, start_line, end_line);
ctx.prev.buffername = name;
ctx.prev.start = start_line;
ctx.prev.end = start_line;
ctx.prev().buffername = name;
ctx.prev().start = start_line;
ctx.prev().end = start_line;
ctx.marks.collapse(name, start_line, end_line - start_line);
if (parser)
parser->erase(root, start_line, end_line - start_line);
@@ -118,9 +118,9 @@ inline void reset(std::ostream &out) {
}
void Buffer::print(BEd &ctx, uint64_t start_line, uint64_t end_line) {
ctx.prev.buffername = name;
ctx.prev.start = start_line;
ctx.prev.end = end_line;
ctx.prev().buffername = name;
ctx.prev().start = start_line;
ctx.prev().end = end_line;
if (parser) {
std::optional<syntax::Parser::Iterator> it_o = parser->get_hl(root, start_line - 1);
auto &it = *it_o;
@@ -161,9 +161,9 @@ void Buffer::print(BEd &ctx, uint64_t start_line, uint64_t end_line) {
}
void Buffer::number_print(BEd &ctx, uint64_t start_line, uint64_t end_line) {
ctx.prev.buffername = name;
ctx.prev.start = start_line;
ctx.prev.end = end_line;
ctx.prev().buffername = name;
ctx.prev().start = start_line;
ctx.prev().end = end_line;
uint8_t width = 1;
for (uint64_t n = end_line; n >= 10; n /= 10)
++width;
+18 -1
View File
@@ -66,11 +66,28 @@ void Function::register_posix(BEd &ctx) {
.handle = [](BEd &ctx, const buffer::Address &addr_, vase::Shard *text, const Argument &, std::vector<buffer::Line> *) {
auto addr = std::get<buffer::Line>(addr_);
ctx.buffer(addr.buffername).append(ctx, text, addr.number);
ctx.current() = {ctx.prev.buffername, ctx.prev.end};
ctx.current() = {ctx.prev().buffername, ctx.prev().end};
vase::Shard::release(text);
}
}
);
ctx.functions.insert(
"d",
Function{
.address_kind = Function::AddressKind::Range,
.argument_kind = Function::ArgumentKind::None,
.input_mode = Function::InputMode::None,
.desc = "Delete set of lines.",
.default_address = ".,.",
.accept_zero = true,
.pre_text_mode = nullptr,
.handle = [](BEd &ctx, const buffer::Address &addr_, vase::Shard *, const Argument &, std::vector<buffer::Line> *) {
auto addr = std::get<buffer::Range>(addr_);
ctx.buffer(addr.buffername).remove(ctx, addr.start, addr.end);
ctx.current() = {addr.buffername, addr.start};
}
}
);
ctx.functions.insert(
"j",
Function{
+7 -7
View File
@@ -119,8 +119,8 @@ std::optional<buffer::Line> AddressPromise::get_line(BEd &ctx, std::vector<Addre
curr.offset = 0;
prev_given = false;
} else if (std::holds_alternative<LastRange>(curr.base)) {
curr.bufname = ctx.prev.buffername;
curr.base = Number(ctx.prev.end);
curr.bufname = ctx.prev().buffername;
curr.base = Number(ctx.prev().end);
prev_given = true;
} else {
prev_given = true;
@@ -146,8 +146,8 @@ std::optional<buffer::Line> AddressPromise::get_line(BEd &ctx, std::vector<Addre
}
}
} else if (std::holds_alternative<LastRange>(curr.base)) {
curr.bufname = ctx.prev.buffername;
curr.base = Number(ctx.prev.end);
curr.bufname = ctx.prev().buffername;
curr.base = Number(ctx.prev().end);
}
return curr.resolve(ctx);
}
@@ -182,8 +182,8 @@ std::optional<buffer::Range> AddressPromise::get_range(BEd &ctx, std::vector<Add
curr.offset = 0;
prev_given = false;
} else if (std::holds_alternative<LastRange>(curr.base)) {
curr.bufname = ctx.prev.buffername;
curr.base = Number(ctx.prev.end);
curr.bufname = ctx.prev().buffername;
curr.base = Number(ctx.prev().end);
prev_given = true;
} else {
prev_given = true;
@@ -210,7 +210,7 @@ std::optional<buffer::Range> AddressPromise::get_range(BEd &ctx, std::vector<Add
return buffer::Range(prev.resolve(ctx), curr.resolve(ctx));
}
} else if (std::holds_alternative<LastRange>(curr.base)) {
return ctx.prev;
return ctx.prev();
}
if (prev_given)
return buffer::Range(prev.resolve(ctx), curr.resolve(ctx));