]>
Commit | Line | Data |
---|---|---|
56292c79 RBR |
1 | ------------------------------------------------------------------------------- |
2 | -- Tools to deal with tasks | |
3 | ------------------------------------------------------------------------------- | |
503d09fc RBR |
4 | local Tasks = {} |
5 | local Configuration = require('configuration') | |
6 | local api = vim.api | |
7 | ------------------------------------------------------------------------------- | |
8 | -- Internal Functions | |
9 | ------------------------------------------------------------------------------- | |
56292c79 RBR |
10 | ------------------------------------------------------------------------------- |
11 | -- Public Interface | |
12 | ------------------------------------------------------------------------------- | |
13 | ||
14 | --- Toggles a task completion status | |
503d09fc RBR |
15 | function 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}) | |
35 | end | |
36 | ||
37 | --- Toggles a task completion status | |
38 | function 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 |
58 | end |
59 | ||
60 | --- Inserts a new task at the cursor location | |
503d09fc RBR |
61 | function Tasks.insert() |
62 | vim.cmd('normal! o- [ ] ') | |
63 | vim.cmd('startinsert!') | |
56292c79 RBR |
64 | end |
65 | ||
66 | --- Captures a new task into the inbox | |
503d09fc RBR |
67 | function Tasks.capture() |
68 | error('Not yet implemented') | |
56292c79 RBR |
69 | end |
70 | ||
71 | --- Tag a task | |
503d09fc RBR |
72 | function Tasks.tag() |
73 | error('Not yet implemented') | |
56292c79 RBR |
74 | end |
75 | ||
76 | --- Reschedule a task for today | |
503d09fc RBR |
77 | function Tasks.reschedule_for_today() |
78 | error('Not yet implemented') | |
56292c79 RBR |
79 | end |
80 | ||
81 | --- Reschedule a task for tomorrow | |
503d09fc RBR |
82 | function Tasks.reschedule_for_tomorrow() |
83 | error('Not yet implemented') | |
56292c79 RBR |
84 | end |
85 | ||
86 | --- Reschedule a task for someday | |
503d09fc RBR |
87 | function Tasks.reschedule_for_someday() |
88 | error('Not yet implemented') | |
56292c79 RBR |
89 | end |
90 | ||
91 | --- Reschedule a task for an arbitrary date | |
503d09fc RBR |
92 | function Tasks.reschedule(new_date) |
93 | error('Not yet implemented') | |
56292c79 RBR |
94 | end |
95 | ||
503d09fc | 96 | return Tasks |