-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
core.itero.next-iteration should respect groups #938
Comments
I came here to make a similar request. Where I find that the current behavior to be a problem is when navigating around the file in normal mode, since then I'm unlikely to have the cursor at the end of the current list item or heading section. I've made a normal mode keybinding to Here's an example in a Norg file,
Here I'm using [A] [B] and [C] to mark lines. In Doom Emacs, pressing Control + Enter in normal mode (or in insert mode) with the cursor anywhere in these lines will create a new level 2 heading right above Another place where this would come up is if you are typing a list and have a list item spanning multiple lines that you enter normal mode to edit, then want to continue the list. With the current behavior, you have to make sure your cursor is on the last line of that list item. I'm guessing that part of why the behavior is how it currently is is that the use case in mind was when you are first actively typing a list in insert mode and so the cursor is at the end of the line; but the current behavior doesn't seem to generalize well to other contexts. I haven't worked directly with treesitter myself before, but I'm guessing the functionality that @theherk and I are asking for could be handled by a function that uses treesitter to find the end of the appropriate subtree and insert the new heading or list item there. One question I have is whether we should change the behavior of I might try to figure this out over the holidays, though lua + treesitter + plugins are all new to me so. While we're at it, we might as well try to add an equivalent to org-mode's |
Did some hacking on this and think I've achieved the desired behavior by changing the end of the definition of the neorg/lua/neorg/modules/core/itero/module.lua Line 140 in 9021c7c
-- Determine the row to insert the new line after the end of the
-- current node. There are two cases; for list items that are followed
-- by a blank line, the end of the node as returned by treesitter will
-- be on the line with text (in which case, we need to add 1 to then
-- end row); for other cases, it will be at column 0 of the following
-- line (in which case we can use the end row).
local end_row, end_col = current:end_()
cursor_pos = end_row + (end_col == 0 and 0 or 1)
vim.api.nvim_buf_set_lines(
event.buffer,
cursor_pos,
cursor_pos,
true,
{ string.rep(" ", column) .. text_to_repeat .. (should_append_extension and "( ) " or "") }
)
vim.api.nvim_win_set_cursor(
event.window,
{ cursor_pos + 1, column + text_to_repeat:len() + (should_append_extension and ("( ) "):len() or 0) }
)
end
end The if/else clause to determine the |
This commit changes the behavior of the next.iteration command compared to the behavior in the core.itero module. In core.itero, the new heading or list item is inserted immediately after the line the cursor is on. The version in this commit instead inserts the new item after the end of the node. Addresses the issue discussed in nvim-neorg/neorg#938 (comment).
This commit changes the behavior of the next.iteration command compared to the behavior in the core.itero module. In core.itero, the new heading or list item is inserted immediately after the line the cursor is on. The version in this commit instead inserts the new item after the end of the node. Addresses the issue discussed in nvim-neorg/neorg#938 (comment).
Issues
Feature description
Best explained by example. When you are in this position (note the cursor pipe):
And you call
core.itero.next-iteration
, the result should be:But instead, you get:
As though items
item 2a
anditem 2b
are suddenly part of the forthcomingitem 3
.Help
Yes
Implementation help
I am not sure how to contribute this, but I'm sure I could sort it out. The main questions are, do others agree and unfortunately do I have enough time?
The text was updated successfully, but these errors were encountered: