feat: Adds shorten_path, show_all_buffers opts and fixes alignment (buffers builtin) (#32)
This commit is contained in:
@@ -233,6 +233,15 @@ require'telescope.builtin'.command_history{}
|
|||||||
|
|
||||||
Search the vim command history.
|
Search the vim command history.
|
||||||
|
|
||||||
|
```lua
|
||||||
|
require'telescope.builtin'.buffers{
|
||||||
|
-- Optional
|
||||||
|
-- show_all_buffers = true -- Show unloaded buffers aswell
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Search on vim buffers list.
|
||||||
|
|
||||||
#### LSP
|
#### LSP
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ local function goto_file_selection(prompt_bufnr, command)
|
|||||||
-- TODO: Sometimes we open something with missing line numbers and stuff...
|
-- TODO: Sometimes we open something with missing line numbers and stuff...
|
||||||
if entry_bufnr then
|
if entry_bufnr then
|
||||||
a.nvim_win_set_buf(original_win_id, entry_bufnr)
|
a.nvim_win_set_buf(original_win_id, entry_bufnr)
|
||||||
|
vim.api.nvim_command("doautocmd filetypedetect BufRead " .. vim.fn.fnameescape(filename))
|
||||||
else
|
else
|
||||||
vim.cmd(string.format(":%s %s", command, filename))
|
vim.cmd(string.format(":%s %s", command, filename))
|
||||||
|
|
||||||
|
|||||||
@@ -404,13 +404,19 @@ builtin.fd = builtin.find_files
|
|||||||
builtin.buffers = function(opts)
|
builtin.buffers = function(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|
||||||
local buffers = filter(function(b)
|
local buffers = filter(function(b)
|
||||||
return
|
return
|
||||||
vim.api.nvim_buf_is_loaded(b)
|
(opts.show_all_buffers
|
||||||
|
or vim.api.nvim_buf_is_loaded(b))
|
||||||
and 1 == vim.fn.buflisted(b)
|
and 1 == vim.fn.buflisted(b)
|
||||||
|
|
||||||
end, vim.api.nvim_list_bufs())
|
end, vim.api.nvim_list_bufs())
|
||||||
|
|
||||||
|
if not opts.bufnr_width then
|
||||||
|
local max_bufnr = math.max(unpack(buffers))
|
||||||
|
opts.bufnr_width = #tostring(max_bufnr)
|
||||||
|
end
|
||||||
|
|
||||||
pickers.new(opts, {
|
pickers.new(opts, {
|
||||||
prompt = 'Buffers',
|
prompt = 'Buffers',
|
||||||
finder = finders.new_table {
|
finder = finders.new_table {
|
||||||
|
|||||||
@@ -180,6 +180,8 @@ function make_entry.gen_from_quickfix(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function make_entry.gen_from_buffer(opts)
|
function make_entry.gen_from_buffer(opts)
|
||||||
|
opts = opts or {}
|
||||||
|
|
||||||
local get_position = function(entry)
|
local get_position = function(entry)
|
||||||
local tabpage_wins = vim.api.nvim_tabpage_list_wins(0)
|
local tabpage_wins = vim.api.nvim_tabpage_list_wins(0)
|
||||||
for k, v in ipairs(tabpage_wins) do
|
for k, v in ipairs(tabpage_wins) do
|
||||||
@@ -191,6 +193,18 @@ function make_entry.gen_from_buffer(opts)
|
|||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local make_display = function(entry)
|
||||||
|
local display_bufname
|
||||||
|
if opts.shorten_path then
|
||||||
|
display_bufname = utils.path_shorten(entry.filename)
|
||||||
|
else
|
||||||
|
display_bufname = entry.filename
|
||||||
|
end
|
||||||
|
|
||||||
|
return string.format("%" .. opts.bufnr_width .. "d : %s",
|
||||||
|
entry.bufnr, display_bufname)
|
||||||
|
end
|
||||||
|
|
||||||
return function(entry)
|
return function(entry)
|
||||||
local bufnr_str = tostring(entry)
|
local bufnr_str = tostring(entry)
|
||||||
local bufname = vim.api.nvim_buf_get_name(entry)
|
local bufname = vim.api.nvim_buf_get_name(entry)
|
||||||
@@ -206,7 +220,7 @@ function make_entry.gen_from_buffer(opts)
|
|||||||
|
|
||||||
value = bufname,
|
value = bufname,
|
||||||
ordinal = bufnr_str .. " : " .. bufname,
|
ordinal = bufnr_str .. " : " .. bufname,
|
||||||
display = bufnr_str .. " : " .. bufname,
|
display = make_display,
|
||||||
|
|
||||||
bufnr = entry,
|
bufnr = entry,
|
||||||
filename = bufname,
|
filename = bufname,
|
||||||
|
|||||||
Reference in New Issue
Block a user