-------------------------------------------------------------------------------
-- Tools to deal with tasks
-------------------------------------------------------------------------------
+local Tasks = {}
+local Configuration = require('configuration')
+local api = vim.api
+-------------------------------------------------------------------------------
+-- Internal Functions
+-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Public Interface
-------------------------------------------------------------------------------
--- Toggles a task completion status
--- @param configuration tNotaConfiguration the plugin configuration
-function toggle(configuration)
- error("Not yet implemented")
+function Tasks.toggle()
+ local line_number = api.nvim_win_get_cursor(0)[1]
+ local line = api.nvim_get_current_line()
+
+ local unchecked_pattern = '^(%s*)%- %[ %]'
+ local unchecked_important_pattern = '^(%s*)%* %[ %]'
+ local checked_pattern = '^(%s*)%- %[x%]'
+ local checked_important_pattern = '^(%s*)%* %[x%]'
+
+ if line:match(unchecked_pattern) then
+ line = line:gsub(unchecked_pattern, '%1- [x]', 1)
+ elseif line:match(unchecked_important_pattern) then
+ line = line:gsub(unchecked_important_pattern, '%1* [x]', 1)
+ elseif line:match(checked_pattern) then
+ line = line:gsub(checked_pattern, '%1- [ ]', 1)
+ elseif line:match(checked_important_pattern) then
+ line = line:gsub(checked_important_pattern, '%1* [ ]', 1)
+ end
+
+ api.nvim_buf_set_lines(0, line_number - 1, line_number, false, {line})
+end
+
+--- Toggles a task completion status
+function Tasks.toggle_importance()
+ local line_number = api.nvim_win_get_cursor(0)[1]
+ local line = api.nvim_get_current_line()
+
+ local unchecked_pattern = '^(%s*)%- %[ %]'
+ local unchecked_important_pattern = '^(%s*)%* %[ %]'
+ local checked_pattern = '^(%s*)%- %[x%]'
+ local checked_important_pattern = '^(%s*)%* %[x%]'
+
+ if line:match(unchecked_pattern) then
+ line = line:gsub(unchecked_pattern, '%1* [ ]', 1)
+ elseif line:match(unchecked_important_pattern) then
+ line = line:gsub(unchecked_important_pattern, '%1- [ ]', 1)
+ elseif line:match(checked_pattern) then
+ line = line:gsub(checked_pattern, '%1* [x]', 1)
+ elseif line:match(checked_important_pattern) then
+ line = line:gsub(checked_important_pattern, '%1- [x]', 1)
+ end
+
+ api.nvim_buf_set_lines(0, line_number - 1, line_number, false, {line})
end
--- Inserts a new task at the cursor location
--- @param configuration tNotaConfiguration the plugin configuration
-function insert(configuration)
- error("Not yet implemented")
+function Tasks.insert()
+ vim.cmd('normal! o- [ ] ')
+ vim.cmd('startinsert!')
end
--- Captures a new task into the inbox
--- @param configuration tNotaConfiguration the plugin configuration
-function capture(configuration)
- error("Not yet implemented")
+function Tasks.capture()
+ error('Not yet implemented')
end
--- Tag a task
--- @param configuration tNotaConfiguration the plugin configuration
-function tag(configuration)
- error("Not yet implemented")
+function Tasks.tag()
+ error('Not yet implemented')
end
--- Reschedule a task for today
--- @param configuration tNotaConfiguration the plugin configuration
-function reschedule_for_today(configuration)
- error("Not yet implemented")
+function Tasks.reschedule_for_today()
+ error('Not yet implemented')
end
--- Reschedule a task for tomorrow
--- @param configuration tNotaConfiguration the plugin configuration
-function reschedule_for_tomorrow(configuration)
- error("Not yet implemented")
+function Tasks.reschedule_for_tomorrow()
+ error('Not yet implemented')
end
--- Reschedule a task for someday
--- @param configuration tNotaConfiguration the plugin someday
-function reschedule_for_someday(configuration)
- error("Not yet implemented")
+function Tasks.reschedule_for_someday()
+ error('Not yet implemented')
end
--- Reschedule a task for an arbitrary date
--- @param configuration tNotaConfiguration the plugin someday
-function reschedule(configuration, new_date)
- error("Not yet implemented")
+function Tasks.reschedule(new_date)
+ error('Not yet implemented')
end
--------------------------------------------------------------------------------
--- Internal Functions
--------------------------------------------------------------------------------
-
+return Tasks