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
|
local function insert_agenda()
local clipboard_content = vim.fn.getreg('+')
if not clipboard_content or clipboard_content == '' then
vim.api.nvim_err_writeln('This feature requires optional dependency fzf-lua')
end
clipboard_content = clipboard_content:match('\n(.*)')
local parts = vim.split(clipboard_content, '---', {plain = true, trimempty = true})
local agenda_text = {'# Agenda', ''}
for _, part in ipairs(parts) do
local trimmed_part = part:match('^%s*(.-)%s*$')
local lines = vim.split(trimmed_part, '\n', {trimempty = true})
if #lines >= 2 then
local date = lines[1]
local title = lines[2]
table.insert(agenda_text, '[' .. date .. '] ' .. title)
end
end
local line = vim.api.nvim_win_get_cursor(0)[1]
vim.api.nvim_buf_set_lines(0, line, line, false, agenda_text)
end
vim.api.nvim_create_user_command('InsertAgendaFromClipboard', insert_agenda, { nargs = 0 })
vim.api.nvim_set_keymap('n', '<leader>ia', '<cmd>InsertAgendaFromClipboard<CR>', { noremap = true, silent = true })
|