style: format code
This commit is contained in:
parent
ed1c31acb4
commit
d90f41269b
@ -1,11 +1,10 @@
|
|||||||
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)
|
local file_results = vim.tbl_map(function(file)
|
||||||
return { file = file, filename = file.filename }
|
return { file = file, filename = file.filename }
|
||||||
end, orgmode.load())
|
end, orgmode.load())
|
||||||
@ -23,14 +22,13 @@ utils.get_entries = function(opts)
|
|||||||
local results = {}
|
local results = {}
|
||||||
for _, file_entry in ipairs(file_results) do
|
for _, file_entry in ipairs(file_results) do
|
||||||
for _, headline in ipairs(file_entry.file.headlines) 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_depth = opts.max_depth == nil or headline.level <= opts.max_depth
|
||||||
local allowed_archive = opts.archived or not headline.is_archived
|
local allowed_archive = opts.archived or not headline.is_archived
|
||||||
if allowed_depth and allowed_archive then
|
if allowed_depth and allowed_archive then
|
||||||
local entry = {
|
local entry = {
|
||||||
file = file_entry.file,
|
file = file_entry.file,
|
||||||
filename = file_entry.filename,
|
filename = file_entry.filename,
|
||||||
headline = headline
|
headline = headline,
|
||||||
}
|
}
|
||||||
table.insert(results, entry)
|
table.insert(results, entry)
|
||||||
end
|
end
|
||||||
@ -41,13 +39,12 @@ utils.get_entries = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
utils.make_entry = function(opts)
|
utils.make_entry = function(opts)
|
||||||
|
|
||||||
local displayer = entry_display.create({
|
local displayer = entry_display.create({
|
||||||
separator = ' ',
|
separator = " ",
|
||||||
items = {
|
items = {
|
||||||
{ width = vim.F.if_nil(opts.location_width, 20) },
|
{ width = vim.F.if_nil(opts.location_width, 20) },
|
||||||
{ remaining = true }
|
{ remaining = true },
|
||||||
}
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
local function make_display(entry)
|
local function make_display(entry)
|
||||||
@ -58,23 +55,23 @@ utils.make_entry = function(opts)
|
|||||||
local headline = entry.headline
|
local headline = entry.headline
|
||||||
|
|
||||||
local lnum = nil
|
local lnum = nil
|
||||||
local location = vim.fn.fnamemodify(entry.filename, ':t')
|
local location = vim.fn.fnamemodify(entry.filename, ":t")
|
||||||
local line = ""
|
local line = ""
|
||||||
|
|
||||||
if headline then
|
if headline then
|
||||||
lnum = headline.position.start_line
|
lnum = headline.position.start_line
|
||||||
location = string.format('%s:%i', location, lnum)
|
location = string.format("%s:%i", location, lnum)
|
||||||
line = string.format('%s %s', string.rep('*', headline.level), headline.title)
|
line = string.format("%s %s", string.rep("*", headline.level), headline.title)
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
value = entry,
|
value = entry,
|
||||||
ordinal = location .. ' ' .. line,
|
ordinal = location .. " " .. line,
|
||||||
filename = entry.filename,
|
filename = entry.filename,
|
||||||
lnum = lnum,
|
lnum = lnum,
|
||||||
display = make_display,
|
display = make_display,
|
||||||
location = location,
|
location = location,
|
||||||
line = line
|
line = line,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -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"),
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
|
@ -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
|
||||||
|
.new(opts, {
|
||||||
prompt_title = "Search Headings",
|
prompt_title = "Search Headings",
|
||||||
finder = finders.new_table {
|
finder = finders.new_table({
|
||||||
results = utils.get_entries(opts),
|
results = utils.get_entries(opts),
|
||||||
entry_maker = opts.entry_maker or utils.make_entry(opts),
|
entry_maker = opts.entry_maker or utils.make_entry(opts),
|
||||||
},
|
}),
|
||||||
sorter = conf.generic_sorter(opts),
|
sorter = conf.generic_sorter(opts),
|
||||||
previewer = conf.grep_previewer(opts),
|
previewer = conf.grep_previewer(opts),
|
||||||
}):find()
|
})
|
||||||
|
:find()
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user