Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

outshine-imenu does not recognize the different heading levels #89

Open
maxecharel opened this issue Dec 11, 2021 · 3 comments
Open

outshine-imenu does not recognize the different heading levels #89

maxecharel opened this issue Dec 11, 2021 · 3 comments

Comments

@maxecharel
Copy link

Hi,
In org-mode, imenu recognizes the different heading levels (here imenu-list, which relies on imenu):
org_imenu_and_imenu-list

However, when using outline-outshine e.g. with ESS, all headings are put on the same level:
outshineoutline_imenu_and_imenu-list

Would it be possible to solve this and to have index items and subitems like in org-mode?

@jdtsmith
Copy link

Not sure if this is related, but python-mode makes a really strange outline-end regexp with similar behavior. I fixed it with

	   (setq-local outline-heading-end-regexp 
		       (default-value 'outline-heading-end-regexp)))

to get outlines parsing normally.

@dankessler
Copy link

dankessler commented Mar 13, 2022

The imenu documentation in the elisp manual details how the behavior of imenu can be customized. From a bit of tinkering, I can see that org-mode does the nesting by locally sets imenu-create-index-function to org-imenu-get-tree.

Fortunately, it does not look like a terribly complicated function (you can go check out the source with M-x find-function RET org-imenu-get-tree RET). It may be possible to either use it directly from outshine (within a let form that would tweak the behavior to account for the commenting that outshine prefixes headlines with) or to just create an analogous outshine-imenu-get-tree that uses the same logic. I assume the former approach would be preferable as it seems that outshine prefers to rely on extant org or outline functionality whenever possible.

I've taken a crack at this in my fork in the branch imenu-nested. I've created a new function outshine-imenu-get-tree which binds org-complex-heading-regexp in a manner similar to org-mode does at initialization but that also accounts for the leading comment characters (when deployed) by outshine. Then, I modify outshine-imenu so that it tells imenu to use outshine-imenu-get-tree when parsing the file. I think outshine-imenu-with-navi-regexp could be similarly modified, but I don't use navi-mode and so I don't understand its logic well enough to be confident that I could change it quickly without breaking it.

Getting this to play nice with imenu-list is another matter, however, although I imagine that in the same way that outshine-imenu wraps a call to imenu, one could create a function outshine-imenu-list that would do the same kind of thing.

Personally, since I use helm I prefer having things flat rather than having to navigate down the hierarchy step-by-step, but perhaps I can take a crack at making an outshine version of helm-org-in-buffer-headings, although some quick googling suggests that maybe helm-navi already does this.

@alphapapa
Copy link
Owner

alphapapa commented Mar 26, 2022

Thanks to all of you for your input here.

I don't use Outshine much anymore, and I don't have time to work on changes as big as the ones mentioned by Dan. I don't think @thblt uses it much anymore, either, but I'm always glad to have his help and input when he's able.

@dankessler If you'd like to propose a PR, and I can grok it easily enough, I'd be glad to merge it, especially if you would be able to help fix any related bugs that might be discovered later (not that your code wouldn't be perfect, of course).

If anyone's interested, for this kind of navigation within a file or project, I'm generally working on Deffy, though it currently only supports Lisp; eventually I may publish it as a separate project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants