Add basic scripting support.

- Fix certain bugs in ruby parser
- And a lot more cleanup/minor fixes.
This commit is contained in:
2026-09-08 18:07:39 +01:00
parent a5794d9ab3
commit bb3ce7549a
20 changed files with 410 additions and 84 deletions
+31 -9
View File
@@ -37,7 +37,19 @@ void Function::register_posix(BEd &ctx) {
.desc = "Append text to a line",
.default_address = ".",
.accept_zero = true,
.pre_text_mode = nullptr,
.pre_text_mode = [](
BEd &ctx,
const buffer::Address &addr_,
const Argument &
) -> std::tuple<vase::Shard *, syntax::Language *, void *> {
const auto &addr = std::get<buffer::Line>(addr_);
auto &buf_ = ctx.buffer(addr.buffername);
if (buf_.kind != buffer::Buffer::Kind::Generic)
return {nullptr, nullptr, nullptr};
auto &buf = *(buffer::GenericBuffer *)&buf_;
void *state = syntax::state_before(buf.parse, buf.root, addr.number);
return {nullptr, buf.parse.lang, state};
},
.handle = [](
BEd &ctx,
const buffer::Address &addr_,
@@ -47,8 +59,7 @@ void Function::register_posix(BEd &ctx) {
) {
auto addr = std::get<buffer::Line>(addr_);
ctx.buffer(addr.buffername).append(ctx, text, addr.number);
vase::Shard::release(text);
}
vase::Shard::release(text); }
}
);
ctx.functions.insert(
@@ -70,9 +81,7 @@ void Function::register_posix(BEd &ctx) {
if (buf_.kind != buffer::Buffer::Kind::Generic)
return {buf_.copy(addr.start, addr.end), nullptr, nullptr};
auto &buf = *(buffer::GenericBuffer *)&buf_;
if (!buf.parse.lang)
return {buf.copy(addr.start, addr.end), nullptr, nullptr};
void *state = nullptr; // TODO: buf.parse.root.get_at(addr.start);
void *state = syntax::state_before(buf.parse, buf.root, addr.start - 1);
return {buf.copy(addr.start, addr.end), buf.parse.lang, state};
},
.handle = [](
@@ -291,7 +300,21 @@ void Function::register_posix(BEd &ctx) {
.desc = "Insert text before a line",
.default_address = ".",
.accept_zero = true,
.pre_text_mode = nullptr,
.pre_text_mode = [](
BEd &ctx,
const buffer::Address &addr_,
const Argument &
) -> std::tuple<vase::Shard *, syntax::Language *, void *> {
auto addr = std::get<buffer::Line>(addr_);
if (addr.number)
addr.number--;
auto &buf_ = ctx.buffer(addr.buffername);
if (buf_.kind != buffer::Buffer::Kind::Generic)
return {nullptr, nullptr, nullptr};
auto &buf = *(buffer::GenericBuffer *)&buf_;
void *state = syntax::state_before(buf.parse, buf.root, addr.number);
return {nullptr, buf.parse.lang, state};
},
.handle = [](
BEd &ctx,
const buffer::Address &addr_,
@@ -303,8 +326,7 @@ void Function::register_posix(BEd &ctx) {
if (addr.number)
addr.number--;
ctx.buffer(addr.buffername).append(ctx, text, addr.number);
vase::Shard::release(text);
}
vase::Shard::release(text); }
}
);
ctx.functions.insert(