Compare commits

...

2 commits

Author SHA1 Message Date
af7eb4bf7e
feat: Bufferline 2024-11-26 20:58:00 -08:00
8efea03163
fix: Proper injection queries 2024-11-26 20:50:32 -08:00
6 changed files with 220 additions and 124 deletions

10
lib/icons/default.nix Normal file
View file

@ -0,0 +1,10 @@
_: {
icons = {
diagnostics = {
error = " ";
warn = " ";
hint = " ";
info = " ";
};
};
}

View file

@ -23,51 +23,43 @@ in {
]; ];
autoCmd = [ autoCmd = [
(autocmds.mk' ["FocusGained" "TermClose" "TermLeave"] "checktime" (mkRaw (autocmds.mk' ["FocusGained" "TermClose" "TermLeave"] "checktime" (mkRaw ''
# lua function()
'' if vim.o.buftype ~= "nofile" then
function() vim.cmd("checktime")
if vim.o.buftype ~= "nofile" then
vim.cmd("checktime")
end
end end
'') "Check if file needs to be reloaded when changed") end
'') "Check if file needs to be reloaded when changed")
(autocmds.mk' ["TextYankPost"] "highlight_yank" (mkRaw (autocmds.mk' ["TextYankPost"] "highlight_yank" (mkRaw ''
# lua function()
'' (vim.hl or vim.highlight).on_yank()
function() end
(vim.hl or vim.highlight).on_yank() '') "Highlight on yank")
end
'') "Highlight on yank")
(autocmds.mk' ["VimResized"] "resize_splits" (mkRaw (autocmds.mk' ["VimResized"] "resize_splits" (mkRaw ''
# lua function()
'' local current_tab = vim.fn.tabpagenr()
function() vim.cmd("tabdo wincmd =")
local current_tab = vim.fn.tabpagenr() vim.cmd("tabnext " .. current_tab)
vim.cmd("tabdo wincmd =") end
vim.cmd("tabnext " .. current_tab) '') "Resize splits on window resize")
end
'') "Resize splits on window resize")
(autocmds.mk' ["BufReadPost"] "last_loc" (mkRaw (autocmds.mk' ["BufReadPost"] "last_loc" (mkRaw ''
# lua function(event)
'' local exclude = { "gitcommit" }
function(event) local buf = event.buf
local exclude = { "gitcommit" } if vim.tbl_contains(exclude, vim.bo[buf].filetype) or vim.b[buf].marleyvim_last_loc then
local buf = event.buf return
if vim.tbl_contains(exclude, vim.bo[buf].filetype) or vim.b[buf].marleyvim_last_loc then
return
end
vim.b[buf].marleyvim_last_loc = true
local mark = vim.api.nvim_buf_get_mark(buf, '"')
local lcount = vim.api.nvim_buf_line_count(buf)
if mark[1] > 0 and mark[1] <= lcount then
pcall(vim.api.nvim_win_set_cursor, 0, mark)
end
end end
'') "Go to last location when opening a buffer") vim.b[buf].marleyvim_last_loc = true
local mark = vim.api.nvim_buf_get_mark(buf, '"')
local lcount = vim.api.nvim_buf_line_count(buf)
if mark[1] > 0 and mark[1] <= lcount then
pcall(vim.api.nvim_win_set_cursor, 0, mark)
end
end
'') "Go to last location when opening a buffer")
(autocmds.mk ["FileType"] "close_with_q" [ (autocmds.mk ["FileType"] "close_with_q" [
"PlenaryTestPopup" "PlenaryTestPopup"
@ -86,31 +78,27 @@ in {
"spectre_panel" "spectre_panel"
"startuptime" "startuptime"
"tsplayground" "tsplayground"
] (mkRaw ] (mkRaw ''
# lua
''
function(event)
vim.bo[event.buf].buflisted = false
vim.schedule(function()
vim.keymap.set("n", "q", function()
vim.cmd("close")
pcall(vim.api.nvim_buf_delete, event.buf, { force = true })
end, {
buffer = event.buf,
silent = true,
desc = "Quit buffer",
})
end)
end
'') "Close some filetypes with <q>")
(autocmds.mk ["FileType"] "man_unlisted" ["man"] (mkRaw
# lua
''
function(event) function(event)
vim.bo[event.buf].buflisted = false vim.bo[event.buf].buflisted = false
vim.schedule(function()
vim.keymap.set("n", "q", function()
vim.cmd("close")
pcall(vim.api.nvim_buf_delete, event.buf, { force = true })
end, {
buffer = event.buf,
silent = true,
desc = "Quit buffer",
})
end)
end end
'') "Easy-close man files") '') "Close some filetypes with <q>")
(autocmds.mk ["FileType"] "man_unlisted" ["man"] (mkRaw ''
function(event)
vim.bo[event.buf].buflisted = false
end
'') "Easy-close man files")
(autocmds.mk ["FileType"] "wrap_spell" [ (autocmds.mk ["FileType"] "wrap_spell" [
"text" "text"
@ -118,33 +106,27 @@ in {
"typst" "typst"
"gitcommit" "gitcommit"
"markdown" "markdown"
] (mkRaw ] (mkRaw ''
# lua
''
function()
vim.opt_local.wrap = true
vim.opt_local.spell = true
end
'') "Wrap & check spelling in text files")
(autocmds.mk ["FileType"] "json_conceal" ["json" "jsonc" "json5"] (mkRaw
# lua
''
function() function()
vim.opt_local.conceallevel = 0 vim.opt_local.wrap = true
vim.opt_local.spell = true
end end
'') "Fix conceallevel for json files") '') "Wrap & check spelling in text files")
(autocmds.mk' ["BufWritePre"] "auto_create_dir" (mkRaw (autocmds.mk ["FileType"] "json_conceal" ["json" "jsonc" "json5"] (mkRaw ''
# lua function()
'' vim.opt_local.conceallevel = 0
function(event) end
if event.match:match("^%w%w+:[\\/][\\/]") then '') "Fix conceallevel for json files")
return
end (autocmds.mk' ["BufWritePre"] "auto_create_dir" (mkRaw ''
local file = vim.uv.fs_realpath(event.match) or event.match function(event)
vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p") if event.match:match("^%w%w+:[\\/][\\/]") then
return
end end
'') "Auto create missing parent dirs when saving") local file = vim.uv.fs_realpath(event.match) or event.match
vim.fn.mkdir(vim.fn.fnamemodify(file, ":p:h"), "p")
end
'') "Auto create missing parent dirs when saving")
]; ];
} }

View file

@ -165,9 +165,9 @@ in {
# Diagnostics - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Diagnostics - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
++ [ ++ [
(keys.mk ["n"] "<LEADER>cd" ( (keys.mk ["n"] "<LEADER>cd" (
mkRaw mkRaw ''
# lua function() vim.diagnostic.open_float() end
"function() vim.diagnostic.open_float() end" ''
) "Line Diagnostics") ) "Line Diagnostics")
] ]
++ ( ++ (
@ -200,13 +200,11 @@ in {
cmd = toLower dir; cmd = toLower dir;
sev = sevs."${key}".key; sev = sevs."${key}".key;
in in
keys.mk ["n"] kmap keys.mk ["n"] kmap (
( mkRaw ''
mkRaw function() vim.diagnostic.goto_${cmd}({ severity = ${sev} }) end
# lua ''
"function() vim.diagnostic.goto_${cmd}({ severity = ${sev} }) end" ) "${dir} ${sevs."${key}".desc}"
)
"${dir} ${sevs."${key}".desc}"
) )
{ {
dir = ["Next" "Prev"]; dir = ["Next" "Prev"];

View file

@ -0,0 +1,98 @@
{
lib,
helpers,
...
}: let
inherit (lib) flatten mapAttrsToList map;
inherit (lib.marleyvim) icons keys autocmds;
inherit (helpers) mkRaw;
in {
plugins.bufferline = {
enable = true;
settings = {
options = {
close_command.__raw = "function(n) Snacks.bufdelete(n) end";
right_mouse_command.__raw = "function(n) Snacks.bufdelete(n) end";
diagnostics = "nvim_lsp";
diagnostics_indicator.__raw =
# lua
''
function(_, _, diag)
local ret = (diag.error and "${icons.diagnostics.error}" .. diag.error .. " " or "")
.. (diag.warning and "${icons.diagnostics.warn}" .. diag.warning or "")
return vim.trim(ret)
end
'';
always_show_bufferline = true;
offsets = [
{
filetype = "neo-tree";
text = "Explorer";
highlight = "Directory";
text_align = "left";
}
];
get_element_icon.__raw = ''
function(elem)
local icon, hl, _ =
require('mini.icons').get('filetype', elem.filetype)
return icon, hl
end
'';
};
};
};
autoGroups.marleyos_bufferline.clear = true;
autoCmd = [
(autocmds.mk' ["BufAdd" "BufDelete"] "bufferline" (
mkRaw ''
function()
vim.schedule(function()
pcall(nvim_bufferline)
end)
end
''
) "Fix bufferline when restoring a session")
];
keymaps =
[
(keys.mk ["n"] "<LEADER>bp" "<CMD>BufferLineTogglePin<CR>" "Toggle Pin")
(keys.mk ["n"] "<LEADER>bP" "<CMD>BufferLineGroupClose ungrouped<CR>"
"Delete Non-Pinned Buffers")
(keys.mk ["n"] "<LEADER>br" "<CMD>BufferLineCloseRight<CR>"
"Delete Buffers to the Right")
(keys.mk ["n"] "<LEADER>bl" "<CMD>BufferLineCloseLeft<CR>"
"Delete Buffers to the Left")
(keys.mk ["n"] "<S-H>" "<CMD>BufferLineCyclePrev<CR>" "Prev Buffer")
(keys.mk ["n"] "<S-L>" "<CMD>BufferLineCycleNext<CR>" "Next Buffer")
]
++ (flatten (mapAttrsToList (
a: ks:
map (k: keys.mk ["n"] k "<CMD>BufferLineCycle${a}<CR>" "${a} Buffer") ks
) {
Prev = ["<S-H>" "[b"];
Next = ["<S-L>" "]b"];
}))
++ (
mapAttrsToList (
a: k: let
befAft =
if (a == "Prev")
then "After"
else "Before";
in
keys.mk ["n"] "${k}B" "<CMD>BufferLineMove${a}<CR>"
"Move Buffer ${befAft} ${a}"
) {
Prev = "[";
After = "]";
}
);
}

View file

@ -0,0 +1,8 @@
_: {
plugins.mini = {
enable = true;
mockDevIcons = true;
modules.icons = {};
};
}

View file

@ -23,62 +23,62 @@ in {
keymaps = [ keymaps = [
(keys.mk ["n"] "<LEADER>un" ( (keys.mk ["n"] "<LEADER>un" (
mkRaw mkRaw ''
# lua function() Snacks.notifier.hide() end
"function() Snacks.notifier.hide() end" ''
) "Dismiss All Notifications") ) "Dismiss All Notifications")
(keys.mk ["n"] "<LEADER>bd" ( (keys.mk ["n"] "<LEADER>bd" (
mkRaw mkRaw ''
# lua function() Snacks.bufdelete() end
"function() Snacks.bufdelete() end" ''
) "Delete Buffer") ) "Delete Buffer")
(keys.mk ["n"] "<LEADER>bo" ( (keys.mk ["n"] "<LEADER>bo" (
mkRaw mkRaw ''
# lua function() Snacks.bufdelete.other() end
"function() Snacks.bufdelete.other() end" ''
) "Delete Other Buffers") ) "Delete Other Buffers")
# LazyGit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # LazyGit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(keys.mk ["n"] "<LEADER>gg" ( (keys.mk ["n"] "<LEADER>gg" (
mkRaw mkRaw ''
# lua function() Snacks.lazygit() end
"function() Snacks.lazygit() end" ''
) "Lazygit") ) "Lazygit")
(keys.mk ["n"] "<LEADER>gf" ( (keys.mk ["n"] "<LEADER>gf" (
mkRaw mkRaw ''
# lua function() Snacks.lazygit.log_file() end
"function() Snacks.lazygit.log_file() end" ''
) "Lazygit Current File History") ) "Lazygit Current File History")
(keys.mk ["n"] "<LEADER>gl" ( (keys.mk ["n"] "<LEADER>gl" (
mkRaw mkRaw ''
# lua function() Snacks.lazygit.log() end
"function() Snacks.lazygit.log() end" ''
) "Lazygit Log") ) "Lazygit Log")
# Git - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Git - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(keys.mk ["n"] "<LEADER>gb" ( (keys.mk ["n"] "<LEADER>gb" (
mkRaw mkRaw ''
# lua function() Snacks.git.blame_line() end
"function() Snacks.git.blame_line() end" ''
) "Git Blame Line") ) "Git Blame Line")
(keys.mk ["n" "x"] "<LEADER>gB" ( (keys.mk ["n" "x"] "<LEADER>gB" (
mkRaw mkRaw ''
# lua function() Snacks.gitbrowse() end
"function() Snacks.gitbrowse() end" ''
) "Git Browse (open)") ) "Git Browse (open)")
(keys.mk ["n" "x"] "<LEADER>gY" (mkRaw (keys.mk ["n" "x"] "<LEADER>gY" (
# lua mkRaw ''
''
function() function()
Snacks.gitbrowse({ open = function(url) vim.fn.setreg("+", url) end }) Snacks.gitbrowse({ open = function(url) vim.fn.setreg("+", url) end })
end end
'') "Git Browse (copy)") ''
) "Git Browse (copy)")
]; ];
# Toggles - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # Toggles - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -