Skip to content

Commit d90f412

Browse files
committed
style: format code
1 parent ed1c31a commit d90f412

File tree

3 files changed

+86
-87
lines changed

3 files changed

+86
-87
lines changed

lua/telescope-orgmode/utils.lua

Lines changed: 67 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,79 @@
11
local entry_display = require("telescope.pickers.entry_display")
22

3-
local orgmode = require('orgmode.api')
3+
local orgmode = require("orgmode.api")
44

55
local utils = {}
66

77
utils.get_entries = function(opts)
8-
9-
local file_results = vim.tbl_map(function(file)
10-
return { file = file, filename = file.filename }
11-
end, orgmode.load())
12-
13-
if not opts.archived then
14-
file_results = vim.tbl_filter(function(entry)
15-
return not entry.file.is_archive_file
16-
end, file_results)
17-
end
18-
19-
if opts.max_depth == 0 then
20-
return file_results
21-
end
22-
23-
local results = {}
24-
for _, file_entry in ipairs(file_results) do
25-
for _, headline in ipairs(file_entry.file.headlines) do
26-
27-
local allowed_depth = opts.max_depth == nil or headline.level <= opts.max_depth
28-
local allowed_archive = opts.archived or not headline.is_archived
29-
if allowed_depth and allowed_archive then
30-
local entry = {
31-
file = file_entry.file,
32-
filename = file_entry.filename,
33-
headline = headline
34-
}
35-
table.insert(results, entry)
36-
end
37-
end
38-
end
39-
40-
return results
8+
local file_results = vim.tbl_map(function(file)
9+
return { file = file, filename = file.filename }
10+
end, orgmode.load())
11+
12+
if not opts.archived then
13+
file_results = vim.tbl_filter(function(entry)
14+
return not entry.file.is_archive_file
15+
end, file_results)
16+
end
17+
18+
if opts.max_depth == 0 then
19+
return file_results
20+
end
21+
22+
local results = {}
23+
for _, file_entry in ipairs(file_results) do
24+
for _, headline in ipairs(file_entry.file.headlines) do
25+
local allowed_depth = opts.max_depth == nil or headline.level <= opts.max_depth
26+
local allowed_archive = opts.archived or not headline.is_archived
27+
if allowed_depth and allowed_archive then
28+
local entry = {
29+
file = file_entry.file,
30+
filename = file_entry.filename,
31+
headline = headline,
32+
}
33+
table.insert(results, entry)
34+
end
35+
end
36+
end
37+
38+
return results
4139
end
4240

4341
utils.make_entry = function(opts)
44-
45-
local displayer = entry_display.create({
46-
separator = ' ',
47-
items = {
48-
{ width = vim.F.if_nil(opts.location_width, 20) },
49-
{ remaining = true }
50-
}
51-
})
52-
53-
local function make_display(entry)
54-
return displayer({ entry.location, entry.line })
55-
end
56-
57-
return function(entry)
58-
local headline = entry.headline
59-
60-
local lnum = nil
61-
local location = vim.fn.fnamemodify(entry.filename, ':t')
62-
local line = ""
63-
64-
if headline then
65-
lnum = headline.position.start_line
66-
location = string.format('%s:%i', location, lnum)
67-
line = string.format('%s %s', string.rep('*', headline.level), headline.title)
68-
end
69-
70-
return {
71-
value = entry,
72-
ordinal = location .. ' ' .. line,
73-
filename = entry.filename,
74-
lnum = lnum,
75-
display = make_display,
76-
location = location,
77-
line = line
78-
}
79-
end
42+
local displayer = entry_display.create({
43+
separator = " ",
44+
items = {
45+
{ width = vim.F.if_nil(opts.location_width, 20) },
46+
{ remaining = true },
47+
},
48+
})
49+
50+
local function make_display(entry)
51+
return displayer({ entry.location, entry.line })
52+
end
53+
54+
return function(entry)
55+
local headline = entry.headline
56+
57+
local lnum = nil
58+
local location = vim.fn.fnamemodify(entry.filename, ":t")
59+
local line = ""
60+
61+
if headline then
62+
lnum = headline.position.start_line
63+
location = string.format("%s:%i", location, lnum)
64+
line = string.format("%s %s", string.rep("*", headline.level), headline.title)
65+
end
66+
67+
return {
68+
value = entry,
69+
ordinal = location .. " " .. line,
70+
filename = entry.filename,
71+
lnum = lnum,
72+
display = make_display,
73+
location = location,
74+
line = line,
75+
}
76+
end
8077
end
8178

8279
return utils

lua/telescope/_extensions/orgmode/init.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
-- public orgmode api
33
-- TODO: add highlight groups
44

5-
return require("telescope").register_extension {
6-
exports = {
7-
search_headings = require("telescope._extensions.orgmode.search_headings"),
8-
refile_heading = require("telescope._extensions.orgmode.refile_heading")
9-
},
10-
}
5+
return require("telescope").register_extension({
6+
exports = {
7+
search_headings = require("telescope._extensions.orgmode.search_headings"),
8+
refile_heading = require("telescope._extensions.orgmode.refile_heading"),
9+
},
10+
})

lua/telescope/_extensions/orgmode/search_headings.lua

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@ local pickers = require("telescope.pickers")
22
local finders = require("telescope.finders")
33
local conf = require("telescope.config").values
44

5-
local utils = require('telescope-orgmode.utils')
5+
local utils = require("telescope-orgmode.utils")
66

77
return function(opts)
8-
opts = opts or {}
8+
opts = opts or {}
99

10-
pickers.new(opts, {
11-
prompt_title = "Search Headings",
12-
finder = finders.new_table {
13-
results = utils.get_entries(opts),
14-
entry_maker = opts.entry_maker or utils.make_entry(opts),
15-
},
16-
sorter = conf.generic_sorter(opts),
17-
previewer = conf.grep_previewer(opts),
18-
}):find()
10+
pickers
11+
.new(opts, {
12+
prompt_title = "Search Headings",
13+
finder = finders.new_table({
14+
results = utils.get_entries(opts),
15+
entry_maker = opts.entry_maker or utils.make_entry(opts),
16+
}),
17+
sorter = conf.generic_sorter(opts),
18+
previewer = conf.grep_previewer(opts),
19+
})
20+
:find()
1921
end

0 commit comments

Comments
 (0)