mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-06-14 17:29:00 +02:00
rewrite a bit of nvim config in fennel
This commit is contained in:
parent
72eb90a939
commit
6de6a9d44c
8
mzte-nv/conf/filetype.fnl
Normal file
8
mzte-nv/conf/filetype.fnl
Normal 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}})
|
|
@ -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
7
mzte-nv/conf/init.fnl
Normal file
|
@ -0,0 +1,7 @@
|
|||
(require :mzte_nv_preloader)
|
||||
|
||||
(require :plugins)
|
||||
(require :settings)
|
||||
(require :maps)
|
||||
(require :neovide)
|
||||
(require :pipe)
|
|
@ -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
40
mzte-nv/conf/lua/maps.fnl
Normal 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})
|
|
@ -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 })
|
8
mzte-nv/conf/lua/mzte_nv_preloader.fnl
Normal file
8
mzte-nv/conf/lua/mzte_nv_preloader.fnl
Normal 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))
|
|
@ -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()
|
2
mzte-nv/conf/lua/neovide.fnl
Normal file
2
mzte-nv/conf/lua/neovide.fnl
Normal file
|
@ -0,0 +1,2 @@
|
|||
(set vim.g.neovide_transparency 0.9)
|
||||
(set vim.g.neovide_cursor_vfx_mode :wireframe)
|
|
@ -1,4 +0,0 @@
|
|||
local g = vim.g
|
||||
|
||||
g.neovide_transparency = 0.9
|
||||
g.neovide_cursor_vfx_mode = "wireframe"
|
|
@ -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,
|
||||
|
|
|
@ -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]);
|
||||
|
||||
|
|
Loading…
Reference in a new issue