Compare commits

...

36 Commits
spaces ... main

Author SHA1 Message Date
Borja FMS a61f83248f nombre en mayúsculas a ver si triguerea algo 6 months ago
Borja FMS ca773ddbfa cambia nombre a TODOs 6 months ago
Borja FMS 2743447f90 vuelve a lo normal 6 months ago
Borja FMS 250efda5d0 prueba otra vez con una string 6 months ago
brobert 9b73c145b3 revert 6 months ago
brobert 962238d18a intenta añadir icono en el whichkeys 6 months ago
borja 184b932b78 test 1 year ago
borja ad8ec54d10 a ver si ahora 1 year ago
borja 82cafd0c8f tab y shift tab 1 year ago
borja 7a19758eb6 test 1 year ago
borja c7a256fdab cambio leve 1 year ago
borja 599d0524f7 añade tab 1 year ago
borja 4c8b17569e cambia el patter de toggle todo para que no pille todos los espacios del principio y así mantenga el indentado cuando hace los cambios 1 year ago
borja 1fa6f9048c devuelve al fin de línea cuando se crea todo vacío 1 year ago
borja 5ef2af6f6d nuevas pattern 1 year ago
borja ee6ddbdf4a test find 1 year ago
borja 981a084909 test 1 year ago
borja 28d6af114c ahora apaña el remove todo 1 year ago
borja 99e9d3790e a ver si así sí 1 year ago
borja f829721373 me habia dejado una cosa 1 year ago
borja bcd0ca26aa arregla bug 1 year ago
borja 98808b7c0e ni idea 1 year ago
borja 4eb596e405 a ver si ahora respeta los espacios 1 year ago
borja ac03e408f8 prueba con find 1 year ago
borja abde05a54f test 1 year ago
borja eb05f300a1 test 1 year ago
borja ee123faeed arregla 1 year ago
borja 0137f9a286 añade todo contando con la indentación 1 year ago
borja a05a096b73 no añade espacio extra al añadir todo si ya hay un espacio 1 year ago
borja e75c9d3a82 cambio quitar todo 1 year ago
borja 8bc9e689b4 a ver como va esto 1 year ago
borja a4c2acf107 cambio por igual a false 1 year ago
borja 649edc6234 cambia add_todo para hacerlo con pattern recognition 1 year ago
borja 71e37876e9 mejores patterns para titulos 1 year ago
borja 92aff65210 cambia los patterns 1 year ago
brobert 349b0d6832 Merge pull request 'cambia el reconocimiento por patrones que deberían aceptar los espacios iniciales' (#1) from spaces into main
Reviewed-on: #1
1 year ago

@ -0,0 +1,4 @@
# TODO
- [ ] Fix press_enter when line is indented
- [ ] When line is a todo, tab indents

@ -1,9 +1,11 @@
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)
@ -25,20 +27,42 @@ 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 })
-- function that checks if the current line starts with the string "- [ ]" or "- [x]" and toggles the x -- indent line if tab is pressed when line is a todo
local function press_tab()
local current_line = vim.api.nvim_get_current_line()
local function toggle_todo() -- Check if current line matches the patterns
-- create a variable called openpattern with a pattern that matches a string that starts with any amount of spaces or tabs followed by "- [ ]" local openpattern = "%- %[[ ]%]"
local openpattern = "^%s*%- %[[ x]%]" local closedpattern = "%- %[[x]%]"
-- create a variable called closepattern with a pattern that matches a string that starts with any amount of spaces or tabs followed by "- [x]" if string.match(current_line, openpattern) or string.match(current_line, closedpattern) then
local closedpattern = "^%s*%- %[[ x]%]" print("tab pressed, allegedly")
vim.api.nvim_feedkeys("C-t", "i", true)
end
end
vim.keymap.set("i", "<TAB>", press_tab, { desc = "On tab", noremap = true, expr = true })
-- create a variable called titleopenpattern with a pattern that matches a string that starts with "# [ ]" -- indent line if shift tab is pressed when line is a todo
local titleopenpattern = "^# [ ]" local function press_shift_tab()
local current_line = vim.api.nvim_get_current_line()
-- create a variable called titleclosedpattern with a pattern that matches a string that starts with "# [x]" -- Check if current line matches the patterns
local titleclosedpattern = "^# [x]" local openpattern = "%- %[[ ]%]"
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()
@ -55,44 +79,47 @@ 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()
if string.sub(line, 1, 5) ~= "- [ ] " then local index, spaces = string.find(line, "^%s*")
line = "- [ ] " .. line
vim.api.nvim_set_current_line(line) if index == 1 and not string.match(line, openpattern) and not string.match(line, closedpattern) then
vim.api.nvim_feedkeys("A", "n", true) if index == 1 and spaces == 0 then
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()
if string.sub(line, 1, 6) == "- [ ] " or string.sub(line, 1, 6) == "- [x] " then -- local index, spaces = string.find(line, "^%s*")
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" })

Loading…
Cancel
Save