style: format code

This commit is contained in:
Lyz 2024-02-08 01:14:13 +01:00
parent ed1c31acb4
commit d90f41269b
No known key found for this signature in database
GPG Key ID: 6C7D7C1612CDE02F
3 changed files with 77 additions and 78 deletions

View File

@ -1,82 +1,79 @@
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 = {} local utils = {}
utils.get_entries = function(opts) utils.get_entries = function(opts)
local file_results = vim.tbl_map(function(file)
return { file = file, filename = file.filename }
end, orgmode.load())
local file_results = vim.tbl_map(function(file) if not opts.archived then
return { file = file, filename = file.filename } file_results = vim.tbl_filter(function(entry)
end, orgmode.load()) return not entry.file.is_archive_file
end, file_results)
end
if not opts.archived then if opts.max_depth == 0 then
file_results = vim.tbl_filter(function(entry) return file_results
return not entry.file.is_archive_file end
end, file_results)
end
if opts.max_depth == 0 then local results = {}
return file_results for _, file_entry in ipairs(file_results) do
end for _, headline in ipairs(file_entry.file.headlines) do
local allowed_depth = opts.max_depth == nil or headline.level <= opts.max_depth
local allowed_archive = opts.archived or not headline.is_archived
if allowed_depth and allowed_archive then
local entry = {
file = file_entry.file,
filename = file_entry.filename,
headline = headline,
}
table.insert(results, entry)
end
end
end
local results = {} return results
for _, file_entry in ipairs(file_results) do
for _, headline in ipairs(file_entry.file.headlines) do
local allowed_depth = opts.max_depth == nil or headline.level <= opts.max_depth
local allowed_archive = opts.archived or not headline.is_archived
if allowed_depth and allowed_archive then
local entry = {
file = file_entry.file,
filename = file_entry.filename,
headline = headline
}
table.insert(results, entry)
end
end
end
return results
end end
utils.make_entry = function(opts) utils.make_entry = function(opts)
local displayer = entry_display.create({
separator = " ",
items = {
{ width = vim.F.if_nil(opts.location_width, 20) },
{ remaining = true },
},
})
local displayer = entry_display.create({ local function make_display(entry)
separator = ' ', return displayer({ entry.location, entry.line })
items = { end
{ width = vim.F.if_nil(opts.location_width, 20) },
{ remaining = true }
}
})
local function make_display(entry) return function(entry)
return displayer({ entry.location, entry.line }) local headline = entry.headline
end
return function(entry) local lnum = nil
local headline = entry.headline local location = vim.fn.fnamemodify(entry.filename, ":t")
local line = ""
local lnum = nil if headline then
local location = vim.fn.fnamemodify(entry.filename, ':t') lnum = headline.position.start_line
local line = "" location = string.format("%s:%i", location, lnum)
line = string.format("%s %s", string.rep("*", headline.level), headline.title)
end
if headline then return {
lnum = headline.position.start_line value = entry,
location = string.format('%s:%i', location, lnum) ordinal = location .. " " .. line,
line = string.format('%s %s', string.rep('*', headline.level), headline.title) filename = entry.filename,
end lnum = lnum,
display = make_display,
return { location = location,
value = entry, line = line,
ordinal = location .. ' ' .. line, }
filename = entry.filename, end
lnum = lnum,
display = make_display,
location = location,
line = line
}
end
end end
return utils return utils

View File

@ -2,9 +2,9 @@
-- public orgmode api -- public orgmode api
-- TODO: add highlight groups -- TODO: add highlight groups
return require("telescope").register_extension { return require("telescope").register_extension({
exports = { exports = {
search_headings = require("telescope._extensions.orgmode.search_headings"), search_headings = require("telescope._extensions.orgmode.search_headings"),
refile_heading = require("telescope._extensions.orgmode.refile_heading") refile_heading = require("telescope._extensions.orgmode.refile_heading"),
}, },
} })

View File

@ -2,18 +2,20 @@ local pickers = require("telescope.pickers")
local finders = require("telescope.finders") local finders = require("telescope.finders")
local conf = require("telescope.config").values local conf = require("telescope.config").values
local utils = require('telescope-orgmode.utils') local utils = require("telescope-orgmode.utils")
return function(opts) return function(opts)
opts = opts or {} opts = opts or {}
pickers.new(opts, { pickers
prompt_title = "Search Headings", .new(opts, {
finder = finders.new_table { prompt_title = "Search Headings",
results = utils.get_entries(opts), finder = finders.new_table({
entry_maker = opts.entry_maker or utils.make_entry(opts), results = utils.get_entries(opts),
}, entry_maker = opts.entry_maker or utils.make_entry(opts),
sorter = conf.generic_sorter(opts), }),
previewer = conf.grep_previewer(opts), sorter = conf.generic_sorter(opts),
}):find() previewer = conf.grep_previewer(opts),
})
:find()
end end