[Feature request]: how to narrow view to the subtree
-
In the org-mode, is there any way to show contents of only the clicked entry (in the main window) by the narrow view (In org-mode itself, this can be down by
org-narrow-to-subtreeorC-x n s)? The narrow-view may help to focus on the clicked entry. -
Now, imenu-list afford
imenu-list-after-jump-hookto make the headline of the entry at the center or top of the window, which can partly help to focus on the clicked entry. Here, I want it to be at the top, so I use the following setting. This setting need setrecenter-positions. Is there any simple way to directly set headline (cussor) position just for imenu-list?
(setq imenu-list-after-jump-hook 'recenter-top-bottom)
(setq recenter-positions '(top middle bottom))
- Maybe Bugs: While all the entries are folded in the Ilist buffer, when I click one entry to see the content in the mainbuffer, all the folded entries in the Ilist buffer are unfolding immediately. How can I remove this effect? Take the file structures in the end for example.
- In Ilist, we may show only level-1 sections ('section 1' and 'section2') by folding them;
- Then I want to see the subsection list of 'section 1'. I click it , and get the list-show of subsection A and B. Of course now, the subsections of section 2 is still folded.
- However, if I want to check the content of 'subsection A' by clicking it, I find beside the content of 'subsection A' is shown in the main window, the 'section 2' in Ilist window is also unfolded - I can not see subsection C and D.
* section 1
** subsection A
** subsection B
* section 2
** subsection C
** subsection D
After some research,
Prob. 1 can be easy solved. To get narrow view, Just use (setq imenu-list-after-jump-hook 'org-narrow-to-subtree);
Prob. 2 is no more necessary while Prob. 1 is solved.
Prob 3. is still unsolved. However, I have more details:
<RET>(orimenu-list-goto-entry) is good to show subsections. While want use it to the last step to see content of subsections, it unfold everything!<SPC>(orimenu-list-display-entry) can well finish the last step work - to show the content without affect the Ilist menu. However, it can not be used for the low level headlines like 'section 1' in above example. It will give errors as follows
Invalid function: (#("subsection A" 0 7 (org-imenu-marker #<marker at 357 in test.org> org-imenu t)) . #<marker at 357 in test.org>)
So, is there any way to combine this two functions?
Is there any simple way to directly set headline (cussor) position just for imenu-list?
Regarding Prob. 2 you could have done this:
(setq imenu-list-after-jump-hook nil)
(add-hook 'imenu-list-after-jump-hook (lambda () (recenter 0)))
Invalid function: (#("subsection A" 0 7 (org-imenu-marker #<marker at 357 in test.org> org-imenu t)) . #<marker at 357 in test.org>)
That's indeed a bug. Imenu doesn't support jumping to non-low-level nodes. RET works because it calls push-button when point is on such nodes. When calling imenu-list-display-entry, it tries to jump to the header with imenu, but because imenu doesn't support this it throws the error above. One solution is to do nothing when imenu-list-display-entry is invoked on headers - it will eliminate the error, but won't change anything else. Another solution is to invoke imenu on the first low-level node under the header when imenu-list-display-entry is invoked on a header - I think this is what you wanted. I think it's doable but will need to research.
Prob. 3 happens because of how imenu-list updates the index buffer. When the index of the main buffer changed, it just rewrites the index entirely. No information about folds is retained and that's why everything unfolds. I need to research how to fix this, but I don't know when I'll have the time to do so.
However, in your case you don't change the contents of the main buffer, so I don't know why imenu-list decides to update the index buffer. This might be another bug. Does it happen only for org-mode buffers?
@phyliu79 new branch named outline should fix this problem:
Invalid function: (#("subsection A" 0 7 (org-imenu-marker #<marker at 357 in test.org> org-imenu t)) . #<marker at 357 in test.org>)
Relevant commits are https://github.com/bmag/imenu-list/commit/f188f0674d7d959b8a042758e2c734ebd2b9ab48 and https://github.com/bmag/imenu-list/commit/42f983de889bd4d71df71613bcce444c256334c1. Can you verify that this problem is fixed, and doesn't cause other issues? (Prob. 3 not fixed yet)
Hi, I re-checked *.org *.tex and *.el:
- the headlines of *.tex can never be folded. So We don't have Prob.3 above;
- *.el afford variable and Types headlines group. However, the functions are not summoned as a group. Whatever, Prob.3 does not exist for *.el.
- Seems that the Prob only exist for *.org.
I also try the new branches. I found your corresponding to both f188f06 and 42f983d are included into one file. I download it from the outline branch. I get the follow result:
- Still no problem with *.tex, *.el;
- Prob.3 is not solved for org-mode- The invalid function problem of
<SPC>still exists; The <RET> expand all list still exists. Also, the problem of42f983dstill exists.<RET>can not get the content of the headlines in the main window, instead it fold/unfold the menu list.
However, there are no more issues. At least outline mode is as good as the original one.
There are some clues about <RET> expanding: The cursor of go-to jump to the main window, even I set (setq imenu-list-focus-after-activation t). While the cursor occurs in the main window, every thing of the menu expanded.
@phyliu79 thanks for testing, I was 99% percent sure that it would fix the invalid function bug, so it's weird it didn't work for you. I'm going to merge the outline branch soon, despite that.
I know why the expansion happens, it's just that implementing the fix isn't obvious. As I wrote, I don't know when I'll have time to fix it, sadly.