mirror of
https://github.com/Theaninova/TheaninovOS.git
synced 2025-12-12 11:36:20 +00:00
feat: improve stuff
This commit is contained in:
@@ -5,14 +5,7 @@ in
|
||||
{
|
||||
options.presets.auto-save = {
|
||||
enable = lib.mkEnableOption "auto save";
|
||||
varName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "disable_autosave";
|
||||
};
|
||||
commandName = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "AutoSaveToggle";
|
||||
};
|
||||
disableOnStart = lib.mkEnableOption "disable auto save on start";
|
||||
event = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [
|
||||
@@ -25,15 +18,18 @@ in
|
||||
config = lib.mkIf cfg.enable {
|
||||
extraConfigLua = # lua
|
||||
''
|
||||
function AutoSave()
|
||||
if not vim.b.${cfg.varName} and not vim.g.${cfg.varName} then
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local modified = vim.api.nvim_buf_get_option(bufnr, 'modified')
|
||||
if modified then
|
||||
vim.cmd('silent! w')
|
||||
print("Auto save at " .. os.date("%H:%M:%S"))
|
||||
end
|
||||
end
|
||||
function PerformAutoSave(buf)
|
||||
buf = buf or vim.api.nvim_get_current_buf()
|
||||
|
||||
if vim.b.disable_autosave or vim.g.disable_autosave then return end
|
||||
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')
|
||||
print("Auto save at " .. os.date("%H:%M:%S"))
|
||||
end)
|
||||
end
|
||||
'';
|
||||
|
||||
@@ -41,19 +37,22 @@ in
|
||||
{
|
||||
event = cfg.event;
|
||||
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;
|
||||
command.__raw = # lua
|
||||
''
|
||||
function(args)
|
||||
if args.bang then
|
||||
vim.b.${cfg.varName} = not vim.b.${cfg.varName}
|
||||
vim.b.disable_autosave = not vim.b.disable_autosave
|
||||
else
|
||||
vim.g.${cfg.varName} = not vim.g.${cfg.varName}
|
||||
vim.g.disable_autosave = not vim.g.disable_autosave
|
||||
end
|
||||
local lualine, lib = pcall(require, 'lualine')
|
||||
if lualine then
|
||||
@@ -68,13 +67,13 @@ in
|
||||
key = "<leader>as";
|
||||
mode = "n";
|
||||
options.silent = true;
|
||||
action = "<cmd>:${cfg.commandName}<CR>";
|
||||
action = "<cmd>:ToggleAutoSave<CR>";
|
||||
}
|
||||
{
|
||||
key = "<leader>aS";
|
||||
mode = "n";
|
||||
options.silent = true;
|
||||
action = "<cmd>:${cfg.commandName}!<CR>";
|
||||
action = "<cmd>:ToggleAutoSave!<CR>";
|
||||
}
|
||||
];
|
||||
|
||||
@@ -87,15 +86,12 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
neo-tree.eventHandlers.window_before_open = # lua
|
||||
''
|
||||
function()
|
||||
AutoSave()
|
||||
end
|
||||
'';
|
||||
/*neo-tree.eventHandlers.window_before_open = # lua
|
||||
"function() PerformAutoSave() end";*/
|
||||
|
||||
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"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
@@ -87,7 +87,6 @@ in
|
||||
R = "Restart LSP";
|
||||
d = "Definitions";
|
||||
i = "Implementations";
|
||||
s = "Document Symbols";
|
||||
w = "Workspace Symbols";
|
||||
t = "Type Definitions";
|
||||
h = "Diagnostics";
|
||||
|
||||
@@ -13,6 +13,10 @@ in
|
||||
key = "<leader>ft";
|
||||
action = "<cmd>:Neotree toggle<CR>";
|
||||
}
|
||||
{
|
||||
key = "<leader>ss";
|
||||
action = "<cmd>:Neotree document_symbols right toggle<CR>";
|
||||
}
|
||||
];
|
||||
plugins = {
|
||||
neo-tree = {
|
||||
@@ -22,15 +26,19 @@ in
|
||||
followCurrentFile.enabled = true;
|
||||
filteredItems.visible = true;
|
||||
};
|
||||
extraSources = [ "document_symbols" ];
|
||||
popupBorderStyle = "rounded";
|
||||
eventHandlers.file_opened = # lua
|
||||
eventHandlers.neo_tree_buffer_leave = # lua
|
||||
''
|
||||
function()
|
||||
require('neo-tree').close_all()
|
||||
end
|
||||
'';
|
||||
};
|
||||
which-key.registrations."<leader>f".t = "Tree";
|
||||
which-key.registrations = {
|
||||
"<leader>f".t = "Tree";
|
||||
"<leader>s".s = "Document Symbols";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user