nvim-orgmode / orgmode

Orgmode clone written in Lua for Neovim 0.9+.
https://nvim-orgmode.github.io/
MIT License
3.04k stars 134 forks source link

Narrow/Widen to subtree #200

Open focusaurus opened 2 years ago

focusaurus commented 2 years ago

Does this feature exist in Emacs orgmode core?

Yes

Orgmode link

I don't see a lot of documentation around this but the source org-narrow-to-subtree function declaration is here. I learned about this through spacemacs and the orgmode layer they have there.

Feature value

It lets me hide everything except my current focus. I also use this heavily in workflowy.

Additional context

No response

kristijanhusak commented 2 years ago

I don't think there's an easy way to achieve this in Neovim in a same way Emacs Orgmode does. It hides all the other lines and leaves only the current subtree visible. Neovim can't do that. We could maybe open the current subtree in another window and save it in original window once it's closed.

focusaurus commented 2 years ago

Oh that's a bummer. It seems strange that we can do collapse/expand but not show/hide. I don't understand the details of the limitation.

joshpetit commented 2 years ago

@kristijanhusak I like this idea of creating a buffer that you can edit and then will be saved afterwards. I may try and working on this feature if you think it's valuable, but some clarification and help would be appreciated

kristijanhusak commented 2 years ago

The entire tree (all the way to the top * ) should be put into the buffer?

I think it's only current headline, but I'll double check how Emacs Orgmode behaves

Would it make sense to not allow people to save if the original buffer has been modified since they open up the narrow view? If so is there a way to do this with the vim api?

I think you should follow the same path that levouh took here, since the features are similar: https://github.com/nvim-orgmode/orgmode/pull/151

joshpetit commented 2 years ago

@kristijanhusak Ok cool it's pretty much a copy of that feature haha. It'll be some good practice haven't done something like this.

focusaurus commented 2 years ago

Just note for my use case I often spend all day in a narrow tree on the task I'm doing that day, so I need to write the buffer frequently without needing to close a window or go back to the full wide tree.

joshpetit commented 2 years ago

@focusaurus Could you send a video of an example of how narrow tree works?

focusaurus commented 2 years ago

@joshpetit sure maybe this will help https://d.pr/v/JvdtId

joshpetit commented 2 years ago

Alright seems good so @kristijanhusak I'll implement it to:

joshpetit commented 2 years ago

Just an FYI I'll be busy over the next week but won't forget this haha. It's on my queue.

kristijanhusak commented 2 years ago

I don't think it's any blocker so take your time :)

joshpetit commented 2 years ago

Update: I looked into the implementation of the other feature, and noticed that my experience with lua and the neovim api is very very small 😅. I don't see myself working on this anytime soon so if someone else wants to pick this up that'll be awesome.