Closed grepinsight closed 2 years ago
@kristijanhusak I started working on this and am stuck on how to determine the parent headline of a paragraph. Is there an easy way from the current line of the cursor to the treesitter node that line belongs to?
PS: I thought of mapping this to <Leader>oh
, since it's still free. Let me know if you think a different mapping would make more sense (since e.g. checkbox toggling is done with <C-Space>
).
@jgollenz This should give you the closest headline from your current position: https://github.com/nvim-orgmode/orgmode/blob/master/lua/orgmode/org/mappings.lua#L61
the closest headline from your current position
Ah, the naming of that function confused me. I though it will return the headline with the lowest line diff from my current position. Thank you!
@grepinsight do you mind having a look at this #198? One thing I'm not sure how to handle is tags. Would you expect tags to disappear or should they just remain at the end of the line without any impact? I'd prefer the latter, because it is non-destructive (should you decide to turn the line back into a headline) and already works
Org-mode also allows toggling a checkbox item into a headline:
- [ ] item
becomes * TODO item
but then
* TODO item
becomes TODO item
In general: toggling a list item to a headline and toggling that headline again will result in a paragraph line. Can you think of any other cases besides paragraph lines and list items that I need to consider?
Aside from that, Org-mode does not insert any spaces in front of a headline that was toggled to a paragraph line. However, I think it makes sense to insert them according to org_indent_mode
Thank you for implementing this @jgollenz ! Turning simple text into heading works and vice versa.
Would you expect tags to disappear or should they just remain at the end of the line without any impact? I'd prefer the latter, because it is non-destructive (should you decide to turn the line back into a headline) and already works
I just confirmed with my emacs that emacs does the latter (at least in my setting, which is doom emacs). I think as a user, that's a sensible default because it's non-destructive as you said
In general: toggling a list item to a headline and toggling that headline again will result in a paragraph line.
This is also the behavior I observed in emacs as well.
One thing I wished the feature branch had that was missing was ability to toggle multiple lines of text into multiple headings by visual mode
Other than this, it looks pretty solid. Thank you!
@grepinsight Thank you for testing it :)
toggle multiple lines of text into multiple headings by visual mode
I assume selecting multiple lines in visual mode is the Vim equivalent of what Emacs/Orgmode calls "regions", correct? I have a look at this, but please tell me what happens in Emacs when there is both normal lines and headlines in the region:
conclusion: Looks like if there are mixed types in visual selection, only first type in the visual selection is affected
cc @jgollenz
@grepinsight thanks for clarifying :) I'll see what I can do
@grepinsight one more thing: could you please let me know how it behaves when you have a blank line as the first line in the visual selection?
Thanks for being thorough @jgollenz
When you have a blank line(s) as the first line in the visual selection, they are simply ignored and the first non blank lines are used for toggle
@kristijanhusak support for toggling multiple lines would entail a visual mode mapping. As far as I can see we are only using normal mode mappings right now, hard-coded in the setup_mappings
function if I'm not mistaken. I don't know how many emacs orgmode features rely on regions/visual selections, but IF we want to support them, we should think of how to do it properly. I'd prefer to do that in a different PR then. What's your opinion on this?
@jgollenz for now implement only the normal mode mapping. At one point I'll figure out how to set up multiple mode mappings and we can introduce it then. I don't think it's a big of an issue without the visual mapping here.
Does this feature exist in Emacs orgmode core?
Yes
Orgmode link
https://orgmode.org/manual/Structure-Editing.html
Feature value
Ability to quickly turn arbitrary text into org headings will improve UX
Additional context
org-toggle-item
which isC-c -
in emacs would be also nice to have. This converts text into a list.