|
|
@ -1,11 +1,9 @@
|
|
|
|
vim.keymap.set("n", "<leader>t", function() end, { desc = "+TODOs" })
|
|
|
|
vim.keymap.set("n", "<leader>t", function() end, { desc = "+Todos" })
|
|
|
|
|
|
|
|
|
|
|
|
-- add new todo line when previous is already a todo
|
|
|
|
-- add new todo line when previous is already a todo
|
|
|
|
|
|
|
|
|
|
|
|
local function press_enter()
|
|
|
|
local function press_enter()
|
|
|
|
local current_line = vim.api.nvim_get_current_line()
|
|
|
|
local current_line = vim.api.nvim_get_current_line()
|
|
|
|
local index, spaces = string.find(current_line, "^%s*")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Check if the current line matches the pattern
|
|
|
|
-- Check if the current line matches the pattern
|
|
|
|
local pattern = "^%- %[[ x]%] .*$"
|
|
|
|
local pattern = "^%- %[[ x]%] .*$"
|
|
|
|
local match = string.match(current_line, pattern)
|
|
|
|
local match = string.match(current_line, pattern)
|
|
|
@ -27,42 +25,20 @@ local function press_enter()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
vim.keymap.set("i", "<CR>", press_enter, { desc = "On enter", noremap = true, expr = true })
|
|
|
|
vim.keymap.set("i", "<CR>", press_enter, { desc = "On enter", noremap = true, expr = true })
|
|
|
|
|
|
|
|
|
|
|
|
-- indent line if tab is pressed when line is a todo
|
|
|
|
-- function that checks if the current line starts with the string "- [ ]" or "- [x]" and toggles the x
|
|
|
|
local function press_tab()
|
|
|
|
|
|
|
|
local current_line = vim.api.nvim_get_current_line()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Check if current line matches the patterns
|
|
|
|
local function toggle_todo()
|
|
|
|
local openpattern = "%- %[[ ]%]"
|
|
|
|
-- create a variable called openpattern with a pattern that matches a string that starts with any amount of spaces or tabs followed by "- [ ]"
|
|
|
|
local closedpattern = "%- %[[x]%]"
|
|
|
|
local openpattern = "^%s*%- %[[ x]%]"
|
|
|
|
|
|
|
|
|
|
|
|
if string.match(current_line, openpattern) or string.match(current_line, closedpattern) then
|
|
|
|
-- create a variable called closepattern with a pattern that matches a string that starts with any amount of spaces or tabs followed by "- [x]"
|
|
|
|
print("tab pressed, allegedly")
|
|
|
|
local closedpattern = "^%s*%- %[[ x]%]"
|
|
|
|
vim.api.nvim_feedkeys("C-t", "i", true)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
vim.keymap.set("i", "<TAB>", press_tab, { desc = "On tab", noremap = true, expr = true })
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- indent line if shift tab is pressed when line is a todo
|
|
|
|
-- create a variable called titleopenpattern with a pattern that matches a string that starts with "# [ ]"
|
|
|
|
local function press_shift_tab()
|
|
|
|
local titleopenpattern = "^# [ ]"
|
|
|
|
local current_line = vim.api.nvim_get_current_line()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Check if current line matches the patterns
|
|
|
|
-- create a variable called titleclosedpattern with a pattern that matches a string that starts with "# [x]"
|
|
|
|
local openpattern = "%- %[[ ]%]"
|
|
|
|
local titleclosedpattern = "^# [x]"
|
|
|
|
local closedpattern = "%- %[[x]%]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if string.match(current_line, openpattern) or string.match(current_line, closedpattern) then
|
|
|
|
|
|
|
|
print("shift tab pressed, allegedly")
|
|
|
|
|
|
|
|
vim.api.nvim_feedkeys("C-d", "i", true)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
vim.keymap.set("i", "S-Tab", press_shift_tab, { desc = "On shift tab", noremap = true, expr = true })
|
|
|
|
|
|
|
|
-- function that checks if the current line starts with the string "- [ ]" or "- [x]" and toggles the x
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local function toggle_todo()
|
|
|
|
|
|
|
|
local openpattern = "%- %[[ ]%]"
|
|
|
|
|
|
|
|
local closedpattern = "%- %[[x]%]"
|
|
|
|
|
|
|
|
local titleopenpattern = "# %[[ ]%]"
|
|
|
|
|
|
|
|
local titleclosedpattern = "# %[[x]%]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local line = vim.api.nvim_get_current_line()
|
|
|
|
local line = vim.api.nvim_get_current_line()
|
|
|
|
|
|
|
|
|
|
|
@ -79,47 +55,44 @@ local function toggle_todo()
|
|
|
|
line = string.gsub(line, titleclosedpattern, "# [ ]")
|
|
|
|
line = string.gsub(line, titleclosedpattern, "# [ ]")
|
|
|
|
vim.api.nvim_set_current_line(line)
|
|
|
|
vim.api.nvim_set_current_line(line)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- if string.sub(line, 1, 5) == "- [ ]" then
|
|
|
|
|
|
|
|
-- line = string.sub(line, 6, -1)
|
|
|
|
|
|
|
|
-- line = "- [x]" .. line
|
|
|
|
|
|
|
|
-- vim.api.nvim_set_current_line(line)
|
|
|
|
|
|
|
|
-- elseif string.sub(line, 1, 5) == "- [x]" then
|
|
|
|
|
|
|
|
-- line = string.sub(line, 6, -1)
|
|
|
|
|
|
|
|
-- line = "- [ ]" .. line
|
|
|
|
|
|
|
|
-- vim.api.nvim_set_current_line(line)
|
|
|
|
|
|
|
|
-- elseif string.sub(line, 1, 5) == "# [ ]" then
|
|
|
|
|
|
|
|
-- line = string.sub(line, 6, -1)
|
|
|
|
|
|
|
|
-- line = "# [x]" .. line
|
|
|
|
|
|
|
|
-- vim.api.nvim_set_current_line(line)
|
|
|
|
|
|
|
|
-- elseif string.sub(line, 1, 5) == "# [x]" then
|
|
|
|
|
|
|
|
-- line = string.sub(line, 6, -1)
|
|
|
|
|
|
|
|
-- line = "# [ ]" .. line
|
|
|
|
|
|
|
|
-- vim.api.nvim_set_current_line(line)
|
|
|
|
|
|
|
|
-- end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
vim.keymap.set("n", "<leader>tt", toggle_todo, { desc = "Toggle TODO" })
|
|
|
|
vim.keymap.set("n", "<leader>tt", toggle_todo, { desc = "Toggle todo" })
|
|
|
|
|
|
|
|
|
|
|
|
-- function that checks if the current line doesn't start with the string "- [ ] " and, if it doesn't, adds the string at the beginning of the line
|
|
|
|
-- function that checks if the current line doesn't start with the string "- [ ] " and, if it doesn't, adds the string at the beginning of the line
|
|
|
|
local function add_todo()
|
|
|
|
local function add_todo()
|
|
|
|
local openpattern = "^%s*%- %[[ ]%]"
|
|
|
|
|
|
|
|
local closedpattern = "^%s*%- %[[x]%]"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local line = vim.api.nvim_get_current_line()
|
|
|
|
local line = vim.api.nvim_get_current_line()
|
|
|
|
local index, spaces = string.find(line, "^%s*")
|
|
|
|
if string.sub(line, 1, 5) ~= "- [ ] " then
|
|
|
|
|
|
|
|
line = "- [ ] " .. line
|
|
|
|
if index == 1 and not string.match(line, openpattern) and not string.match(line, closedpattern) then
|
|
|
|
vim.api.nvim_set_current_line(line)
|
|
|
|
if index == 1 and spaces == 0 then
|
|
|
|
vim.api.nvim_feedkeys("A", "n", true)
|
|
|
|
line = "- [ ] " .. line
|
|
|
|
|
|
|
|
vim.api.nvim_set_current_line(line)
|
|
|
|
|
|
|
|
vim.api.nvim_feedkeys("A", "n", true)
|
|
|
|
|
|
|
|
elseif index == 1 and spaces > 0 then
|
|
|
|
|
|
|
|
local trimedline = string.sub(line, spaces + 1)
|
|
|
|
|
|
|
|
local spacestring = ""
|
|
|
|
|
|
|
|
for x = 1, spaces, 1 do
|
|
|
|
|
|
|
|
spacestring = spacestring .. " "
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
line = spacestring .. "- [ ] " .. trimedline
|
|
|
|
|
|
|
|
vim.api.nvim_set_current_line(line)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
vim.keymap.set("n", "<leader>ta", add_todo, { desc = "Add TODO" })
|
|
|
|
vim.keymap.set("n", "<leader>ta", add_todo, { desc = "Add todo" })
|
|
|
|
|
|
|
|
|
|
|
|
-- function that checks if the current line starts with the string "- [ ]" or "- [x]" and, if it does, removes that string from the line
|
|
|
|
-- function that checks if the current line starts with the string "- [ ]" or "- [x]" and, if it does, removes that string from the line
|
|
|
|
local function remove_todo()
|
|
|
|
local function remove_todo()
|
|
|
|
local openpattern = "%- %[[ ]%]"
|
|
|
|
|
|
|
|
local closedpattern = "%- %[[x]%]"
|
|
|
|
|
|
|
|
local line = vim.api.nvim_get_current_line()
|
|
|
|
local line = vim.api.nvim_get_current_line()
|
|
|
|
-- local index, spaces = string.find(line, "^%s*")
|
|
|
|
if string.sub(line, 1, 6) == "- [ ] " or string.sub(line, 1, 6) == "- [x] " then
|
|
|
|
|
|
|
|
line = string.sub(line, 7, -1)
|
|
|
|
if string.match(line, openpattern) or string.match(line, closedpattern) then
|
|
|
|
|
|
|
|
print("encontrado")
|
|
|
|
|
|
|
|
line = string.gsub(line, openpattern, "")
|
|
|
|
|
|
|
|
line = string.gsub(line, closedpattern, "")
|
|
|
|
|
|
|
|
vim.api.nvim_set_current_line(line)
|
|
|
|
vim.api.nvim_set_current_line(line)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
vim.keymap.set("n", "<leader>td", remove_todo, { desc = "Remove TODO" })
|
|
|
|
vim.keymap.set("n", "<leader>td", remove_todo, { desc = "Remove todo" })
|
|
|
|