a lot more stuff
This commit is contained in:
@ -29,10 +29,19 @@ end
|
||||
--- set colorscheme
|
||||
---@param name string name of colorscheme
|
||||
function M.colorscheme(name)
|
||||
vim.cmd.colorscheme(name)
|
||||
-- only set the colorscheme if it exists
|
||||
for _, v in pairs(vim.fn.getcompletion('', 'color')) do
|
||||
if v == name then
|
||||
vim.cmd("colorscheme "..name)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- override with any addons
|
||||
for _, v in pairs(vim.fn.getcompletion('', 'color')) do
|
||||
if v == name..'.ext' then
|
||||
vim.cmd.colorscheme(name..'.ext')
|
||||
vim.cmd("colorscheme"..name..'.ext')
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -41,12 +50,24 @@ end
|
||||
---@param mode string|table mode for the keymap
|
||||
---@param bind string|table keymap
|
||||
---@param cmd function|string command to run
|
||||
---@param opts table? keymap options
|
||||
---@param opts vim.keymap.set.Opts? keymap options
|
||||
function M.map(mode, bind, cmd, opts)
|
||||
opts = opts or {}
|
||||
opts['noremap'] = true
|
||||
opts['silent'] = true
|
||||
|
||||
-- attempt to autogenerate a basic description
|
||||
if not opts['desc'] then
|
||||
if type(cmd) == "string" then
|
||||
opts['desc'] = cmd:gsub("<%a+>", "")
|
||||
elseif type(cmd) == "function" then
|
||||
-- TODO: find a way to generate a better name
|
||||
local file_name = vim.fn.fnamemodify(debug.getinfo(cmd, "S").short_src, ":t")
|
||||
opts['desc'] = "origin@"..file_name
|
||||
end
|
||||
end
|
||||
|
||||
-- define the keybinds
|
||||
if type(bind) == 'table' then
|
||||
for i in pairs(bind) do
|
||||
vim.keymap.set(mode, bind[i], cmd, opts)
|
||||
@ -69,7 +90,7 @@ end
|
||||
|
||||
--- extend vim.api.nvim_create_autocmd
|
||||
---@param event string|table event or events
|
||||
---@param opts table options
|
||||
---@param opts vim.api.keyset.create_autocmd options
|
||||
function M.auto(event, opts)
|
||||
vim.api.nvim_create_autocmd(event, opts)
|
||||
end
|
||||
@ -161,24 +182,29 @@ function M.timeout_highlight(opts)
|
||||
|
||||
-- timer code was happily stolen from neovim/runtime/lua/vim/highlight.lua :)
|
||||
local timer, timer_cancel
|
||||
|
||||
if timer then
|
||||
timer:close()
|
||||
assert(timer_cancel)
|
||||
timer_cancel()
|
||||
if not vim.fn.has("nvim-0.11") then
|
||||
if timer then
|
||||
timer:close()
|
||||
assert(timer_cancel)
|
||||
timer_cancel()
|
||||
end
|
||||
end
|
||||
|
||||
-- set the highlight
|
||||
vim.highlight.range(0, namespaceid, opts.hl, opts.range[1], opts.range[2], {})
|
||||
vim.highlight.range(0, namespaceid, opts.hl, opts.range[1], opts.range[2], {
|
||||
opts.timeout,
|
||||
})
|
||||
|
||||
timer_cancel = function()
|
||||
timer = nil
|
||||
timer_cancel = nil
|
||||
pcall(vim.api.nvim_buf_clear_namespace, 0, namespaceid, 0, -1)
|
||||
pcall(vim.api.nvim_win_remove_ns, 0, namespaceid)
|
||||
if not vim.fn.has("nvim-0.11") then
|
||||
timer_cancel = function()
|
||||
timer = nil
|
||||
timer_cancel = nil
|
||||
pcall(vim.api.nvim_buf_clear_namespace, 0, namespaceid, 0, -1)
|
||||
pcall(vim.api.nvim_win_remove_ns, 0, namespaceid)
|
||||
end
|
||||
|
||||
timer = vim.defer_fn(timer_cancel, opts.timeout)
|
||||
end
|
||||
|
||||
timer = vim.defer_fn(timer_cancel, opts.timeout)
|
||||
end
|
||||
|
||||
return M
|
||||
|
Reference in New Issue
Block a user