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

global-ts-fold-mode breaks evil folding for unsupported languages #3

Closed
eeshugerman opened this issue Dec 18, 2021 · 8 comments
Closed
Labels
question Further information is requested

Comments

@eeshugerman
Copy link

eeshugerman commented Dec 18, 2021

If I enable global-ts-fold-mode and then try to use evil folding (evil-close-fold) with an unsupported major mode (eg sql-mode), I get

Error: (user-error "Ignored, tree-sitter-mode is not enable in the current buffer")

Is there some way this could be avoided?

Alternatively (or in addition), could ts-fold define (and autoload) a list of supported major modes?

My specific use case is a Spacemacs layer (which I hope to get merged upstream) that (optionally) enables ts-fold for all supported languages -- ideally we wouldn't have to maintain that list in the layer. I imagine this would benefit many non-Spacemacs users as well, for basically the same reason.

@jcs090218
Copy link
Member

You might want to enable tree-sitter-mode globally as well? Try

(global-tree-sitter-mode 1)

@eeshugerman
Copy link
Author

I have global-tree-sitter-mode enabled. The issue is in major modes that tree-sitter-mode does not support.

I just took a closer look -- global-tree-sitter-mode does not actually enable tree-sitter-mode in major modes that it does not support. If global-ts-fold-mode could do the same, that would resolve this issue.

@jcs090218
Copy link
Member

Sorry for the late reply. Kinda got busy in a time.

Ah, okay. I think the message Ignored, tree-sitter-mode is not enable in the current buffer is just a kind message to inform user about the state of ts-fold. It's should harm you from any aspect.

@eeshugerman
Copy link
Author

It does do harm: it breaks evil-fold (in unsupported major modes). Instead of folding, the error is thrown.

Perhaps if it were message instead of user-error logging the message, then folding would still work, but I'm not sure about that.

@jcs090218
Copy link
Member

I assumed you are talking about the fallback scenario? If that's the case, should evil-fold handle this condition itself? 😕

Perhaps if it were message instead of user-error logging the message, then folding would still work, but I'm not sure about that.

user-error will abort the operation for sure.

@jcs090218 jcs090218 added the question Further information is requested label Jul 6, 2022
@eeshugerman
Copy link
Author

eeshugerman commented Jul 6, 2022

From what I can tell evil-fold is working as intended.

I tried replacing user-error with message in ts-fold--ensure-ts. This did not fix folding. It turns out this is not surprising if we look at how evil-fold uses evil-fold-list: https://githubt.com/emacs-evil/evil/blob/master/evil-commands.el#L3080-L3101

  • "actions" are performed in a with-demoted-errors form
  • only the first matching action (by mode) is performed (ie there is no fallback scenario -- if that's what you meant?)

So to remedy this, we need some way to enable ts-fold-mode in supported major modes only. Currently, to this end, we have defined a list of supported modes for ts-fold in Spacemacs. This works, but is not ideal -- it would be nice if we (the user) did not have to maintain that list.

@samrjack
Copy link
Contributor

@eeshugerman I don't know if this is still relevant to spacemacs, but the commit above should correct the issue you were facing. Now, when global-ts-fold-mode is used, ts-fold will only be activated in buffers where tree-sitter is also enabled AND only when the major mode has defined folds. That way, it shouldn't eat the evil-fold request without knowing that it can be handled.

eeshugerman added a commit to eeshugerman/spacemacs that referenced this issue Dec 30, 2022
This is possible now since emacs-tree-sitter/ts-fold#3
has been resolved.
eeshugerman added a commit to eeshugerman/spacemacs that referenced this issue Dec 30, 2022
This is possible now since emacs-tree-sitter/ts-fold#3
has been resolved.
@eeshugerman
Copy link
Author

@samrjack great news! As you can see above, I've opened a PR to take advantage of this in Spacemacs. Thanks for tackling this!

smile13241324 pushed a commit to syl20bnr/spacemacs that referenced this issue Jan 1, 2023
This is possible now since emacs-tree-sitter/ts-fold#3
has been resolved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants