marleyvim/modules/nixvim/plugins/base/snacks/default.nix

183 lines
5 KiB
Nix
Raw Normal View History

{
pkgs,
lib,
helpers,
...
}: let
inherit (helpers) mkRaw;
2024-11-25 19:05:18 -08:00
inherit (lib.marleyos) keys;
in {
2024-11-25 17:47:14 -08:00
extraPackages = [pkgs.lazygit];
2024-11-24 19:46:48 -08:00
plugins.snacks = {
enable = true;
settings = {
bigfile.enabled = true;
notifier.enabled = true;
quickfile.enabled = true;
statuscolumn.enabled = true;
words.enabled = true;
};
2024-11-24 19:46:48 -08:00
};
keymaps = [
2024-11-25 19:05:18 -08:00
(keys.mk ["n"] "<leader>un" (
mkRaw
# lua
"function() Snacks.notifier.hide() end"
) "Dismiss All Notifications")
2024-11-24 19:46:48 -08:00
2024-11-25 19:05:18 -08:00
(keys.mk ["n"] "<leader>bd" (
mkRaw
# lua
"function() Snacks.bufdelete() end"
) "Delete Buffer")
2024-11-24 19:46:48 -08:00
2024-11-25 19:05:18 -08:00
(keys.mk ["n"] "<leader>bo" (
mkRaw
# lua
"function() Snacks.bufdelete.other() end"
) "Delete Other Buffers")
2024-11-24 19:46:48 -08:00
# LazyGit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2024-11-25 19:05:18 -08:00
(keys.mk ["n"] "<leader>gg" (
mkRaw
# lua
"function() Snacks.lazygit() end"
) "Lazygit")
2024-11-24 19:46:48 -08:00
2024-11-25 19:05:18 -08:00
(keys.mk ["n"] "<leader>gf" (
mkRaw
# lua
"function() Snacks.lazygit.log_file() end"
) "Lazygit Current File History")
2024-11-24 19:46:48 -08:00
2024-11-25 19:05:18 -08:00
(keys.mk ["n"] "<leader>gl" (
mkRaw
# lua
"function() Snacks.lazygit.log() end"
) "Lazygit Log")
2024-11-24 19:46:48 -08:00
# Git - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2024-11-25 19:05:18 -08:00
(keys.mk ["n"] "<leader>gb" (
mkRaw
# lua
"function() Snacks.git.blame_line() end"
) "Git Blame Line")
2024-11-24 19:46:48 -08:00
2024-11-25 19:05:18 -08:00
(keys.mk ["n" "x"] "<leader>gB" (
mkRaw
# lua
"function() Snacks.gitbrowse() end"
) "Git Browse")
2024-11-24 19:46:48 -08:00
];
# Toggles - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2024-11-25 17:47:14 -08:00
extraConfigLua =
# lua
2024-11-24 19:46:48 -08:00
''
---@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")
'';
}