rewrite a bit of nvim config in fennel

This commit is contained in:
LordMZTE 2023-02-18 00:35:59 +01:00
parent 72eb90a939
commit 6de6a9d44c
Signed by: LordMZTE
GPG key ID: B64802DC33A64FF6
12 changed files with 113 additions and 80 deletions

View file

@ -0,0 +1,8 @@
(vim.filetype.add {:extension {:cgt (fn [_path bufnr]
(local trimmed (path:gsub :.cgt$ ""))
(vim.filetype.match {:filename trimmed
: bufnr}))
;; nvim defaults to scheme
:rkt :racket
:rktl :racket
:rktd :racket}})

View file

@ -1,13 +0,0 @@
vim.filetype.add {
extension = {
cgt = function(path, bufnr)
local trimmed = path:gsub(".cgt$", "")
return vim.filetype.match { filename = trimmed, bufnr = bufnr }
end,
-- nvim defaults to scheme
rkt = "racket",
rktd = "racket",
rktl = "racket",
},
}

7
mzte-nv/conf/init.fnl Normal file
View file

@ -0,0 +1,7 @@
(require :mzte_nv_preloader)
(require :plugins)
(require :settings)
(require :maps)
(require :neovide)
(require :pipe)

View file

@ -1,7 +0,0 @@
require "mzte_nv_preloader"
require "plugins"
require "settings"
require "maps"
require "neovide"
require "pipe"

40
mzte-nv/conf/lua/maps.fnl Normal file
View file

@ -0,0 +1,40 @@
(local opts {:noremap true :silent true})
(macro nmap [map action]
`(vim.api.nvim_set_keymap :n ,map ,action opts))
(macro cmd [c]
(.. :<cmd> c :<CR>))
(macro lcmd [c]
`(cmd ,(.. "lua " c)))
;; Getting stuck in ~~vim~~ terminal
(vim.api.nvim_set_keymap :t :<Esc> "<C-\\><C-n>" {})
;; Quick cursor movement
(nmap :<C-Down> :5j)
(nmap :<C-Up> :5k)
;; Quick system register access
(each [_ p (ipairs ["+" "*"])]
(each [_ r (ipairs [:y :p :d])]
(nmap (.. p r) (.. "\"" p r))))
;; Vimgrep
(nmap :<F4> (cmd :cnext))
(nmap :<S-F4> (cmd :cprevious))
;; LSP
(nmap :-a (lcmd "vim.lsp.buf.code_action()"))
(nmap :-d (lcmd "vim.diagnostic.goto_next()"))
(nmap :-n (lcmd "vim.lsp.buf.rename()"))
(nmap :-r (lcmd "vim.lsp.buf.format { async = true }"))
(nmap :<C-k> (lcmd "vim.lsp.buf.signature_help()"))
(nmap :<space>e (lcmd "vim.diagnostic.open_float()"))
(nmap :K (lcmd "vim.lsp.buf.hover()"))
;; command to stop LSPs
(vim.api.nvim_create_user_command :StopLsps
#(vim.lsp.stop_client (vim.lsp.get_active_clients))
{:nargs 0})

View file

@ -1,36 +0,0 @@
local map = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true }
-- Getting stuck in ~~vim~~ terminal
map("t", "<Esc>", "<C-\\><C-n>", {})
-- Quick cursor movement
map("n", "<C-Down>", "5j", opts)
map("n", "<C-Up>", "5k", opts)
-- Quick pasting/yoinking to system register
map("n", "+y", '"+y', opts)
map("n", "+p", '"+p', opts)
map("n", "+d", '"+d', opts)
map("n", "*y", '"*y', opts)
map("n", "*p", '"*p', opts)
map("n", "*d", '"*d', opts)
-- Vimgrep
map("n", "<F4>", "<cmd>:cnext<CR>", opts)
map("n", "<S-F4>", "<cmd>:cprevious<CR>", opts)
-- See `:help vim.lsp.*` for documentation on any of the below functions
map("n", "-a", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
map("n", "-d", "<cmd>lua vim.diagnostic.goto_next()<CR>", opts)
map("n", "-n", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
map("n", "-r", "<cmd>lua vim.lsp.buf.format { asnyc = true }<CR>", opts)
map("n", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
map("n", "<space>e", "<cmd>lua vim.diagnostic.open_float()<CR>", opts)
map("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
-- command to stop LSP servers
vim.api.nvim_create_user_command("StopLsps", function()
vim.lsp.stop_client(vim.lsp.get_active_clients())
end, { nargs = 0 })

View file

@ -0,0 +1,8 @@
;; This module is responsible for loading the native mzte-nv lua module
(set package.cpath (.. (. package :cpath) ";" (vim.loop.os_homedir)
:/.local/share/nvim/mzte-nv.so))
(let [(success mztenv) (pcall require :mzte_nv)]
(when (not success)
(error "Failed to preload mzte-nv. Is it installed?"))
(mztenv.onInit))

View file

@ -1,9 +0,0 @@
-- 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, mztenv = pcall(require, "mzte_nv")
if not success then
error "Failed to preload mzte-nv. Is it installed?"
end
mztenv.onInit()

View file

@ -0,0 +1,2 @@
(set vim.g.neovide_transparency 0.9)
(set vim.g.neovide_cursor_vfx_mode :wireframe)

View file

@ -1,4 +0,0 @@
local g = vim.g
g.neovide_transparency = 0.9
g.neovide_cursor_vfx_mode = "wireframe"

View file

@ -12,6 +12,7 @@ nullls.setup {
nullls.builtins.formatting.black,
nullls.builtins.formatting.clang_format,
nullls.builtins.formatting.fish_indent,
nullls.builtins.formatting.fnlfmt,
nullls.builtins.formatting.prettier,
nullls.builtins.formatting.raco_fmt,
nullls.builtins.formatting.shfmt,

View file

@ -69,7 +69,9 @@ pub fn doCompile(path: []const u8, alloc: std.mem.Allocator) !void {
switch (entry.kind) {
.File => {
if (std.mem.endsWith(u8, entry.path, ".lua")) {
if (std.mem.endsWith(u8, entry.path, ".lua") or
std.mem.endsWith(u8, entry.path, ".fnl"))
{
try files.append(entry_path);
}
},
@ -81,17 +83,51 @@ pub fn doCompile(path: []const u8, alloc: std.mem.Allocator) !void {
}
for (files.items) |luafile| {
const luafile_z = try alloc.dupeZ(u8, luafile);
defer alloc.free(luafile_z);
var outname = try alloc.dupe(u8, luafile);
defer alloc.free(outname);
c.lua_getfield(l, -1, "dump");
if (c.luaL_loadfile(l, luafile_z) != 0) {
log.warn(
"error compiling lua object {s}: {s}",
.{ luafile, c.lua_tolstring(l, -1, null) },
);
c.lua_pop(l, 2);
continue;
if (std.mem.endsWith(u8, luafile, ".fnl")) {
// replace file extension
std.mem.copy(u8, outname[outname.len - 3 ..], "lua");
const res = try std.ChildProcess.exec(.{
.allocator = alloc,
.argv = &.{ "fennel", "-c", luafile },
});
defer alloc.free(res.stdout);
defer alloc.free(res.stderr);
if (!std.meta.eql(res.term, .{ .Exited = 0 })) {
log.warn("error compiling fennel object {s}: {s}", .{ luafile, res.stderr });
continue;
}
const luafile_z = try alloc.dupeZ(u8, luafile);
defer alloc.free(luafile_z);
if (c.luaL_loadbuffer(l, res.stdout.ptr, res.stdout.len, luafile_z) != 0) {
log.warn(
"error compiling fennel lua object {s}: {s}",
.{ luafile, c.lua_tolstring(l, -1, null) },
);
c.lua_pop(l, 2);
continue;
}
} else {
const luafile_z = try alloc.dupeZ(u8, luafile);
defer alloc.free(luafile_z);
if (c.luaL_loadfile(l, luafile_z) != 0) {
log.warn(
"error compiling lua object {s}: {s}",
.{ luafile, c.lua_tolstring(l, -1, null) },
);
c.lua_pop(l, 2);
continue;
}
}
c.lua_pushboolean(l, 1); // strip debug info
@ -100,7 +136,7 @@ pub fn doCompile(path: []const u8, alloc: std.mem.Allocator) !void {
var outlen: usize = 0;
const outptr = c.lua_tolstring(l, -1, &outlen);
var outfile = try std.fs.cwd().createFile(luafile, .{});
var outfile = try std.fs.cwd().createFile(outname, .{});
defer outfile.close();
try outfile.writeAll(outptr[0..outlen]);