2024-11-25 18:29:33 -08:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
helpers,
|
|
|
|
...
|
|
|
|
}: let
|
|
|
|
inherit (helpers) mkRaw;
|
2024-11-25 20:33:41 -08:00
|
|
|
inherit (lib.marleyvim) keys;
|
2024-11-25 18:29:33 -08:00
|
|
|
in {
|
2024-11-25 17:47:14 -08:00
|
|
|
extraPackages = [pkgs.lazygit];
|
2024-11-24 19:46:48 -08:00
|
|
|
|
|
|
|
plugins.snacks = {
|
|
|
|
enable = true;
|
|
|
|
|
2024-11-24 20:08:54 -08:00
|
|
|
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 21:23:29 -08:00
|
|
|
(keys.mk ["n"] "<LEADER>un" (
|
2024-11-26 20:50:32 -08:00
|
|
|
mkRaw ''
|
|
|
|
function() Snacks.notifier.hide() end
|
|
|
|
''
|
2024-11-25 18:29:33 -08:00
|
|
|
) "Dismiss All Notifications")
|
2024-11-24 19:46:48 -08:00
|
|
|
|
2024-11-25 21:23:29 -08:00
|
|
|
(keys.mk ["n"] "<LEADER>bd" (
|
2024-11-26 20:50:32 -08:00
|
|
|
mkRaw ''
|
|
|
|
function() Snacks.bufdelete() end
|
|
|
|
''
|
2024-11-25 18:29:33 -08:00
|
|
|
) "Delete Buffer")
|
2024-11-24 19:46:48 -08:00
|
|
|
|
2024-11-25 21:23:29 -08:00
|
|
|
(keys.mk ["n"] "<LEADER>bo" (
|
2024-11-26 20:50:32 -08:00
|
|
|
mkRaw ''
|
|
|
|
function() Snacks.bufdelete.other() end
|
|
|
|
''
|
2024-11-25 18:29:33 -08:00
|
|
|
) "Delete Other Buffers")
|
2024-11-24 19:46:48 -08:00
|
|
|
|
|
|
|
# LazyGit - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2024-11-25 21:23:29 -08:00
|
|
|
(keys.mk ["n"] "<LEADER>gg" (
|
2024-11-26 20:50:32 -08:00
|
|
|
mkRaw ''
|
|
|
|
function() Snacks.lazygit() end
|
|
|
|
''
|
2024-11-25 18:29:33 -08:00
|
|
|
) "Lazygit")
|
2024-11-24 19:46:48 -08:00
|
|
|
|
2024-11-25 21:23:29 -08:00
|
|
|
(keys.mk ["n"] "<LEADER>gf" (
|
2024-11-26 20:50:32 -08:00
|
|
|
mkRaw ''
|
|
|
|
function() Snacks.lazygit.log_file() end
|
|
|
|
''
|
2024-11-25 18:29:33 -08:00
|
|
|
) "Lazygit Current File History")
|
2024-11-24 19:46:48 -08:00
|
|
|
|
2024-11-25 21:23:29 -08:00
|
|
|
(keys.mk ["n"] "<LEADER>gl" (
|
2024-11-26 20:50:32 -08:00
|
|
|
mkRaw ''
|
|
|
|
function() Snacks.lazygit.log() end
|
|
|
|
''
|
2024-11-25 18:29:33 -08:00
|
|
|
) "Lazygit Log")
|
2024-11-24 19:46:48 -08:00
|
|
|
|
|
|
|
# Git - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
2024-11-25 21:23:29 -08:00
|
|
|
(keys.mk ["n"] "<LEADER>gb" (
|
2024-11-26 20:50:32 -08:00
|
|
|
mkRaw ''
|
|
|
|
function() Snacks.git.blame_line() end
|
|
|
|
''
|
2024-11-25 18:29:33 -08:00
|
|
|
) "Git Blame Line")
|
2024-11-24 19:46:48 -08:00
|
|
|
|
2024-11-25 21:23:29 -08:00
|
|
|
(keys.mk ["n" "x"] "<LEADER>gB" (
|
2024-11-26 20:50:32 -08:00
|
|
|
mkRaw ''
|
|
|
|
function() Snacks.gitbrowse() end
|
|
|
|
''
|
2024-11-25 21:11:18 -08:00
|
|
|
) "Git Browse (open)")
|
|
|
|
|
2024-11-26 20:50:32 -08:00
|
|
|
(keys.mk ["n" "x"] "<LEADER>gY" (
|
|
|
|
mkRaw ''
|
2024-11-25 21:11:18 -08:00
|
|
|
function()
|
|
|
|
Snacks.gitbrowse({ open = function(url) vim.fn.setreg("+", url) end })
|
|
|
|
end
|
2024-11-26 20:50:32 -08:00
|
|
|
''
|
|
|
|
) "Git Browse (copy)")
|
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
|
|
|
|
|
2024-11-25 21:23:29 -08:00
|
|
|
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")
|
2024-11-24 19:46:48 -08:00
|
|
|
if vim.lsp.inlay_hint then
|
2024-11-25 21:23:29 -08:00
|
|
|
Snacks.toggle.inlay_hints():map("<LEADER>uh")
|
2024-11-24 19:46:48 -08:00
|
|
|
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
|
|
|
|
|
2024-11-25 21:23:29 -08:00
|
|
|
maximize_window():map("<LEADER>wm")
|
2024-11-24 19:46:48 -08:00
|
|
|
'';
|
|
|
|
}
|