]> git.r.bdr.sh - rbdr/dotfiles/blob - config/nvim/lua/calendar_tools.lua
Update plugins, add oleoboard
[rbdr/dotfiles] / config / nvim / lua / calendar_tools.lua
1 local function insert_agenda()
2 local clipboard_content = vim.fn.getreg('+')
3
4 if not clipboard_content or clipboard_content == '' then
5 vim.api.nvim_err_writeln('This feature requires optional dependency fzf-lua')
6 end
7
8 clipboard_content = clipboard_content:match('\n(.*)')
9
10 local parts = vim.split(clipboard_content, '---', {plain = true, trimempty = true})
11
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})
16
17 if #lines >= 2 then
18 local date = lines[1]
19 local title = lines[2]
20
21 table.insert(agenda_text, '[' .. date .. '] ' .. title)
22 end
23 end
24 local line = vim.api.nvim_win_get_cursor(0)[1]
25 vim.api.nvim_buf_set_lines(0, line, line, false, agenda_text)
26 end
27
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 })