-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create new checkbox instead of adding numbers #67
Comments
Sorry for the very late reply, ive been busy lately. Have you tried org mode? I am proposing to use a sort of org-mode way of doing lists. There will be a function purely for cycling the list types There will be a mapping that when pressed on top of a checkbox, completes it. (normally bound to enter in emacs) When pressing enter on a list, the new created bullet will inherit the last line's properties (checkbox or no checkbox) There will not be a function for removing checkboxes. this is easily doable in vim, and when creating a new bullet, not using checkboxes is as easy as deleting it. Then with the above changes, the next new bullet will not have checkboxes, as it inherits the no checkbox property. |
Not exactly what you are looking for, but I added a small enhancement to add a checkbox if there is non present in a list: function handle_checkbox()
local config = require("autolist.config")
local auto = require("autolist.auto")
local checkbox_pattern = " [ ]"
local filetype_lists = config.lists[vim.bo.filetype]
local line = vim.fn.getline(".")
for i, list_pattern in ipairs(filetype_lists) do
local list_item = line:match("^%s*" .. list_pattern .. "%s*") -- only bullet, no checkbox
list_item = list_item:gsub("%s+", "")
local is_list_item = list_item ~= nil -- only bullet, no checkbox
local is_checkbox_item = line:match("^%s*" .. list_pattern .. "%s*" .. "%[.%]" .. "%s*") ~= nil -- bullet and checkbox
if is_list_item == true and is_checkbox_item == false then
vim.fn.setline(".", (line:gsub(list_item, list_item .. checkbox_pattern, 1)))
local cursor_pos = vim.api.nvim_win_get_cursor(0)
vim.api.nvim_win_set_cursor(0, {cursor_pos[1], cursor_pos[2] + checkbox_pattern:len()})
goto continue
else
auto.toggle_checkbox()
goto continue
end
end
::continue::
end May be it is useful for you as well. |
Amazing! That's super convenient. Works great! |
I've been using the
The behaviour that would make sense to me if I were on the first node is to return:
Is this something difficult to fix, or would a minor tweak to what you provided fix it. Thanks again for your help! |
I have used it only with function M.handle_checkbox()
local config = require("autolist.config")
local auto = require("autolist.auto")
local checkbox_pattern = " [ ]"
local filetype_list = config.lists[vim.bo.filetype]
local line = vim.fn.getline(".")
for i, list_pattern in ipairs(filetype_list) do
local list_item = line:match("^%s*" .. list_pattern .. "%s*") -- only bullet, no checkbox
if list_item == nil then goto continue_for_loop end
list_item = list_item:gsub("%s+", "")
local is_list_item = list_item ~= nil -- only bullet, no checkbox
local is_checkbox_item = line:match("^%s*" .. list_pattern .. "%s*" .. "%[.%]" .. "%s*") ~= nil -- bullet and checkbox
if is_list_item == true and is_checkbox_item == false then
list_item = list_item:gsub('%)', '%%)')
vim.fn.setline(".", (line:gsub(list_item, list_item .. checkbox_pattern, 1)))
local cursor_pos = vim.api.nvim_win_get_cursor(0)
if cursor_pos[2] > 0 then
vim.api.nvim_win_set_cursor(0, {cursor_pos[1], cursor_pos[2] + checkbox_pattern:len()})
end
goto continue
else
auto.toggle_checkbox()
goto continue
end
::continue_for_loop::
end
::continue::
end |
not sure if you had the chance to test the updated code above |
Thanks @kraxli I tried again and got your updated code working. I then modified it to this monstrosity (I am very much a beginner at Lua):
It works, cycling checkboxes through the following:
And round and round. I noticed that my linter says, "Unused local 'i'" at the beginning of the for-loop. There is also some funny business about where the cursor gets moved to if it is too close to the start of a line. In any case, I'd love any help improving this if someone knows how. |
Suppose that I have a list like:
Now say that I am hovering on the "some other point" line and run the
invert_entry
function with the mappings provided. Currently autolist turns it into an numbered list to all lines at that indentation. Intuitively what I would expect (and want) is that it would add the empty box on just the current line so that it looks like- [x]
.I should say that I like how autolist toggles through just
- [ ]
and- [x]
withinvert_entry
instead of also including-
with no box in the cycle. However, wheninvert_entry
is run on-
with no box, it would be great it if added a checked box so that it looks like- [x]
. If one wanted to remove a box altogether (empty or otherwise), that would have to be handled by a separate function which removes the box (empty or otherwise). In practice, I mostly don't remove boxes once they are added, so this further function is not super important for me.It would also be helpful to have a function which toggles between unnumbered dashes like
-
and a numbered list. For instance, consider the list (A) below:Were I to run the imagined toggle numbering function, I think the most natural result would be (B):
Toggling number again would then return the (A) list. To summarise, here is the feature set I'm imagining:
Hope that all makes sense, and thanks again for a great plugin!
The text was updated successfully, but these errors were encountered: