jdtsmith / outli

Simple comment-based outline folding for Emacs
GNU General Public License v3.0
104 stars 6 forks source link

Can this work with another outline-regexp? #7

Closed indigoviolet closed 1 year ago

indigoviolet commented 1 year ago

For example, I have

(setq-hook! 'python-mode-hook outline-regexp (python-rx (* space) (or defun decorator)))

Can I use outli-mode to handle # * Head1 style headings on top of the above?

jdtsmith commented 1 year ago

Not sure what you are trying to achieve here. Maybe add an example. You can for example add a function to outli-mode-hook to append something to outline-regexp in python-mode. The problem is that outli understands the depth of a heading based on its stem and repeat chars. If you alter the form of outline matchers it will no longer understand that.

indigoviolet commented 1 year ago

I want to recognize def, or @decorator in Python files as headings for outline to collapse etc (which my setting above already does); but I also want to recognize # * Head1 or # ** Head2 like outli does. Currently outli will override the outline-regexp and so I can only have one or the other.

For example, one way that I imagine this working: outli could let me define an outli-alternate-outline-regexp and set outli-alternate-outline-regexp-level, and treat everything matching the alternate regexp as a heading of that level. That would let me include the above regexp into outli's setup.

indigoviolet commented 1 year ago

Should have also said to begin with: outli is pretty cool, and thank you! I'd like to use it everywhere, hence the question!

jdtsmith commented 1 year ago

I see, thanks. Since outli relies on outline, and that uses a single regex matcher, the alternate regexp would have to be compiled in and then the type of heading would need to be determined based on the combined match. And such alternate headings would have to be placed at a quite low level, so that all containing headings could still collapse it. But then some use heading within functions, so that would conflict. It sounds challenging to get this working in a general and non-confusing manner.

Is this just for folding? It seems like tree-sitter is a better match for this, and could fold other logical blocks precisely, orthogonally to outline. For def/block/var nav, imenu works very well (especially with consult-imenu or similar). And of course lsp can expose things to imenu as well if you use that.