Skip to content

Commit c2410a3

Browse files
committed
Separate out location and line for alignment
1 parent 777cca9 commit c2410a3

File tree

1 file changed

+32
-16
lines changed
  • lua/telescope/_extensions/orgmode

1 file changed

+32
-16
lines changed

lua/telescope/_extensions/orgmode/init.lua

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ local orgmode = require('orgmode.api')
22

33
local pickers = require("telescope.pickers")
44
local finders = require("telescope.finders")
5+
local entry_display = require("telescope.pickers.entry_display")
56
local conf = require("telescope.config").values
67

8+
-- TODO: include headline.level and headline.is_archived() as part of the
9+
-- public orgmode api
10+
-- TODO: add highlight groups
11+
-- TODO: add action to refile/capture
12+
713
local function get_entries(opts)
814

915
local file_results = vim.tbl_map(function(file)
@@ -33,8 +39,6 @@ local function get_entries(opts)
3339
filename = file_entry.filename,
3440
headline = headline
3541
}
36-
37-
assert(headline.position.start_line == headline._section.line_number)
3842
table.insert(results, entry)
3943
end
4044
end
@@ -46,32 +50,44 @@ end
4650
local function search_headings(opts)
4751
opts = opts or {}
4852

53+
local displayer = entry_display.create({
54+
separator = ' ',
55+
items = {
56+
{ width = vim.F.if_nil(opts.location_width, 20) },
57+
{ remaining = true }
58+
}
59+
})
60+
61+
local function make_display(entry)
62+
return displayer({ entry.location, entry.line })
63+
end
64+
4965
pickers.new(opts, {
5066
prompt_title = "Search Headings",
5167
finder = finders.new_table {
5268
results = get_entries(opts),
53-
entry_maker = opts.entry_maker or function (entry)
69+
entry_maker = opts.entry_maker or function(entry)
5470

5571
local headline = entry.headline
5672

57-
local display = entry.filename
5873
local lnum = nil
74+
local location = vim.fn.fnamemodify(entry.filename, ':t')
75+
local line = ""
5976

6077
if headline then
6178
lnum = headline.position.start_line
62-
63-
local text = string.format('%s %s', string.rep('*', headline._section.level), headline.title)
64-
local line = string.format('%s:%i:%s', entry.filename, lnum, text)
65-
display = line
66-
79+
location = string.format('%s:%i', location, lnum)
80+
line = string.format('%s %s', string.rep('*', headline._section.level), headline.title)
6781
end
6882

6983
return {
70-
value = display,
71-
ordinal = display,
72-
display = display,
84+
value = entry,
85+
ordinal = location .. ' ' .. line,
7386
filename = entry.filename,
74-
lnum = lnum
87+
lnum = lnum,
88+
display = make_display,
89+
location = location,
90+
line = line
7591
}
7692
end,
7793
},
@@ -81,7 +97,7 @@ local function search_headings(opts)
8197
end
8298

8399
return require("telescope").register_extension {
84-
exports = {
85-
search_headings = search_headings
86-
},
100+
exports = {
101+
search_headings = search_headings,
102+
},
87103
}

0 commit comments

Comments
 (0)