]> git.r.bdr.sh - rbdr/nota.nvim/blame - lua/tasks.lua
Add minimum workable functionality
[rbdr/nota.nvim] / lua / tasks.lua
CommitLineData
56292c79
RBR
1-------------------------------------------------------------------------------
2-- Tools to deal with tasks
3-------------------------------------------------------------------------------
503d09fc
RBR
4local Tasks = {}
5local Configuration = require('configuration')
6local api = vim.api
7-------------------------------------------------------------------------------
8-- Internal Functions
9-------------------------------------------------------------------------------
56292c79
RBR
10-------------------------------------------------------------------------------
11-- Public Interface
12-------------------------------------------------------------------------------
13
14--- Toggles a task completion status
503d09fc
RBR
15function Tasks.toggle()
16 local line_number = api.nvim_win_get_cursor(0)[1]
17 local line = api.nvim_get_current_line()
18
19 local unchecked_pattern = '^(%s*)%- %[ %]'
20 local unchecked_important_pattern = '^(%s*)%* %[ %]'
21 local checked_pattern = '^(%s*)%- %[x%]'
22 local checked_important_pattern = '^(%s*)%* %[x%]'
23
24 if line:match(unchecked_pattern) then
25 line = line:gsub(unchecked_pattern, '%1- [x]', 1)
26 elseif line:match(unchecked_important_pattern) then
27 line = line:gsub(unchecked_important_pattern, '%1* [x]', 1)
28 elseif line:match(checked_pattern) then
29 line = line:gsub(checked_pattern, '%1- [ ]', 1)
30 elseif line:match(checked_important_pattern) then
31 line = line:gsub(checked_important_pattern, '%1* [ ]', 1)
32 end
33
34 api.nvim_buf_set_lines(0, line_number - 1, line_number, false, {line})
35end
36
37--- Toggles a task completion status
38function Tasks.toggle_importance()
39 local line_number = api.nvim_win_get_cursor(0)[1]
40 local line = api.nvim_get_current_line()
41
42 local unchecked_pattern = '^(%s*)%- %[ %]'
43 local unchecked_important_pattern = '^(%s*)%* %[ %]'
44 local checked_pattern = '^(%s*)%- %[x%]'
45 local checked_important_pattern = '^(%s*)%* %[x%]'
46
47 if line:match(unchecked_pattern) then
48 line = line:gsub(unchecked_pattern, '%1* [ ]', 1)
49 elseif line:match(unchecked_important_pattern) then
50 line = line:gsub(unchecked_important_pattern, '%1- [ ]', 1)
51 elseif line:match(checked_pattern) then
52 line = line:gsub(checked_pattern, '%1* [x]', 1)
53 elseif line:match(checked_important_pattern) then
54 line = line:gsub(checked_important_pattern, '%1- [x]', 1)
55 end
56
57 api.nvim_buf_set_lines(0, line_number - 1, line_number, false, {line})
56292c79
RBR
58end
59
60--- Inserts a new task at the cursor location
503d09fc
RBR
61function Tasks.insert()
62 vim.cmd('normal! o- [ ] ')
63 vim.cmd('startinsert!')
56292c79
RBR
64end
65
66--- Captures a new task into the inbox
503d09fc
RBR
67function Tasks.capture()
68 error('Not yet implemented')
56292c79
RBR
69end
70
71--- Tag a task
503d09fc
RBR
72function Tasks.tag()
73 error('Not yet implemented')
56292c79
RBR
74end
75
76--- Reschedule a task for today
503d09fc
RBR
77function Tasks.reschedule_for_today()
78 error('Not yet implemented')
56292c79
RBR
79end
80
81--- Reschedule a task for tomorrow
503d09fc
RBR
82function Tasks.reschedule_for_tomorrow()
83 error('Not yet implemented')
56292c79
RBR
84end
85
86--- Reschedule a task for someday
503d09fc
RBR
87function Tasks.reschedule_for_someday()
88 error('Not yet implemented')
56292c79
RBR
89end
90
91--- Reschedule a task for an arbitrary date
503d09fc
RBR
92function Tasks.reschedule(new_date)
93 error('Not yet implemented')
56292c79
RBR
94end
95
503d09fc 96return Tasks