summaryrefslogtreecommitdiff
path: root/src/config.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.zig')
-rw-r--r--src/config.zig23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/config.zig b/src/config.zig
index a2aed287..ee7d76f7 100644
--- a/src/config.zig
+++ b/src/config.zig
@@ -1489,8 +1489,9 @@ const doc_typ = struct {
/// The other build's builtins (docs/typ/builtins-*.json), so the docs
/// may name a window-only word in a terminal build's test, and back.
var other_build: []const u8 = "";
- /// The shipped addons' sources (addons/*/*.c): their words are named
- /// in the docs too, `PA_WORD("PdfFit", ...`.
+ /// The shipped addons' sources (addons/*/*.c and *.zig): their words
+ /// are named in the docs too, `PA_WORD("PdfFit", ...` or a Zig kind's
+ /// `.{ .name = "PdfFit"`.
var addon_sources: []const u8 = "";
fn loadAddons(gpa: std.mem.Allocator) !void {
@@ -1502,20 +1503,28 @@ const doc_typ = struct {
var sub = try root.openDir(io, k.name, .{ .iterate = true });
defer sub.close(io);
var files = sub.iterate();
- while (try files.next(io)) |f| if (std.mem.endsWith(u8, f.name, ".c")) {
+ while (try files.next(io)) |f| if (std.mem.endsWith(u8, f.name, ".c") or std.mem.endsWith(u8, f.name, ".zig")) {
addon_sources = try std.mem.concat(gpa, u8, &.{ addon_sources, try sub.readFileAlloc(io, f.name, gpa, .limited(1 << 20)) });
};
};
}
+ /// One of the shipped addons' words, a C kind's or a Zig kind's.
+ fn addonWord(name: []const u8) bool {
+ var buf: [96]u8 = undefined;
+ const c = std.fmt.bufPrint(&buf, "PA_WORD(\"{s}\",", .{name}) catch return false;
+ if (std.mem.indexOf(u8, addon_sources, c) != null) return true;
+ const zig = std.fmt.bufPrint(&buf, ".{{ .name = \"{s}\"", .{name}) catch return false;
+ return std.mem.indexOf(u8, addon_sources, zig) != null;
+ }
+
fn word(w: []const u8) bool {
const name = w[0 .. std.mem.indexOfScalar(u8, w, '+') orelse w.len];
if (std.meta.stringToEnum(Builtin, name) != null) return true;
var buf: [96]u8 = undefined;
const needle = std.fmt.bufPrint(&buf, "{{\"name\": \"{s}\",", .{name}) catch return false;
if (std.mem.indexOf(u8, other_build, needle) != null) return true;
- const addon = std.fmt.bufPrint(&buf, "PA_WORD(\"{s}\",", .{name}) catch return false;
- return std.mem.indexOf(u8, addon_sources, addon) != null;
+ return addonWord(name);
}
fn chord(tok: []const u8) ?Chord {
@@ -1605,9 +1614,7 @@ const doc_typ = struct {
if (!std.mem.startsWith(u8, shown, "Term ") or !std.mem.endsWith(u8, shown, " Collapse Del")) return false;
var mid = std.mem.tokenizeScalar(u8, shown["Term ".len .. shown.len - " Collapse Del".len], ' ');
while (mid.next()) |x| {
- var buf: [96]u8 = undefined;
- const addon = std.fmt.bufPrint(&buf, "PA_WORD(\"{s}\",", .{x}) catch return false;
- if (std.mem.indexOf(u8, addon_sources, addon) == null) return false;
+ if (!addonWord(x)) return false;
}
return true;
}