marleyvim/modules/nixvim/plugins/base/snacks/default.nix
2024-11-24 19:46:48 -08:00

207 lines
5.4 KiB
Nix

{ pkgs, ... }:
{
extraPackages = [ pkgs.lazygit ];
plugins.snacks = {
enable = true;
bigfile.enabled = true;
notifier.enabled = true;
quickfile.enabled = true;
statuscolumn.enabled = true;
words.enabled = true;
};
keymaps = [
{
mode = [ "n" ];
key = "<leader>un";
action.__raw = # lua
"function() Snacks.notifier.hide() end";
options = {
desc = "Dismiss All Notifications";
};
}
{
mode = [ "n" ];
key = "<leader>bd";
action.__raw = # lua
"function() Snacks.bufdelete() end";
options = {
desc = "Delete Buffer";
};
}
{
mode = [ "n" ];
key = "<leader>bo";
action.__raw = # lua
"function() Snacks.bufdelete.other() end";
options = {
desc = "Delete Other Buffers";
};
}
# LazyGit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{
mode = [ "n" ];
key = "<leader>gg";
action.__raw = # lua
"function() Snacks.lazygit() end";
options = {
desc = "Lazygit";
};
}
{
mode = [ "n" ];
key = "<leader>gf";
action.__raw = # lua
"function() Snacks.lazygit.log_file() end";
options = {
desc = "Lazygit Current File History";
};
}
{
mode = [ "n" ];
key = "<leader>gl";
action.__raw = # lua
"function() Snacks.lazygit.log() end";
options = {
desc = "Lazygit Log";
};
}
# Git - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{
mode = [ "n" ];
key = "<leader>gb";
action.__raw = # lua
"function() Snacks.git.blame_line() end";
options = {
desc = "Gib Blame Line";
};
}
{
mode = [
"n"
"x"
];
key = "<leader>gB";
action.__raw = # lua
"function() Snacks.gitbrowse() end";
options = {
desc = "Git Browse";
};
}
];
# Toggles - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
extraConfigLua = # lua
''
---@param buf? number
function format_enabled(buf)
buf = (buf == nil or buf == 0) and vim.api.nvim_get_current_buf() or buf
local gaf = vim.g.autoformat
local baf = vim.b[buf].autoformat
-- If the buffer has a local value, use that
if baf ~= nil then
return baf
end
-- Otherwise use the global value if set, or true by default
return gaf == nil or gaf
end
---@param enable? boolean
---@param buf? boolean
function format_enable(state, buf)
if enable == nil then
enable = true
end
if buf then
vim.b.autoformat = enable
else
vim.g.autoformat = enable
vim.b.autoformat = nil
end
end
---@param buf? boolean
function toggle_format(buf)
return Snacks.toggle({
name = "Auto Format (" .. (buf and "Buffer" or "Global") .. ")",
get = function()
if not buf then
return vim.g.autoformat == nil or vim.g.autoformat
end
return format_enabled()
end,
set = function(state)
format_enable(state, buf)
end,
})
end
toggle_format():map("<leader>uf")
toggle_format(true):map("<leader>uF")
Snacks.toggle.option("spell", { name = "Spelling"}):map("<leader>us")
Snacks.toggle.option("wrap", {name = "Wrap"}):map("<leader>uw")
Snacks.toggle.option("relativenumber", { name = "Relative Number"}):map("<leader>uL")
Snacks.toggle.diagnostics():map("<leader>ud")
Snacks.toggle.line_number():map("<leader>ul")
Snacks.toggle.option("conceallevel", {off = 0, on = vim.o.conceallevel > 0 and vim.o.conceallevel or 2}):map("<leader>uc")
Snacks.toggle.treesitter():map("<leader>uT")
Snacks.toggle.option("background", { off = "light", on = "dark" , name = "Dark Background"}):map("<leader>ub")
if vim.lsp.inlay_hint then
Snacks.toggle.inlay_hints():map("<leader>uh")
end
function maximize_window()
---@type {k:string, v:any}[]?
local maximized = nil
return Snacks.toggle({
name = "Maximize",
get = function()
return maximized ~= nil
end,
set = function(state)
if state then
maximized = {}
local function set(k, v)
table.insert(maximized, 1, { k = v, v = vim.o[k] })
vim.o[k] = v
end
set("winwidth", 999)
set("winheight", 999)
set("winminwidth", 10)
set("winminheight", 4)
vim.cmd("wincmd =")
vim.api.nvim_create_autocmd("ExitPre", {
once = true,
group = vim.api.nvim_create_augroup("marleyvim_restore_max_exit_pre", { clear = true }),
desc = "Restore width/height when closing Neovim while maximized",
callback = function()
maximize_window.set(false)
end,
})
else
for _, opt in ipairs(maximized) do
vim.o[opt.k] = opt.v
end
maximized = nil
vim.cmd("wincmd =")
end
end,
})
end
maximize_window():map("<leader>wm")
'';
}