2022-07-10 20:07:33 +00:00
|
|
|
local controller = require "ivy.controller"
|
|
|
|
|
|
|
|
|
|
-- Put the controller in to the vim global so we can access it in mappings
|
|
|
|
|
-- better without requires. You can call controller commands like `vim.ivy.xxx`.
|
2022-08-06 14:02:42 +00:00
|
|
|
-- luacheck: ignore
|
2022-07-10 20:07:33 +00:00
|
|
|
vim.ivy = controller
|
|
|
|
|
|
2023-03-01 08:17:23 +00:00
|
|
|
local register_backend = function(backend)
|
|
|
|
|
assert(backend.command, "The backend must have a command")
|
|
|
|
|
assert(backend.items, "The backend must have a items function")
|
|
|
|
|
assert(backend.callback, "The backend must have a callback function")
|
|
|
|
|
|
|
|
|
|
local user_command_options = { bang = true }
|
|
|
|
|
if backend.description ~= nil then
|
|
|
|
|
user_command_options.desc = backend.description
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local name = backend.name or backend.command
|
|
|
|
|
vim.api.nvim_create_user_command(backend.command, function()
|
|
|
|
|
vim.ivy.run(name, backend.items, backend.callback)
|
|
|
|
|
end, user_command_options)
|
|
|
|
|
|
|
|
|
|
if backend.keymap ~= nil then
|
|
|
|
|
vim.api.nvim_set_keymap("n", backend.keymap, "<cmd>" .. backend.command .. "<CR>", { nowait = true, silent = true })
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2023-06-02 16:05:57 +00:00
|
|
|
vim.paste = (function(overridden)
|
|
|
|
|
return function(lines, phase)
|
|
|
|
|
local file_type = vim.api.nvim_buf_get_option(0, "filetype")
|
|
|
|
|
if file_type == "ivy" then
|
|
|
|
|
vim.ivy.paste()
|
|
|
|
|
else
|
|
|
|
|
overridden(lines, phase)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end)(vim.paste)
|
|
|
|
|
|
2023-03-01 08:17:23 +00:00
|
|
|
register_backend(require "ivy.backends.buffers")
|
|
|
|
|
register_backend(require "ivy.backends.files")
|
|
|
|
|
register_backend(require "ivy.backends.lines")
|
2023-03-01 08:23:07 +00:00
|
|
|
register_backend(require "ivy.backends.lsp-workspace-symbols")
|
2022-07-23 19:53:07 +00:00
|
|
|
|
2023-05-23 07:01:38 +00:00
|
|
|
if vim.fn.executable "rg" then
|
|
|
|
|
register_backend(require "ivy.backends.rg")
|
|
|
|
|
elseif vim.fn.executable "ag" then
|
|
|
|
|
register_backend(require "ivy.backends.ag")
|
|
|
|
|
end
|
|
|
|
|
|
2022-09-02 20:28:06 +00:00
|
|
|
vim.cmd "highlight IvyMatch cterm=bold gui=bold"
|