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