1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
local M = {}
function M.select()
local mode = vim.api.nvim_get_mode().mode
local is_visual = mode:match("^[vV]")
local entries = {}
if is_visual then
-- This is the best way to get the visual selection at the moment
-- https://github.com/neovim/neovim/pull/13896
local _, start_lnum, _, _ = unpack(vim.fn.getpos("v"))
local _, end_lnum, _, _, _ = unpack(vim.fn.getcurpos())
if start_lnum > end_lnum then
start_lnum, end_lnum = end_lnum, start_lnum
end
for i = start_lnum, end_lnum do
local entry = M.get_entry_on_line(0, i)
if entry then
table.insert(entries, entry)
end
end
else
local entry = M.get_cursor_entry()
if entry then
table.insert(entries, entry)
end
end
end
function M.open(maildir)
local view = require("inbox.view")
if M.bufnr == nil then
local bufname = string.format("maildir://%s", maildir)
M.bufnr = view.initialize(bufname)
end
if not vim.api.nvim_buf_is_valid(M.bufnr) then
--- TODO: Handle error
return
end
vim.api.nvim_set_current_buf(M.bufnr)
end
---@param content_type inbox.ContentType
function M.open_entry(content_type)
if content_type == nil then
content_type = "text/plain"
end
local lnum = vim.api.nvim_win_get_cursor(0)[1]
local indexers = require("inbox.indexers")
local indexer = indexers.get_indexer()
local part = indexer.get_part(0, lnum, content_type)
vim.print(part)
end
---@param opts inbox.Config
function M.setup(opts)
local config = require("inbox.config")
local indexers = require("inbox.indexers")
local utils = require("inbox.utils")
config.setup(opts)
indexers.setup(config.indexer_config)
for sign, value in pairs(config.signs) do
local name = utils.sign_name(sign)
vim.print(sign, value)
vim.fn.sign_define(name, value)
end
utils.sign_priority = vim.tbl_add_reverse_lookup(vim.tbl_keys(config.signs))
end
return M
|