feat: improve stuff

This commit is contained in:
2024-06-12 15:30:56 +02:00
parent 2f5f6de2cd
commit de983e8f6d
4 changed files with 63 additions and 37 deletions

View File

@@ -5,14 +5,7 @@ in
{ {
options.presets.auto-save = { options.presets.auto-save = {
enable = lib.mkEnableOption "auto save"; enable = lib.mkEnableOption "auto save";
varName = lib.mkOption { disableOnStart = lib.mkEnableOption "disable auto save on start";
type = lib.types.str;
default = "disable_autosave";
};
commandName = lib.mkOption {
type = lib.types.str;
default = "AutoSaveToggle";
};
event = lib.mkOption { event = lib.mkOption {
type = lib.types.listOf lib.types.str; type = lib.types.listOf lib.types.str;
default = [ default = [
@@ -25,15 +18,18 @@ in
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
extraConfigLua = # lua extraConfigLua = # lua
'' ''
function AutoSave() function PerformAutoSave(buf)
if not vim.b.${cfg.varName} and not vim.g.${cfg.varName} then buf = buf or vim.api.nvim_get_current_buf()
local bufnr = vim.api.nvim_get_current_buf()
local modified = vim.api.nvim_buf_get_option(bufnr, 'modified') if vim.b.disable_autosave or vim.g.disable_autosave then return end
if modified then if vim.fn.getbufvar(buf, "&modifiable") ~= 1 then return end
if not vim.api.nvim_buf_get_option(buf, 'modified') then return end
if vim.api.nvim_buf_get_option(buf, 'buftype') ~= "" then return end
vim.api.nvim_buf_call(buf, function()
vim.cmd('silent! w') vim.cmd('silent! w')
print("Auto save at " .. os.date("%H:%M:%S")) print("Auto save at " .. os.date("%H:%M:%S"))
end end)
end
end end
''; '';
@@ -41,19 +37,22 @@ in
{ {
event = cfg.event; event = cfg.event;
pattern = [ "*" ]; pattern = [ "*" ];
command = "lua AutoSave()"; callback.__raw = # lua
"function(args) PerformAutoSave(args.buf) end";
} }
]; ];
userCommands.${cfg.commandName} = { globals.disable_autosave = cfg.disableOnStart;
userCommands.ToggleAutoSave = {
bang = true; bang = true;
command.__raw = # lua command.__raw = # lua
'' ''
function(args) function(args)
if args.bang then if args.bang then
vim.b.${cfg.varName} = not vim.b.${cfg.varName} vim.b.disable_autosave = not vim.b.disable_autosave
else else
vim.g.${cfg.varName} = not vim.g.${cfg.varName} vim.g.disable_autosave = not vim.g.disable_autosave
end end
local lualine, lib = pcall(require, 'lualine') local lualine, lib = pcall(require, 'lualine')
if lualine then if lualine then
@@ -68,13 +67,13 @@ in
key = "<leader>as"; key = "<leader>as";
mode = "n"; mode = "n";
options.silent = true; options.silent = true;
action = "<cmd>:${cfg.commandName}<CR>"; action = "<cmd>:ToggleAutoSave<CR>";
} }
{ {
key = "<leader>aS"; key = "<leader>aS";
mode = "n"; mode = "n";
options.silent = true; options.silent = true;
action = "<cmd>:${cfg.commandName}!<CR>"; action = "<cmd>:ToggleAutoSave!<CR>";
} }
]; ];
@@ -87,15 +86,12 @@ in
}; };
}; };
neo-tree.eventHandlers.window_before_open = # lua /*neo-tree.eventHandlers.window_before_open = # lua
'' "function() PerformAutoSave() end";*/
function()
AutoSave()
end
'';
lualine.sections.lualine_x = lib.mkOrder 700 [ lualine.sections.lualine_x = lib.mkOrder 700 [
"(vim.g.${cfg.varName} or vim.b.${cfg.varName}) and '󱙃' or nil" # lua
"(vim.g.disable_autosave or vim.b.disable_autosave) and '󱙃' or nil"
]; ];
}; };
}; };

View File

@@ -87,7 +87,6 @@ in
R = "Restart LSP"; R = "Restart LSP";
d = "Definitions"; d = "Definitions";
i = "Implementations"; i = "Implementations";
s = "Document Symbols";
w = "Workspace Symbols"; w = "Workspace Symbols";
t = "Type Definitions"; t = "Type Definitions";
h = "Diagnostics"; h = "Diagnostics";

View File

@@ -13,6 +13,10 @@ in
key = "<leader>ft"; key = "<leader>ft";
action = "<cmd>:Neotree toggle<CR>"; action = "<cmd>:Neotree toggle<CR>";
} }
{
key = "<leader>ss";
action = "<cmd>:Neotree document_symbols right toggle<CR>";
}
]; ];
plugins = { plugins = {
neo-tree = { neo-tree = {
@@ -22,15 +26,19 @@ in
followCurrentFile.enabled = true; followCurrentFile.enabled = true;
filteredItems.visible = true; filteredItems.visible = true;
}; };
extraSources = [ "document_symbols" ];
popupBorderStyle = "rounded"; popupBorderStyle = "rounded";
eventHandlers.file_opened = # lua eventHandlers.neo_tree_buffer_leave = # lua
'' ''
function() function()
require('neo-tree').close_all() require('neo-tree').close_all()
end end
''; '';
}; };
which-key.registrations."<leader>f".t = "Tree"; which-key.registrations = {
"<leader>f".t = "Tree";
"<leader>s".s = "Document Symbols";
};
}; };
}; };
} }

View File

@@ -44,6 +44,9 @@ end
hi! Pmenu ctermbg=none guibg=none guifg={{colors.on_surface.default.hex}} hi! Pmenu ctermbg=none guibg=none guifg={{colors.on_surface.default.hex}}
hi! PmenuSel guibg={{colors.primary.default.hex}} guifg={{colors.on_primary.default.hex}} hi! PmenuSel guibg={{colors.primary.default.hex}} guifg={{colors.on_primary.default.hex}}
hi! PmenuThumb guifg=none guifg={{colors.primary.default.hex}}
hi! link NormalFloat Normal
hi! FloatBorder guifg={{colors.primary.default.hex}}
hi! CursorColumn guibg={{colors.primary.default.hex}} guifg={{colors.on_primary.default.hex}} hi! CursorColumn guibg={{colors.primary.default.hex}} guifg={{colors.on_primary.default.hex}}
hi! CursorLine guibg={{colors.primary.default.hex}} guifg={{colors.on_primary.default.hex}} hi! CursorLine guibg={{colors.primary.default.hex}} guifg={{colors.on_primary.default.hex}}
hi! WildMenu guibg={{colors.primary.default.hex}} guifg={{colors.on_primary.default.hex}} hi! WildMenu guibg={{colors.primary.default.hex}} guifg={{colors.on_primary.default.hex}}
@@ -109,9 +112,9 @@ hi! NeoTreeGitConflict guifg={{colors.danger.default.hex}}
hi! NeoTreeGitUntracked guifg={{colors.blue.default.hex}} hi! NeoTreeGitUntracked guifg={{colors.blue.default.hex}}
hi! NonText guifg={{colors.outline_variant.default.hex}} hi! NonText guifg={{colors.outline_variant.default.hex}}
hi! LineNr guifg={{colors.outline_variant.default.hex}}
hi! CursorLineNr guifg={{colors.on_surface.default.hex}} hi! CursorLineNr guifg={{colors.on_surface.default.hex}}
hi! SignColumn guibg=none guifg={{colors.on_surface.default.hex}} hi! SignColumn guibg=none guifg={{colors.on_surface.default.hex}}
hi! LineNr guifg={{colors.secondary.default.hex}}
hi! IblScope guifg={{colors.on_surface.default.hex}} hi! IblScope guifg={{colors.on_surface.default.hex}}
hi! @ibl.scope.char.1 guifg={{colors.on_surface.default.hex}} hi! @ibl.scope.char.1 guifg={{colors.on_surface.default.hex}}
@@ -129,7 +132,9 @@ hi! @variable guifg={{colors.on_surface.default.hex}}
hi! Operator guifg={{colors.on_surface.default.hex}} hi! Operator guifg={{colors.on_surface.default.hex}}
hi! Delimiter guifg={{colors.on_surface.default.hex}} hi! Delimiter guifg={{colors.on_surface.default.hex}}
hi! Statement gui=bold guifg={{colors.on_surface.default.hex}} hi! Statement gui=bold guifg={{colors.on_surface.default.hex}}
hi! link Operator Normal hi! link Operator Normal
hi! link @punctuation.special @punctuation
hi! @conditional.ternary guifg={{colors.on_surface.default.hex}} hi! @conditional.ternary guifg={{colors.on_surface.default.hex}}
hi! link @keyword.conditional.ternary Operator hi! link @keyword.conditional.ternary Operator
hi! link Delimiter Normal hi! link Delimiter Normal
@@ -140,6 +145,11 @@ hi! @lsp.mod.defaultLibrary gui=bold
hi! @lsp.mod.readonly gui=italic hi! @lsp.mod.readonly gui=italic
hi! Constant guifg={{colors.constants.default.hex}} hi! Constant guifg={{colors.constants.default.hex}}
hi! link @variable Constant
hi! link @variable.parameter Identifier
hi! link @lsp.typemod.variable.local Identifier
hi! link @variable.python Identifier
hi! link @variable.lua Identifier
hi! @property guifg={{colors.properties.default.hex}} hi! @property guifg={{colors.properties.default.hex}}
hi! link @field @property hi! link @field @property
@@ -151,9 +161,6 @@ hi! link @lsp.type.property @property
hi! link @attribute @property hi! link @attribute @property
hi! link @tag.attribute @property hi! link @tag.attribute @property
hi! link @lsp.type.variable Constant
hi! link @lsp.typemod.variable.local Identifier
hi! Keyword guifg={{colors.keywords.default.hex}} hi! Keyword guifg={{colors.keywords.default.hex}}
hi! Special guifg={{colors.keywords.default.hex}} hi! Special guifg={{colors.keywords.default.hex}}
hi! link Character Keyword hi! link Character Keyword
@@ -165,6 +172,17 @@ hi! link Include Keyword
hi! link Conditional Keyword hi! link Conditional Keyword
hi! link @type.builtin Keyword hi! link @type.builtin Keyword
hi! link NotifyERRORIcon NotifyERRORBorder
hi! link NotifyWARNIcon NotifyWARNBorder
hi! link NotifyINFOIcon NotifyINFOBorder
hi! link NotifyTRACEIcon NotifyTRACEBorder
hi! link NotifyDEBUGIcon NotifyDEBUGBorder
hi! link NotifyERRORTitle NotifyERRORBorder
hi! link NotifyWARNTitle NotifyWARNBorder
hi! link NotifyINFOTitle NotifyINFOBorder
hi! link NotifyTRACETitle NotifyTRACEBorder
hi! link NotifyDEBUGTitle NotifyDEBUGBorder
hi! Number guifg={{colors.numbers.default.hex}} hi! Number guifg={{colors.numbers.default.hex}}
hi! Function guifg={{colors.functions.default.hex}} hi! Function guifg={{colors.functions.default.hex}}
@@ -172,6 +190,11 @@ hi! Structure guifg={{colors.structures.default.hex}}
hi! link PreProc Structure hi! link PreProc Structure
hi! link Tag Structure hi! link Tag Structure
hi! link @attribute.typescript Structure hi! link @attribute.typescript Structure
hi! link @lsp.type.decorator Structure
hi! link @lsp.type.attributeBracket Structure
hi! link @keyword.directive.cpp PreProc
hi! link @keyword.directive.define.cpp PreProc
hi! link @keyword.import.cpp PreProc
hi! Type gui=none guifg={{colors.types.default.hex}} hi! Type gui=none guifg={{colors.types.default.hex}}
hi! link @lsp.type.interface Type hi! link @lsp.type.interface Type