summaryrefslogtreecommitdiff
path: root/lua/telescope/make_entry.lua
diff options
context:
space:
mode:
authorSimon Hauser <Simon-Hauser@outlook.de>2020-11-23 16:11:46 +0100
committerGitHub <noreply@github.com>2020-11-23 10:11:46 -0500
commit863328a96d81d4b93bcfaa0038d429ea24880b0b (patch)
tree4560fcbb47d2c084711d228f70ab58983182d874 /lua/telescope/make_entry.lua
parent2ac0582c06d8a52a42907dde106983e44ae989ef (diff)
feat: Buffers rework (indicators and sorting) (#208)
Diffstat (limited to 'lua/telescope/make_entry.lua')
-rw-r--r--lua/telescope/make_entry.lua48
1 files changed, 24 insertions, 24 deletions
diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua
index aa1d3db..fc8b569 100644
--- a/lua/telescope/make_entry.lua
+++ b/lua/telescope/make_entry.lua
@@ -283,18 +283,16 @@ end
function make_entry.gen_from_buffer(opts)
opts = opts or {}
- local cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
-
- local get_position = function(entry)
- local tabpage_wins = vim.api.nvim_tabpage_list_wins(0)
- for k, v in ipairs(tabpage_wins) do
- if entry == vim.api.nvim_win_get_buf(v) then
- return vim.api.nvim_win_get_cursor(v)
- end
- end
+ local displayer = entry_display.create {
+ separator = " ",
+ items = {
+ { width = opts.bufnr_width },
+ { width = 4 },
+ { remaining = true },
+ },
+ }
- return {}
- end
+ local cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
local make_display = function(entry)
local display_bufname
@@ -304,33 +302,35 @@ function make_entry.gen_from_buffer(opts)
display_bufname = entry.filename
end
- return string.format("%" .. opts.bufnr_width .. "d : %s",
- entry.bufnr, display_bufname)
+ return displayer {
+ entry.bufnr,
+ entry.indicator,
+ display_bufname .. ":" .. entry.lnum,
+ }
end
return function(entry)
- local bufnr_str = tostring(entry)
- local bufname = path.normalize(vim.api.nvim_buf_get_name(entry), cwd)
-
+ local bufname = entry.info.name ~= "" and entry.info.name or '[No Name]'
-- if bufname is inside the cwd, trim that part of the string
+ bufname = path.normalize(bufname, cwd)
- local position = get_position(entry)
-
- if '' == bufname then
- return nil
- end
+ local hidden = entry.info.hidden == 1 and 'h' or 'a'
+ local readonly = vim.api.nvim_buf_get_option(entry.bufnr, 'readonly') and '=' or ' '
+ local changed = entry.info.changed == 1 and '+' or ' '
+ local indicator = entry.flag .. hidden .. readonly .. changed
return {
valid = true,
value = bufname,
- ordinal = bufnr_str .. " : " .. bufname,
+ ordinal = entry.bufnr .. " : " .. bufname,
display = make_display,
- bufnr = entry,
+ bufnr = entry.bufnr,
filename = bufname,
- lnum = position[1] or 1,
+ lnum = entry.info.lnum or 1,
+ indicator = indicator,
}
end
end