mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-12-14 04:23:48 +01:00
feat: mzte-nv now compiles packer-compiled.lua
This commit is contained in:
parent
15fa36b24c
commit
73d251f9cf
5 changed files with 39 additions and 26 deletions
|
@ -1,9 +1,9 @@
|
|||
-- This module is responsible for loading the native mzte-nv lua module
|
||||
package.cpath = package.cpath .. ";" .. vim.loop.os_homedir() .. "/.local/share/nvim/mzte-nv.so"
|
||||
|
||||
local success = pcall(require, "mzte_nv");
|
||||
local success, mztenv = pcall(require, "mzte_nv")
|
||||
if not success then
|
||||
error "Failed to preload mzte-nv. Is it installed?"
|
||||
end
|
||||
|
||||
require("mzte_nv").onInit()
|
||||
mztenv.onInit()
|
||||
|
|
|
@ -186,6 +186,11 @@ require("packer").startup(function(use)
|
|||
cmp_plugins(use)
|
||||
end)
|
||||
|
||||
vim.api.nvim_create_user_command("CompilePlugins", function()
|
||||
require("mzte_nv").compile.compilePath(require("packer").config.package_root)
|
||||
end, { nargs = 0 })
|
||||
-- actually compile packer-generated config after packer's "compile" step
|
||||
vim.api.nvim_create_autocmd("User", {
|
||||
pattern = "PackerCompileDone",
|
||||
once = true,
|
||||
callback = function()
|
||||
require("mzte_nv").compile.compilePath(require("packer").config.compile_path)
|
||||
end,
|
||||
})
|
||||
|
|
|
@ -40,3 +40,7 @@ cmd "filetype plugin on"
|
|||
vim.api.nvim_create_user_command("CompileConfig", function()
|
||||
require("mzte_nv").compile.compilePath(vim.fn.getenv("HOME") .. "/.config/nvim")
|
||||
end, { nargs = 0 })
|
||||
|
||||
vim.api.nvim_create_user_command("CompilePlugins", function()
|
||||
require("mzte_nv").compile.compilePath(require("packer").config.package_root)
|
||||
end, { nargs = 0 })
|
||||
|
|
|
@ -46,32 +46,36 @@ pub fn doCompile(path: []const u8, alloc: std.mem.Allocator) !void {
|
|||
// prepare state
|
||||
c.lua_getfield(l, c.LUA_GLOBALSINDEX, "string");
|
||||
|
||||
var dir = try std.fs.cwd().openIterableDir(path, .{});
|
||||
defer dir.close();
|
||||
|
||||
var walker = try dir.walk(alloc);
|
||||
defer walker.deinit();
|
||||
|
||||
// a list of lua files to compile
|
||||
var files = std.ArrayList([]const u8).init(alloc);
|
||||
defer files.deinit();
|
||||
|
||||
// an arena allocator to hold data to be used during the build
|
||||
var build_arena = std.heap.ArenaAllocator.init(alloc);
|
||||
defer build_arena.deinit();
|
||||
const build_alloc = build_arena.allocator();
|
||||
|
||||
while (try walker.next()) |entry| {
|
||||
const entry_path = try std.fs.path.join(build_alloc, &.{ path, entry.path });
|
||||
// a list of lua files to compile
|
||||
var files = std.ArrayList([]const u8).init(alloc);
|
||||
defer files.deinit();
|
||||
|
||||
switch (entry.kind) {
|
||||
.File => {
|
||||
if (std.mem.endsWith(u8, entry.path, ".lua")) {
|
||||
try files.append(entry_path);
|
||||
}
|
||||
},
|
||||
else => {},
|
||||
if ((try std.fs.cwd().statFile(path)).kind == .Directory) {
|
||||
var dir = try std.fs.cwd().openIterableDir(path, .{});
|
||||
defer dir.close();
|
||||
|
||||
var walker = try dir.walk(alloc);
|
||||
defer walker.deinit();
|
||||
|
||||
while (try walker.next()) |entry| {
|
||||
const entry_path = try std.fs.path.join(build_alloc, &.{ path, entry.path });
|
||||
|
||||
switch (entry.kind) {
|
||||
.File => {
|
||||
if (std.mem.endsWith(u8, entry.path, ".lua")) {
|
||||
try files.append(entry_path);
|
||||
}
|
||||
},
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try files.append(path);
|
||||
}
|
||||
|
||||
for (files.items) |luafile| {
|
||||
|
@ -80,7 +84,7 @@ pub fn doCompile(path: []const u8, alloc: std.mem.Allocator) !void {
|
|||
|
||||
c.lua_getfield(l, -1, "dump");
|
||||
if (c.luaL_loadfile(l, luafile_z) != 0) {
|
||||
std.log.warn(
|
||||
log.warn(
|
||||
"error compiling lua object {s}: {s}",
|
||||
.{ luafile, c.lua_tolstring(l, -1, null) },
|
||||
);
|
||||
|
|
|
@ -3,7 +3,7 @@ const ffi = @import("ffi.zig");
|
|||
const ser = @import("ser.zig");
|
||||
const c = ffi.c;
|
||||
|
||||
pub const version = "1.1.0";
|
||||
pub const version = "1.2.0";
|
||||
|
||||
const modules = struct {
|
||||
const cmp = @import("modules/cmp.zig");
|
||||
|
|
Loading…
Reference in a new issue