jdtsmith / outli

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

Issues with treesitter based major modes #16

Closed isamert closed 5 days ago

isamert commented 1 week ago

treesit.el sets the following:

(setq-local outline-search-function #'treesit-outline-search
                outline-level #'treesit-outline-level)

so, when you enable outli in a treesitter based major mode, typescript-ts-mode for example, the folding will not work correctly.

outli already sets outline-level function. It also, probably, should set the outline-search-function to nil while initializing the mode so that it works as expected.

jdtsmith commented 1 week ago

Is this with Emacs 30?

isamert commented 1 week ago

Yes, forgot to mention that. I am on the following:

GNU Emacs 30.0.90 (build 1, aarch64-apple-darwin23.6.0, NS appkit-2487.70 Version 14.6.1 (Build 23G93)) of 2024-08-23

jdtsmith commented 6 days ago

Aha, hadn't seem that coming. Does setting outline-search-function to nil fully resolve the issue? I'm wondering if having both forms of folding would be appealing (or feasible). What do you think?

isamert commented 6 days ago

Honestly, I didn't even try what the folding provided by treesit.el does. Now that I tried, it does the obvious, you can fold functions etc. I did not find it very satisfactory though, at least in it's current form. Probably I'll keep hs-minor-mode for C-like languages for now.

Having said that, making outli work with treesit would be nice but it may end up being confusing. When I fold the whole file, I only expect the outli outlines to be folded. Not the whole file hierarchy, with functions and all. There may be a way to handle this more gracefully but I suspect that it will be hard to do (all folding functions needs become context-aware).

But of course not integrating them means users of outli will lose the ability to fold with treesit. Currently I am fine with this but if treesit folding becomes superior and de facto way of folding files, then I might reconsider this statement :D

Does setting outline-search-function to nil fully resolve the issue?

Yes, it fully resolves the issue.

jdtsmith commented 6 days ago

That's a very good point. For now HS might still be the superior solution, but treesitter is more precise and would enable folding lots of interesting things (long data structures, for example). I wonder if HS will get treesitter support; presumably it could do this too.

In terms of outli working with tree-sitter, I think that's out of scope. But it could possibly try hard to prevent other tools which want to work with treesitter from breaking. So for example it could "composite" a search function that forms the union of the two search modalities. But then tree-sitter must set the search depth somehow too and you'd have to work around that (e.g. a top-level function inside a 3rd level # *** Heading). Could get complicated.

I've pushed a small change to disable outline-search-function; can you give it a test?

jdtsmith commented 6 days ago

See also: https://github.com/emacs-tree-sitter/treesit-fold

isamert commented 5 days ago

I wonder if HS will get treesitter support; presumably it could do this too.

Yeah I think that would be much better. It's a better fit for code folding, outline mode is, I believe, something different. HS also have more granular control over what needs to be folded etc.

In terms of outli working with tree-sitter, I think that's out of scope. [...] Could get complicated.

Makes sense.

I've pushed a small change to disable outline-search-function; can you give it a test?

Yep, working perfectly. Thank you!