You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to tweak how the toggle_checkbox works to:
Append an inactive date at the end of the checkbox once it's completed
Remove the appended inactive date if it's unchecked
The idea is that from this snippet:
- [ ] Test
- [ ] Test 2
I get:
- [ ] Test
- [X] Test 2 [2024-11-20 Wed 11:09]
And if I toggle it again it returns back to the original.
I'm quite new with lua so I'm having newbie confusion. So far I'm at:
localfunctiontoggle_checkbox_with_date()
localline=vim.api.nvim_get_current_line()
vim.notify("Current line: " ..line)
localdate_format="%Y-%m-%d %a %H:%M"localtimestamp_pattern="%[%d%d%d%d%-%d%d%-%d%d% %a% %d%d:%d%d%]$"localcheckbox_pattern="^%s*-%s*%[([xX ])%]%s*(.*)"localis_checkbox=line:match(checkbox_pattern)
ifis_checkboxthenvim.notify("Checkbox state: " ..is_checkbox)
-- Call the orgmode toggle_checkbox functionlocalOrgMappings=require("orgmode.org.mappings")
OrgMappings:toggle_checkbox()
localupdated_line=vim.api.nvim_get_current_line()
vim.notify("Updated line after toggle: " ..updated_line)
ifis_checkbox=="" thenlocalnew_line=updated_line.." [" ..os.date(date_format) .."]"vim.notify("New line: " ..new_line)
vim.api.nvim_set_current_line(new_line)
elseifis_checkbox:lower() =="x" thenlocalnew_line=updated_line:gsub(timestamp_pattern, ""):gsub("%s+$", "")
vim.notify("New line: " ..new_line)
vim.api.nvim_set_current_line(new_line)
endelsevim.notify("Not a checkbox line")
endendvim.api.nvim_create_user_command("DebugToggleCheckbox", function()
toggle_checkbox_with_date()
end, {})
-- Define the keymap for toggling checkboxes with date handlingvim.api.nvim_set_keymap("n", "<C-f>", "", { noremap=true, silent=true, callback=toggle_checkbox_with_date })
My problem is that I don't know how to call the toggle_checkbox() function from within my function. I've checked the API and saw no entry there.
I also don't know how to check with the API if the current headline is a TODO or a regular headline, as my functionality only makes sense for TODO items.
My plan would be to convert this to a plugin (once I know how!, I'll check telescope-orgmode).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to tweak how the
toggle_checkbox
works to:The idea is that from this snippet:
I get:
And if I toggle it again it returns back to the original.
I'm quite new with lua so I'm having newbie confusion. So far I'm at:
My problem is that I don't know how to call the
toggle_checkbox()
function from within my function. I've checked the API and saw no entry there.I also don't know how to check with the API if the current headline is a TODO or a regular headline, as my functionality only makes sense for TODO items.
My plan would be to convert this to a plugin (once I know how!, I'll check telescope-orgmode).
Thanks for your help (•‿•)
Beta Was this translation helpful? Give feedback.
All reactions