🐛 fix(multiplatform): adjustments to support multiple platforms
This commit is contained in:
@@ -74,6 +74,10 @@ M.ripsub = {
|
||||
"RipSubstitute",
|
||||
}
|
||||
|
||||
M.spell_errors = {
|
||||
"Telescope spell_errors",
|
||||
}
|
||||
|
||||
--- Suda plugin cmds
|
||||
M.suda = {
|
||||
"SudaWrite",
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ M.alpha = {
|
||||
-- stylua: ignore start
|
||||
dashboard.section.buttons.val = {
|
||||
---@diagnostic disable: param-type-mismatch
|
||||
dashboard.button("f", " " .. " Find file", LazyVim.pick()),
|
||||
dashboard.button("f", " " .. " Find file", "<cmd>Telescope frecency workspace=CWD <cr>"),
|
||||
dashboard.button("n", " " .. " New file", [[<cmd> ene <BAR> startinsert <cr>]]),
|
||||
dashboard.button("r", " " .. " Recent files", LazyVim.pick("oldfiles")),
|
||||
dashboard.button("g", " " .. " Grep text", LazyVim.pick("live_grep")),
|
||||
|
||||
@@ -233,6 +233,218 @@ function M.notify(message, level, title)
|
||||
return true
|
||||
end
|
||||
|
||||
---@function Function to generate a y/n confirmation prompt
|
||||
---@param prompt string The prompt text to display
|
||||
---@param action function|string The action to execute if the user confirms the prompt, or a Vim command as a string
|
||||
---@return boolean condition true if the user confirms the prompt, false otherwise
|
||||
function M.ConfirmPrompt(prompt, action)
|
||||
-- Validate the action parameter
|
||||
local function perform_action()
|
||||
if type(action) == "function" then
|
||||
action() -- Call the function
|
||||
elseif type(action) == "string" then
|
||||
vim.cmd(action) -- Run the Vim command
|
||||
else
|
||||
M.notify(
|
||||
"Action must be a function or a string",
|
||||
"ERROR",
|
||||
"Configuration Error"
|
||||
)
|
||||
end
|
||||
end
|
||||
-- Create a new buffer
|
||||
local buf = vim.api.nvim_create_buf(false, true) -- Create a new empty buffer
|
||||
-- Set the prompt text in the buffer
|
||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, { prompt, "y/n: " })
|
||||
-- Create a floating window to display the buffer
|
||||
local win_height = 2 -- Height of floating window
|
||||
local win_width = math.floor(vim.o.columns * 0.25) -- Width of floating window
|
||||
local row = math.floor((vim.o.lines - win_height) / 2) -- Position row
|
||||
local col = math.floor((vim.o.columns - win_width) / 2) -- Position column
|
||||
local win_border = "rounded"
|
||||
local style = "minimal"
|
||||
-- Create a floating window
|
||||
local win = vim.api.nvim_open_win(buf, true, {
|
||||
relative = "editor",
|
||||
width = win_width,
|
||||
height = win_height,
|
||||
col = col,
|
||||
row = row,
|
||||
style = style,
|
||||
border = win_border,
|
||||
})
|
||||
-- Move the cursor to the end of the buffer
|
||||
vim.api.nvim_win_set_cursor(win, { 2, 5 })
|
||||
-- Define the yes function
|
||||
local yes = function()
|
||||
vim.api.nvim_win_close(win, true)
|
||||
perform_action() -- Perform the action
|
||||
return true
|
||||
end
|
||||
-- Define the no function
|
||||
local no = function()
|
||||
vim.api.nvim_win_close(win, true)
|
||||
M.notify("Action Canceled", "INFO", "Info")
|
||||
end
|
||||
-- Define buffer-specific key mappings
|
||||
local keymaps = {
|
||||
y = function()
|
||||
yes()
|
||||
end,
|
||||
n = function()
|
||||
no()
|
||||
end,
|
||||
q = function()
|
||||
no()
|
||||
end,
|
||||
["<Esc>"] = function()
|
||||
no()
|
||||
end,
|
||||
}
|
||||
-- Set the key mappings
|
||||
for key, callback in pairs(keymaps) do
|
||||
vim.api.nvim_buf_set_keymap(buf, "n", key, "", {
|
||||
noremap = true,
|
||||
nowait = true,
|
||||
callback = callback,
|
||||
})
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
---@function Function to generate an input prompt
|
||||
---@param prompt string The prompt text to display
|
||||
---@param callback function The function to call with the user input
|
||||
function M.InputPrompt(prompt, callback)
|
||||
-- Create a new buffer
|
||||
local buf = vim.api.nvim_create_buf(false, true) -- Create a new empty buffer
|
||||
|
||||
-- Set the buffer name
|
||||
vim.api.nvim_buf_set_name(buf, "Input")
|
||||
-- Set the buffer filetype (e.g., for custom behavior or syntax highlighting)
|
||||
vim.bo[buf].filetype = "input"
|
||||
-- Set the buffer type to "nofile" to avoid editing or saving the buffer
|
||||
vim.bo[buf].buftype = "nofile"
|
||||
-- Set the prompt text in the buffer
|
||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, { prompt, "Input: " })
|
||||
|
||||
-- Create a floating window to display the buffer
|
||||
local win_height = 2 -- Height of floating window
|
||||
local win_width = math.floor(vim.o.columns * 0.25) -- Width of floating window
|
||||
local row = math.floor((vim.o.lines - win_height) / 2) -- Position row
|
||||
local col = math.floor((vim.o.columns - win_width) / 2) -- Position column
|
||||
local win_border = "rounded"
|
||||
local style = "minimal"
|
||||
|
||||
-- Create a floating window
|
||||
local win = vim.api.nvim_open_win(buf, true, {
|
||||
relative = "editor",
|
||||
width = win_width,
|
||||
height = win_height,
|
||||
col = col,
|
||||
row = row,
|
||||
style = style,
|
||||
border = win_border,
|
||||
})
|
||||
|
||||
-- Move the cursor to the end of the buffer
|
||||
vim.api.nvim_win_set_cursor(win, { 2, 8 })
|
||||
-- Set input mode
|
||||
vim.api.nvim_command("startinsert")
|
||||
|
||||
-- Function to close the window
|
||||
local function exit_win()
|
||||
vim.api.nvim_command("stopinsert")
|
||||
vim.api.nvim_win_close(win, true)
|
||||
end
|
||||
|
||||
-- Function to handle input and close the window
|
||||
local function handle_input()
|
||||
-- Get the text after the "Input: " string
|
||||
local input = vim.api.nvim_buf_get_lines(buf, 1, 2, false)[1]:sub(7) -- Adjust to trim "Input: "
|
||||
return input
|
||||
end
|
||||
|
||||
---@function Function to return user input
|
||||
local function yes()
|
||||
local user_input = handle_input() -- Get the input from the buffer
|
||||
exit_win()
|
||||
if callback then
|
||||
callback(user_input) -- Call the callback with the user input
|
||||
end
|
||||
end
|
||||
|
||||
---@function Function to cancel user input
|
||||
local function no()
|
||||
exit_win()
|
||||
if callback then
|
||||
callback(nil) -- Call the callback with nil to indicate cancellation
|
||||
end
|
||||
end
|
||||
|
||||
-- Define buffer-specific key mappings
|
||||
local keymaps = {
|
||||
["<CR>"] = yes,
|
||||
["<Esc>"] = no,
|
||||
}
|
||||
|
||||
-- Set the key mappings
|
||||
for key, keyback in pairs(keymaps) do
|
||||
vim.api.nvim_buf_set_keymap(buf, "n", key, "", {
|
||||
noremap = true,
|
||||
nowait = true,
|
||||
callback = keyback,
|
||||
})
|
||||
vim.api.nvim_buf_set_keymap(buf, "i", key, "", {
|
||||
noremap = true,
|
||||
nowait = true,
|
||||
callback = keyback,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
---@function Function to reload the user's Neovim configuration
|
||||
---@return nil
|
||||
function M.reload_config()
|
||||
-- Notify the user about the reload process
|
||||
M.notify("Reloading configuration...", "WARN", "Reloading Config")
|
||||
-- 1. Save all buffers
|
||||
vim.cmd("silent! wa")
|
||||
-- 2. Record the list of open buffers to reopen later
|
||||
local buffer_list = vim.api.nvim_list_bufs()
|
||||
local buffers_to_reopen = {}
|
||||
for _, buf in ipairs(buffer_list) do
|
||||
if vim.api.nvim_buf_is_loaded(buf) and vim.fn.bufname(buf) ~= "" then
|
||||
table.insert(
|
||||
buffers_to_reopen,
|
||||
{ buf = buf, file = vim.api.nvim_buf_get_name(buf) }
|
||||
)
|
||||
end
|
||||
end
|
||||
-- 3. Close all buffers
|
||||
vim.cmd("silent! bufdo! bwipeout")
|
||||
-- 4. Clear loaded lua modules related to your custom configuration
|
||||
for name, _ in pairs(package.loaded) do
|
||||
-- Replace 'userconfig' and 'plugin' with your actual config module names
|
||||
if name:match("^userconfig") or name:match("^plugins") then
|
||||
package.loaded[name] = nil
|
||||
end
|
||||
end
|
||||
-- 5. Reload the vim script (init.lua)
|
||||
vim.cmd("source $MYVIMRC")
|
||||
-- 6. Reopen the buffers
|
||||
for _, bufinfo in ipairs(buffers_to_reopen) do
|
||||
local buf = vim.fn.bufadd(bufinfo.file)
|
||||
vim.cmd("buffer " .. buf)
|
||||
vim.api.nvim_buf_call(buf, function()
|
||||
-- You could also restore the exact cursor position if desired
|
||||
vim.cmd('silent! normal! g`"')
|
||||
end)
|
||||
end -- Notify the user that the config has been reloaded
|
||||
M.notify("Configuration reloaded successfully!", "INFO", "Reloaded Config")
|
||||
end
|
||||
|
||||
---@function Function to reload all plugins.
|
||||
--- This is a messy operation. It's not recommended to use it.
|
||||
--- If you do, please define the exclusion list in your config.lua file.
|
||||
|
||||
+24
-3
@@ -357,6 +357,13 @@ M.misc = {
|
||||
end,
|
||||
desc = "Toggle Hardmode",
|
||||
},
|
||||
{ -- Reload config
|
||||
lhs = "<leader>qr",
|
||||
rhs = function()
|
||||
require("data.func").reload_config()
|
||||
end,
|
||||
desc = "Reload Config",
|
||||
},
|
||||
{ -- Yank buffer
|
||||
lhs = "<leader>Y",
|
||||
rhs = "<cmd>%y<cr>",
|
||||
@@ -372,6 +379,21 @@ M.misc = {
|
||||
rhs = "<cmd>Neotree reveal toggle<cr>",
|
||||
desc = "Neotree toggle",
|
||||
},
|
||||
{ -- Neotree
|
||||
lhs = "<leader>\\",
|
||||
rhs = "<cmd>Neotree reveal toggle<cr>",
|
||||
desc = "Neotree toggle",
|
||||
},
|
||||
{ -- Mini.files
|
||||
lhs = "<leader>.",
|
||||
rhs = "<cmd>lua require('mini.files').open()<cr>",
|
||||
desc = "Open mini.files",
|
||||
},
|
||||
{ -- Telescope Frecency
|
||||
lhs = "<leader><leader>",
|
||||
rhs = "<cmd>Telescope frecency workspace=CWD<cr>",
|
||||
desc = "Telescope frecency",
|
||||
},
|
||||
{ -- Exit Neovim
|
||||
lhs = "<leader>Q",
|
||||
rhs = "<cmd>lua require('data').func.exit()<cr>",
|
||||
@@ -603,13 +625,12 @@ M.substitute = {
|
||||
},
|
||||
}
|
||||
|
||||
M.surround = {
|
||||
M.overrides = {
|
||||
{ -- De-map 's' to avoid conflicts with mini.surround
|
||||
lhs = "s",
|
||||
rhs = "<Nop>",
|
||||
desc = "Prevent conflict with mini.surround",
|
||||
desc = "Surround",
|
||||
mode = { "n", "x" },
|
||||
hidden = true,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
+168
-46
@@ -189,6 +189,23 @@ M.arrow = {
|
||||
|
||||
--- Bufferline configuration options
|
||||
M.bufferline = {
|
||||
enabled = function()
|
||||
if
|
||||
require("data.func").check_global_var(
|
||||
"tabline",
|
||||
"bufferline",
|
||||
"bufferline"
|
||||
)
|
||||
or require("data.func").check_global_var(
|
||||
"tabline",
|
||||
"barsNlines",
|
||||
"bufferline"
|
||||
)
|
||||
then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
opts = {
|
||||
options = {
|
||||
themable = true,
|
||||
@@ -440,6 +457,10 @@ M.whichkey = {
|
||||
winblend = 10,
|
||||
},
|
||||
},
|
||||
triggers = {
|
||||
{ "<leader>", mode = { "n", "v" } },
|
||||
{ "s", mode = { "n", "x" } },
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -479,8 +500,10 @@ M.gitgraph = {
|
||||
else
|
||||
-- Fallback
|
||||
return {
|
||||
merge_commit = "M",
|
||||
commit = "*",
|
||||
merge_commit = "",
|
||||
commit = "",
|
||||
merge_commit_end = "",
|
||||
commit_end = "",
|
||||
}
|
||||
end
|
||||
end,
|
||||
@@ -518,6 +541,7 @@ M.ibl = {
|
||||
},
|
||||
scope_char = {
|
||||
light = { "" },
|
||||
hard = { "│" },
|
||||
none = { " " },
|
||||
fancy = { "‖" },
|
||||
strong = { "⦀" },
|
||||
@@ -650,56 +674,122 @@ M.trouble = {
|
||||
}
|
||||
|
||||
--- Function to set up bars-n-lines plugin options
|
||||
M.barsNlines = function()
|
||||
require("bars").setup({
|
||||
exclude_filetypes = M.minimap.ft,
|
||||
exclude_buftypes = M.minimap.buf,
|
||||
statuscolumn = {
|
||||
enable = true,
|
||||
parts = {
|
||||
{
|
||||
type = "fold",
|
||||
markers = {
|
||||
default = {
|
||||
content = { " " },
|
||||
},
|
||||
open = {
|
||||
{ " ", "BarsStatuscolumnFold1" },
|
||||
},
|
||||
close = {
|
||||
{ "╴", "BarsStatuscolumnFold1" },
|
||||
},
|
||||
scope = {
|
||||
{ "│ ", "BarsStatuscolumnFold1" },
|
||||
},
|
||||
divider = {
|
||||
{ "├╴", "BarsStatuscolumnFold1" },
|
||||
},
|
||||
foldend = {
|
||||
{ "╰╼", "BarsStatuscolumnFold1" },
|
||||
M.barsNlines = {
|
||||
enabled = function()
|
||||
if
|
||||
require("data.func").check_global_var(
|
||||
"statuscolumn",
|
||||
"barsNlines",
|
||||
"native"
|
||||
)
|
||||
or require("data.func").check_global_var(
|
||||
"tabline",
|
||||
"barsNlines",
|
||||
"bufferline"
|
||||
)
|
||||
or require("data.func").check_global_var(
|
||||
"statusline",
|
||||
"barsNlines",
|
||||
"lualine"
|
||||
)
|
||||
then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end,
|
||||
config = function()
|
||||
require("bars").setup({
|
||||
exclude_filetypes = M.minimap.ft,
|
||||
exclude_buftypes = M.minimap.buf,
|
||||
statuscolumn = {
|
||||
enable = require("data.func").check_global_var(
|
||||
"statuscolumn",
|
||||
"barsNlines",
|
||||
"native"
|
||||
),
|
||||
parts = {
|
||||
{
|
||||
type = "fold",
|
||||
markers = {
|
||||
default = {
|
||||
content = { " " },
|
||||
},
|
||||
open = {
|
||||
{ " ", "BarsStatuscolumnFold1" },
|
||||
},
|
||||
close = {
|
||||
{ "╴", "BarsStatuscolumnFold1" },
|
||||
},
|
||||
scope = {
|
||||
{ "│ ", "BarsStatuscolumnFold1" },
|
||||
},
|
||||
divider = {
|
||||
{ "├╴", "BarsStatuscolumnFold1" },
|
||||
},
|
||||
foldend = {
|
||||
{ "╰╼", "BarsStatuscolumnFold1" },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
type = "number",
|
||||
mode = "hybrid",
|
||||
hl = "LineNr",
|
||||
lnum_hl = "BarsStatusColumnNum",
|
||||
relnum_hl = "LineNr",
|
||||
virtnum_hl = "TablineSel",
|
||||
wrap_hl = "TablineSel",
|
||||
{
|
||||
type = "number",
|
||||
mode = "hybrid",
|
||||
hl = "LineNr",
|
||||
lnum_hl = "BarsStatusColumnNum",
|
||||
relnum_hl = "LineNr",
|
||||
virtnum_hl = "TablineSel",
|
||||
wrap_hl = "TablineSel",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
tabline = false,
|
||||
statusline = false,
|
||||
})
|
||||
end
|
||||
tabline = {
|
||||
enable = require("data.func").check_global_var(
|
||||
"tabline",
|
||||
"barsNlines",
|
||||
"bufferline"
|
||||
),
|
||||
parts = {
|
||||
{
|
||||
-- Part name
|
||||
type = "bufs",
|
||||
|
||||
-- Active buffer configuration
|
||||
active = {
|
||||
corner_left = { "", "BarsTablineBufActiveSep" },
|
||||
corner_right = { "", "BarsTablineBufActiveSep" },
|
||||
|
||||
padding_left = { " ", "BarsTablineBufActive" },
|
||||
padding_right = { " " },
|
||||
},
|
||||
|
||||
-- Inactive buffer configuration
|
||||
inactive = {
|
||||
corner_left = { "", "BarsTablineBufInactiveSep" },
|
||||
corner_right = { "", "BarsTablineBufInactiveSep" },
|
||||
|
||||
padding_left = { " ", "BarsTablineBufInactive" },
|
||||
padding_right = { " " },
|
||||
},
|
||||
|
||||
-- List of patterns to ignore
|
||||
ignore = {},
|
||||
},
|
||||
},
|
||||
},
|
||||
statusline = {
|
||||
enable = require("data.func").check_global_var(
|
||||
"statusline",
|
||||
"barsNlines",
|
||||
"lualine"
|
||||
),
|
||||
},
|
||||
})
|
||||
end,
|
||||
}
|
||||
|
||||
--- Function to setup Pigeon plugin options
|
||||
M.pigeon = function()
|
||||
local data = require("data")
|
||||
local platform = data.func.get_os("platform")
|
||||
local platform = require("data.func").get_os("platform")
|
||||
local lazy_installed = pcall(require, "lazy")
|
||||
local packer_installed = pcall(require, "packer_plugins")
|
||||
local pigeon_enabled = true -- default
|
||||
@@ -711,7 +801,7 @@ M.pigeon = function()
|
||||
elseif vim.fn.exists("g:plugs") == 1 then
|
||||
plugman = "vim-plug"
|
||||
else
|
||||
data.func.notify(
|
||||
require("data.func").notify(
|
||||
"Failed to detect package manager.\nPigeon disabled.",
|
||||
"ERROR"
|
||||
)
|
||||
@@ -955,6 +1045,38 @@ M.toggleterm = {
|
||||
},
|
||||
}
|
||||
|
||||
M.treesitter = {
|
||||
opts = {
|
||||
ensure_installed = {
|
||||
"bash",
|
||||
"c",
|
||||
"css",
|
||||
"diff",
|
||||
"html",
|
||||
"javascript",
|
||||
"jsdoc",
|
||||
"json",
|
||||
"jsonc",
|
||||
"lua",
|
||||
"luadoc",
|
||||
"luap",
|
||||
"markdown",
|
||||
"markdown_inline",
|
||||
"printf",
|
||||
"python",
|
||||
"query",
|
||||
"regex",
|
||||
"toml",
|
||||
"tsx",
|
||||
"typescript",
|
||||
"vim",
|
||||
"vimdoc",
|
||||
"xml",
|
||||
"yaml",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
--- Function to extend minimap.buf with general exclusions
|
||||
---@private
|
||||
---@return nil
|
||||
|
||||
Reference in New Issue
Block a user