It would be nice to have a sidebar when using org mode. The sidebar would display the headlines of an org file. When a headline is selected, the subheadings and text would be displayed in another buffer.
You can currently do this by using C-c C-x b which is bound to (org-tree-to-indirect-buffer). The command opens a subtree in an indirect buffer which is sort of what I’m looking for, but you have to enter the command each time you land on a new headline.
You can make the process automatic by adding a hook as follows:
(add-hook 'post-command-hook #'org-tree-to-indirect-buffer nil :local)
The solution works, but it’s not quite there.
Searching the internet I found a useful suggestion from the delightfully named My Other Soup’s a Borscht:
M-x occur then search for the regexp "*+ " (note the space at the end)
This gives more of the functionality I want and has the advantage of being customizable. One problem: I wanted the sidebar to appear on the left hand side.
So I looked a little further and discovered side windows.
My first thought was so what? I can already do that by splitting windows. The advantage of side windows is that you can set them to stay in position and to fix the buffer they display. No more losing your layout when you hit C-x 1.
If the above seems a little confusing (and it did to me at first) there’s an example of what you can do here in the Emacs Manual
So I combined the two things I’d learned and came up with the following function:
(defun my-sidebar-occur() (interactive) (setq fit-window-to-buffer-horizontally t) (setq window-resize-pixelwise t) (setq display-buffer-alist `(("\\*Occur\\*" display-buffer-in-side-window (side . left) (slot . 0) (window-width . fit-window-to-buffer) (preserve-size . (t . nil)) (window-parameters . ((no-delete-other-windows . t)))))))
Here’s a video of the process in action.
One last thing. org-sidebar appears to solve my problem, but at the time of writing it’s still a little buggy. It’s nicely done though and could well become the standard in the future. Until then, I’ll use my workaround.