feat: support tag searching, highlights

This commit is contained in:
Price Hiller 2024-03-31 03:10:54 -05:00
parent d70432192d
commit 47b485c57c
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB

View File

@ -1,6 +1,6 @@
local entry_display = require("telescope.pickers.entry_display")
local entry_display = require('telescope.pickers.entry_display')
local orgmode = require("orgmode.api")
local orgmode = require('orgmode.api')
local utils = {}
@ -39,36 +39,50 @@ utils.get_entries = function(opts)
end
utils.make_entry = function(opts)
local function make_display(entry)
local displayer = entry_display.create({
separator = " ",
separator = ' ',
items = {
{ width = vim.F.if_nil(opts.location_width, 20) },
{ width = 0.2 },
{ width = (#entry.tags > 0 and 0.5 or 0.8) },
{ remaining = true },
},
})
local function make_display(entry)
return displayer({ entry.location, entry.line })
local location = entry.location .. ':' .. entry.lnum
local headline = entry.headline
local headline_level = (headline.level % 8 == 0 and 8 or headline.level)
local headline_hl = '@org.headline.level' .. headline_level
return displayer({
location,
{ entry.line, headline_hl },
{ ' ' .. entry.tags, '@org.tag' },
})
end
return function(entry)
local headline = entry.headline
local lnum = nil
local location = vim.fn.fnamemodify(entry.filename, ":t")
local line = ""
local location = vim.fn.fnamemodify(entry.filename, ':t')
local line = ''
local tags = ''
if headline then
lnum = headline.position.start_line
location = string.format("%s:%i", location, lnum)
line = string.format("%s %s", string.rep("*", headline.level), headline.title)
line = headline.title
line = string.format('%s %s', string.rep('*', headline.level), headline.title)
if #headline.all_tags > 0 then
tags = ':' .. table.concat(headline.all_tags, ':') .. ':'
end
end
return {
value = entry,
ordinal = location .. " " .. line,
ordinal = location .. ' ' .. headline.title .. ' ' .. tags,
filename = entry.filename,
lnum = lnum,
tags = tags,
headline = headline,
display = make_display,
location = location,
line = line,