mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 07:10:06 +08:00
feat(telescope): add Telescope neoyank
extension
This commit is contained in:
parent
898fbc8c37
commit
cfc2b9e7b9
@ -49,6 +49,7 @@ function! SpaceVim#layers#telescope#plugins() abort
|
||||
call add(plugins, [g:_spacevim_root_dir . 'bundle/plenary.nvim', {'merged' : 0}])
|
||||
call add(plugins, [g:_spacevim_root_dir . 'bundle/telescope-menu', {'merged' : 0}])
|
||||
call add(plugins, [g:_spacevim_root_dir . 'bundle/telescope-ctags-outline.nvim', {'merged' : 0}])
|
||||
call add(plugins, [g:_spacevim_root_dir . 'bundle/neoyank.vim', { 'merged' : 0}])
|
||||
return plugins
|
||||
endfunction
|
||||
|
||||
@ -215,9 +216,9 @@ function! s:defind_fuzzy_finder() abort
|
||||
\ ]
|
||||
\ ]
|
||||
nnoremap <silent> <Leader>fh
|
||||
\ :<C-u>CtrlPNeoyank<CR>
|
||||
\ :<C-u>Telescope neoyank<CR>
|
||||
let lnum = expand('<slnum>') + s:unite_lnum - 4
|
||||
let g:_spacevim_mappings.f.h = ['CtrlPNeoyank',
|
||||
let g:_spacevim_mappings.f.h = ['Telescope neoyank',
|
||||
\ 'fuzzy find yank history',
|
||||
\ [
|
||||
\ '[Leader f h] is to fuzzy find history and yank content',
|
||||
|
@ -2,6 +2,7 @@ lua require('telescope').load_extension('menu')
|
||||
lua require('telescope').load_extension('messages')
|
||||
lua require('telescope').load_extension('project')
|
||||
lua require('telescope').load_extension('scriptnames')
|
||||
lua require('telescope').load_extension('neoyank')
|
||||
lua <<EOF
|
||||
local actions = require("telescope.actions")
|
||||
require("telescope").setup{
|
||||
|
73
lua/telescope/_extensions/neoyank.lua
Normal file
73
lua/telescope/_extensions/neoyank.lua
Normal file
@ -0,0 +1,73 @@
|
||||
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_neoyank_output(register)
|
||||
local lines = {}
|
||||
local yank_history = vim.api.nvim_eval('neoyank#_get_yank_histories()')
|
||||
local yank = yank_history[register] or {}
|
||||
|
||||
for _, y in pairs(yank) do
|
||||
table.insert(lines, y)
|
||||
end
|
||||
return lines
|
||||
end
|
||||
|
||||
local function show_yank_history(opts)
|
||||
local opts = opts or {}
|
||||
local register = opts.register or '"'
|
||||
local displayer = entry_display.create({
|
||||
separator = ' ',
|
||||
items = {
|
||||
{ width = 4 },
|
||||
{ remaining = true },
|
||||
},
|
||||
})
|
||||
local function make_display(entry)
|
||||
-- print(vim.inspect(entry))
|
||||
return displayer({
|
||||
{ '[' .. entry.value[2] .. ']', 'TelescopeResultsComment' },
|
||||
{ entry.value[1]:gsub("\n", "\\n"), 'TelescopeResultsFunction' },
|
||||
})
|
||||
end
|
||||
pickers.new(opts, {
|
||||
prompt_title = "neoyank",
|
||||
finder = finders.new_table {
|
||||
results = prepare_neoyank_output(register),
|
||||
entry_maker = function(entry)
|
||||
return {
|
||||
value = entry,
|
||||
display = make_display,
|
||||
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)
|
||||
local reg = vim.fn.getreg('*')
|
||||
vim.fn.setreg('*', entry.value[2])
|
||||
vim.cmd("put *")
|
||||
vim.fn.setreg('*', reg)
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
}):find()
|
||||
end
|
||||
|
||||
local function run()
|
||||
show_yank_history()
|
||||
end
|
||||
|
||||
return require("telescope").register_extension({
|
||||
exports = {
|
||||
-- Default when to argument is given, i.e. :Telescope neoyank
|
||||
neoyank = run,
|
||||
},
|
||||
})
|
||||
|
@ -1,71 +1,71 @@
|
||||
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 get_all_projects()
|
||||
local p = {}
|
||||
local projects = vim.api.nvim_eval('g:unite_source_menu_menus.Projects.command_candidates')
|
||||
|
||||
for _, project in pairs(projects) do
|
||||
table.insert(p, project)
|
||||
end
|
||||
return p
|
||||
end
|
||||
|
||||
local function show_changes(opts)
|
||||
opts = opts or {}
|
||||
local displayer = entry_display.create({
|
||||
separator = ' ',
|
||||
items = {
|
||||
{ width = 20 },
|
||||
{ width = vim.api.nvim_win_get_width(0) - 60 },
|
||||
{ remaining = true },
|
||||
},
|
||||
})
|
||||
local function make_display(entry)
|
||||
-- print(vim.inspect(entry))
|
||||
return displayer({
|
||||
{ '[' .. entry.value.name .. ']', 'TelescopeResultsVariable' },
|
||||
{ entry.value.path, 'TelescopeResultsFunction' },
|
||||
{ '<' .. vim.fn.strftime('%Y-%m-%d %T', entry.value.opened_time) .. '>', 'TelescopeResultsComment' },
|
||||
})
|
||||
end
|
||||
pickers.new(opts, {
|
||||
prompt_title = "Projects",
|
||||
finder = finders.new_table {
|
||||
results = get_all_projects(),
|
||||
entry_maker = function(entry)
|
||||
return {
|
||||
value = entry[3],
|
||||
command = entry[2],
|
||||
display = make_display,
|
||||
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()
|
||||
end
|
||||
|
||||
return require("telescope").register_extension({
|
||||
exports = {
|
||||
-- Default when to argument is given, i.e. :Telescope project
|
||||
project = run,
|
||||
},
|
||||
})
|
||||
|
||||
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 get_all_projects()
|
||||
local p = {}
|
||||
local projects = vim.api.nvim_eval('g:unite_source_menu_menus.Projects.command_candidates')
|
||||
|
||||
for _, project in pairs(projects) do
|
||||
table.insert(p, project)
|
||||
end
|
||||
return p
|
||||
end
|
||||
|
||||
local function show_changes(opts)
|
||||
opts = opts or {}
|
||||
local displayer = entry_display.create({
|
||||
separator = ' ',
|
||||
items = {
|
||||
{ width = 20 },
|
||||
{ width = vim.api.nvim_win_get_width(0) - 60 },
|
||||
{ remaining = true },
|
||||
},
|
||||
})
|
||||
local function make_display(entry)
|
||||
-- print(vim.inspect(entry))
|
||||
return displayer({
|
||||
{ '[' .. entry.value.name .. ']', 'TelescopeResultsVariable' },
|
||||
{ entry.value.path, 'TelescopeResultsFunction' },
|
||||
{ '<' .. vim.fn.strftime('%Y-%m-%d %T', entry.value.opened_time) .. '>', 'TelescopeResultsComment' },
|
||||
})
|
||||
end
|
||||
pickers.new(opts, {
|
||||
prompt_title = "Projects",
|
||||
finder = finders.new_table {
|
||||
results = get_all_projects(),
|
||||
entry_maker = function(entry)
|
||||
return {
|
||||
value = entry[3],
|
||||
command = entry[2],
|
||||
display = make_display,
|
||||
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()
|
||||
end
|
||||
|
||||
return require("telescope").register_extension({
|
||||
exports = {
|
||||
-- Default when to argument is given, i.e. :Telescope project
|
||||
project = run,
|
||||
},
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user