feat: current buffer fuzzy find improvements (#694)
If you don't want to have a previewer disable it with `:Telescope current_buffer_fuzzy_find previewer=false` To ignore empty lines do: `:Telescope current_buffer_fuzzy_find skip_empty_lines=true`
This commit is contained in:
committed by
GitHub
parent
0944c4a88f
commit
d0cf646f65
@@ -329,29 +329,30 @@ files.treesitter = function(opts)
|
||||
end
|
||||
|
||||
files.current_buffer_fuzzy_find = function(opts)
|
||||
-- All actions are on the current buffer
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local filename = vim.fn.expand(vim.api.nvim_buf_get_name(bufnr))
|
||||
|
||||
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
||||
local lines_with_numbers = {}
|
||||
for k, v in ipairs(lines) do
|
||||
table.insert(lines_with_numbers, {k, v})
|
||||
end
|
||||
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
for lnum, line in ipairs(lines) do
|
||||
table.insert(lines_with_numbers, {
|
||||
lnum = lnum,
|
||||
line = line,
|
||||
bufnr = bufnr,
|
||||
filename = filename,
|
||||
})
|
||||
end
|
||||
|
||||
pickers.new(opts, {
|
||||
prompt_title = 'Current Buffer Fuzzy',
|
||||
finder = finders.new_table {
|
||||
results = lines_with_numbers,
|
||||
entry_maker = function(enumerated_line)
|
||||
return {
|
||||
bufnr = bufnr,
|
||||
display = enumerated_line[2],
|
||||
ordinal = enumerated_line[2],
|
||||
|
||||
lnum = enumerated_line[1],
|
||||
}
|
||||
end
|
||||
entry_maker = opts.entry_maker or make_entry.gen_from_buffer_lines(opts),
|
||||
},
|
||||
sorter = conf.generic_sorter(opts),
|
||||
previewer = conf.grep_previewer(opts),
|
||||
attach_mappings = function()
|
||||
action_set.select:enhance {
|
||||
post = function()
|
||||
|
||||
@@ -680,6 +680,38 @@ function make_entry.gen_from_highlights()
|
||||
end
|
||||
end
|
||||
|
||||
function make_entry.gen_from_buffer_lines(opts)
|
||||
local displayer = entry_display.create {
|
||||
separator = ' │ ',
|
||||
items = {
|
||||
{ width = 5 },
|
||||
{ remaining = true },
|
||||
},
|
||||
}
|
||||
|
||||
local make_display = function(entry)
|
||||
return displayer {
|
||||
{ entry.lnum, opts.lnum_highlight_group or 'TelescopeResultsSpecialComment' },
|
||||
entry.line
|
||||
}
|
||||
end
|
||||
|
||||
return function(entry)
|
||||
if opts.skip_empty_lines and string.match(entry.line, '^$') then
|
||||
return
|
||||
end
|
||||
|
||||
return {
|
||||
valid = true,
|
||||
ordinal = entry.line,
|
||||
display = make_display,
|
||||
filename = entry.filename,
|
||||
lnum = entry.lnum,
|
||||
line = entry.line,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function make_entry.gen_from_vimoptions()
|
||||
local process_one_opt = function(o)
|
||||
local ok, value_origin
|
||||
|
||||
Reference in New Issue
Block a user