mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-04-14 23:49:19 +08:00
feat(telescope): implement :Telescope menu
extension
This commit is contained in:
parent
0db74e6fe4
commit
0f885b6e17
@ -1,35 +1,54 @@
|
||||
local pickers = require("telescope.pickers")
|
||||
local finders = require("telescope.finders")
|
||||
local action_state = require("telescope.actions.state")
|
||||
local actions = require("telescope.actions")
|
||||
local conf = require("telescope.config").values
|
||||
local entry_display = require("telescope.pickers.entry_display")
|
||||
local finders = require("telescope.finders")
|
||||
local pickers = require("telescope.pickers")
|
||||
|
||||
local function prepare_output_table()
|
||||
local lines = {}
|
||||
local changes = vim.api.nvim_command_output("changes")
|
||||
local function prepare_menu(menu)
|
||||
local p = {}
|
||||
local projects = vim.api.nvim_eval('g:unite_source_menu_menus.' .. menu .. '.command_candidates')
|
||||
|
||||
for change in changes:gmatch("[^\r\n]+") do
|
||||
table.insert(lines, change)
|
||||
end
|
||||
return lines
|
||||
for _, project in pairs(projects) do
|
||||
table.insert(p, project)
|
||||
end
|
||||
return p
|
||||
end
|
||||
|
||||
local function show_changes(opts)
|
||||
opts = opts or {}
|
||||
pickers.new(opts, {
|
||||
prompt_title = "Menu",
|
||||
finder = finders.new_table {
|
||||
results = prepare_output_table()
|
||||
},
|
||||
sorter = conf.generic_sorter(opts),
|
||||
}):find()
|
||||
local function show_menu(opts)
|
||||
opts = opts or {}
|
||||
local menu = opts.menu or ''
|
||||
pickers.new(opts, {
|
||||
prompt_title = "Menu",
|
||||
finder = finders.new_table {
|
||||
results = prepare_menu(menu),
|
||||
entry_maker = function(entry)
|
||||
return {
|
||||
command = entry[2],
|
||||
display = entry[1],
|
||||
ordinal = entry[1]
|
||||
}
|
||||
end
|
||||
},
|
||||
sorter = conf.generic_sorter(opts),
|
||||
attach_mappings = function(prompt_bufnr)
|
||||
actions.select_default:replace(function()
|
||||
local entry = action_state.get_selected_entry()
|
||||
actions.close(prompt_bufnr)
|
||||
vim.cmd(entry.command)
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
}):find()
|
||||
end
|
||||
|
||||
local function run()
|
||||
show_changes()
|
||||
local function run(opts)
|
||||
show_menu(opts)
|
||||
end
|
||||
|
||||
return require("telescope").register_extension({
|
||||
exports = {
|
||||
-- Default when to argument is given, i.e. :Telescope changes
|
||||
changes = run,
|
||||
-- Default when to argument is given, i.e. :Telescope menu menu=CustomKeyMaps
|
||||
menu = run,
|
||||
},
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user