alphapapa / outshine

Org-mode for non-Org buffers
GNU General Public License v2.0
212 stars 23 forks source link

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

Open maxecharel opened 2 years ago

maxecharel commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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.