r/emacs • • Sep 30 '19

A separate buffer as a sidebar

Hi all,

I saw people using a separate buffer as a sidebar, which may be used both to jump to different sections in an org file and as a terminal to find and open files. Here is an example of what I mean: https://vimvalley.com/replacing-scrivener-with-emacs-and-vim/

I mainly use emacs for academic writing and I know little about programing. Can someone tell me how to set things up? I may need some "foolproof" instructions... :)

7 Upvotes

9 comments sorted by

3

u/[deleted] Sep 30 '19 edited Sep 30 '19

imenu-list will show you outline of your file in a side bar if the mode has imenu support. But in the video, they use plain org mode file folded to contents, which is being edited in a separate window with org-tree-to-indirect-buffer function

2

u/github-alphapapa Sep 30 '19

imenu-list is a pretty good solution, but unlike that screencast, it's not an Org buffer, so it has a few limitations: it doesn't update in real-time, Org key-bindings don't work, etc.

Another possibility, similar to that screencast, is to use something like this: https://gist.github.com/alphapapa/968e22ef0f3873dcd4c5609bc6498a44 (which is from one of the answers posted here).

I'm working on polishing that code and including it in org-sidebar.

1

u/[deleted] Oct 01 '19

well, imenu0list can update in realtime, as soon as new info is available for imenu. Org keybindings aren't really needed, because it is outline menu used only for jumping, and available for everything which has imenu support, like Java or C, but I get your point, that when you're editing org you might want to do things with heading, not only jump on those. The real problem with imenu-list is that it shows not all headings but only first two levels, while org buffer can be narrowed to a complete overview.

Gonna watch for your org-sidebar thing with interest, thanks!

1

u/github-alphapapa Oct 01 '19

well, imenu0list can update in realtime, as soon as new info is available for imenu.

No, it has to re-parse the whole Org buffer to rebuild the imenu list. That's not updating in real-time. Updating in real time means, e.g. an indirect buffer showing the same content in two buffers, so a keystroke in one immediately appears in the other.

Org keybindings aren't really needed, because it is outline menu used only for jumping, and available for everything which has imenu support, like Java or C, but I get your point, that when you're editing org you might want to do things with heading, not only jump on those.

They aren't needed if you don't need them. If you do, they are. There's no reason to not be able to do things like set priorities, to-do keywords, etc. in the tree view.

The real problem with imenu-list is that it shows not all headings but only first two levels

That's not correct. e.g. https://i.imgur.com/l35Wlki.png

1

u/[deleted] Oct 01 '19

No, it has to re-parse the whole Org buffer to rebuild the imenu list. That's not updating in real-time.

The fact that it has to re-parser the whole Org buffer means that update is not incremental, but it is still real time, because parsing is done asynchronously on every stroke of SPC or RET tied to some timer to avoid overhead of imenu. Incremental parsing could be used to make it update on every keystroke, but it will be significantly more complicated parsing algorithm.

Updating in real time means, e.g. an indirect buffer showing the same content in two buffers, so a keystroke in one immediately appears in the other.

Sure, imenu-list update is not instant, but that's not a big deal because you use it to acess things that already exist, and if you create something in org document it will appear in imenu-list buffer as fast as possible. You might need to configure the timeout.

They aren't needed if you don't need them. If you do, they are.

Sure, if you do, then this isn't a task for imenu-list as I already said before.

That's not correct. e.g. https://i.imgur.com/l35Wlki.png

Well maybe I need to change some configuration, but as of now I can only see two first levels.

1

u/github-alphapapa Oct 01 '19

it is still real time, because parsing is done asynchronously on every stroke of SPC or RET tied to some timer to avoid overhead

Asynchronous, timer-delayed re-parsing is not real-time. :)

Incremental parsing could be used to make it update on every keystroke, but it will be significantly more complicated parsing algorithm.

Which is why using an indirect buffer is a superior solution. It just needs a bit of UI polishing.

Sure, imenu-list update is not instant, but that's not a big deal because you use it to acess things that already exist, and if you create something in org document it will appear in imenu-list buffer as fast as possible. You might need to configure the timeout.

There are other drawbacks as well. For example, in a large Org buffer, re-parsing the entire buffer to gather all of its headings is slow. And it's a worse user experience for changes to be reflected at some arbitrary time after they are actually made.

What actually shows changes as fast as possible is an indirect buffer. :)

1

u/[deleted] Oct 01 '19

Asynchronous, timer-delayed re-parsing is not real-time. :)

That's how any software actually works, e.g. games handle asynchronous events tied to a timer, judging by your logic games are not realtime.

Which is why using an indirect buffer is a superior solution. It just needs a bit of UI polishing.

I didn't say this isn't true ;) Just mentioned that imenu-list is a somewhat suitable solution

1

u/github-alphapapa Oct 01 '19

Gonna watch for your org-sidebar thing with interest, thanks!

Here you go! Please let me know what you think.

https://www.reddit.com/r/emacs/comments/dbsxn7/finally_solving_the_lack_of_a_treeview_navigation/