Separate out location and line for alignment

This commit is contained in:
Joao Sa 2022-10-30 00:14:03 +02:00
parent 777cca967a
commit c2410a3723

View File

@ -2,8 +2,14 @@ local orgmode = require('orgmode.api')
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local entry_display = require("telescope.pickers.entry_display")
local conf = require("telescope.config").values
-- TODO: include headline.level and headline.is_archived() as part of the
-- public orgmode api
-- TODO: add highlight groups
-- TODO: add action to refile/capture
local function get_entries(opts)
local file_results = vim.tbl_map(function(file)
@ -33,8 +39,6 @@ local function get_entries(opts)
filename = file_entry.filename,
headline = headline
}
assert(headline.position.start_line == headline._section.line_number)
table.insert(results, entry)
end
end
@ -46,6 +50,18 @@ end
local function search_headings(opts)
opts = opts or {}
local displayer = entry_display.create({
separator = ' ',
items = {
{ width = vim.F.if_nil(opts.location_width, 20) },
{ remaining = true }
}
})
local function make_display(entry)
return displayer({ entry.location, entry.line })
end
pickers.new(opts, {
prompt_title = "Search Headings",
finder = finders.new_table {
@ -54,24 +70,24 @@ local function search_headings(opts)
local headline = entry.headline
local display = entry.filename
local lnum = nil
local location = vim.fn.fnamemodify(entry.filename, ':t')
local line = ""
if headline then
lnum = headline.position.start_line
local text = string.format('%s %s', string.rep('*', headline._section.level), headline.title)
local line = string.format('%s:%i:%s', entry.filename, lnum, text)
display = line
location = string.format('%s:%i', location, lnum)
line = string.format('%s %s', string.rep('*', headline._section.level), headline.title)
end
return {
value = display,
ordinal = display,
display = display,
value = entry,
ordinal = location .. ' ' .. line,
filename = entry.filename,
lnum = lnum
lnum = lnum,
display = make_display,
location = location,
line = line
}
end,
},
@ -82,6 +98,6 @@ end
return require("telescope").register_extension {
exports = {
search_headings = search_headings
search_headings = search_headings,
},
}