1
0
Fork 0

neovim: Use Telescope community multi-open binding

This commit is contained in:
Jeremy Kaplan 2023-05-23 14:59:47 -07:00
commit cbc831a5ca

View file

@ -119,7 +119,7 @@ plugins = {
local builtin = require('telescope.builtin') local builtin = require('telescope.builtin')
find_files = function(opts) local function find_files(opts)
opts = opts or {} opts = opts or {}
opts['hidden'] = true opts['hidden'] = true
return builtin.find_files(opts) return builtin.find_files(opts)
@ -137,26 +137,116 @@ plugins = {
vim.keymap.set('n', ';b', builtin.buffers) vim.keymap.set('n', ';b', builtin.buffers)
vim.keymap.set('n', ';*', builtin.grep_string) vim.keymap.set('n', ';*', builtin.grep_string)
end, end,
opts = { opts = function(_plugin, _config)
defaults = { local actions = require("telescope.actions")
vimgrep_arguments = { local action_state = require("telescope.actions.state")
"rg", local transform_mod = require("telescope.actions.mt").transform_mod
"--color=never",
"--no-heading", -- https://github.com/nvim-telescope/telescope.nvim/issues/1048#issuecomment-1225975038
"--with-filename", local function multiopen(prompt_bufnr, method)
"--line-number", local method = method or "default"
"--column",
"--smart-case", local edit_file_cmd_map = {
-- Include hidden files, but continue ignoring the .git directory itself. vertical = "vsplit",
"--hidden", horizontal = "split",
"--iglob", "!.git", tab = "tabedit",
default = "edit",
} }
}, local edit_buf_cmd_map = {
pickers = {}, vertical = "vert sbuffer",
extensions = { horizontal = "sbuffer",
aerial = {}, tab = "tab sbuffer",
}, default = "buffer",
}, }
local picker = action_state.get_current_picker(prompt_bufnr)
local multi_selection = picker:get_multi_selection()
if #multi_selection > 1 then
require("telescope.pickers").on_close_prompt(prompt_bufnr)
pcall(vim.api.nvim_set_current_win, picker.original_win_id)
for i, entry in ipairs(multi_selection) do
local filename, row, col
if entry.path or entry.filename then
filename = entry.path or entry.filename
row = entry.row or entry.lnum
col = vim.F.if_nil(entry.col, 1)
elseif not entry.bufnr then
local value = entry.value
if not value then
goto continue
end
if type(value) == "table" then
value = entry.display
end
local sections = vim.split(value, ":")
filename = sections[1]
row = tonumber(sections[2])
col = tonumber(sections[3])
end
local entry_bufnr = entry.bufnr
if entry_bufnr then
if not vim.api.nvim_buf_get_option(entry_bufnr, "buflisted") then
vim.api.nvim_buf_set_option(entry_bufnr, "buflisted", true)
end
local command = i == 1 and "buffer" or edit_buf_cmd_map[method]
pcall(vim.cmd, string.format("%s %s", command, vim.api.nvim_buf_get_name(entry_bufnr)))
else
local command = i == 1 and "edit" or edit_file_cmd_map[method]
if vim.api.nvim_buf_get_name(0) ~= filename or command ~= "edit" then
filename = require("plenary.path"):new(vim.fn.fnameescape(filename)):normalize(vim.loop.cwd())
pcall(vim.cmd, string.format("%s %s", command, filename))
end
end
if row and col then
pcall(vim.api.nvim_win_set_cursor, 0, { row, col-1 })
end
::continue::
end
else
actions["select_" .. method](prompt_bufnr)
end
end
return {
defaults = {
mappings = {
i = {
["<CR>"] = multiopen,
},
n = {
["<CR>"] = multiopen,
},
},
vimgrep_arguments = {
"rg",
"--color=never",
"--no-heading",
"--with-filename",
"--line-number",
"--column",
"--smart-case",
-- Include hidden files, but continue ignoring the .git directory itself.
"--hidden",
"--iglob", "!.git",
},
},
pickers = {},
extensions = {
aerial = {},
},
}
end,
}, },
{ {
"nvim-telescope/telescope-fzf-native.nvim", "nvim-telescope/telescope-fzf-native.nvim",