|
1 | 1 | local entry_display = require("telescope.pickers.entry_display")
|
2 | 2 |
|
3 |
| -local orgmode = require('orgmode.api') |
| 3 | +local orgmode = require("orgmode.api") |
4 | 4 |
|
5 | 5 | local utils = {}
|
6 | 6 |
|
7 | 7 | 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 |
41 | 39 | end
|
42 | 40 |
|
43 | 41 | 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 |
80 | 77 | end
|
81 | 78 |
|
82 | 79 | return utils
|
0 commit comments