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

Wrong return value of puni-region-balance-p in js2-mode #9

Closed
DamienCassou opened this issue Sep 14, 2021 · 6 comments
Closed

Wrong return value of puni-region-balance-p in js2-mode #9

DamienCassou opened this issue Sep 14, 2021 · 6 comments

Comments

@DamienCassou
Copy link
Contributor

Given this content

values
    .filter((a) => a)
    .filter((a) => a);

in a js2-mode buffer, if I mark the second line and type M-: (puni-region-balance-p (region-beginning) (region-end)) RET, I get nil but I expect a non-nil value because .filter((a) => a) seems balanced to me.

forward-sexp seems to work fine but backward-sexp goes back to the beginning of the first line when invoked with point at the end of second line. forward-sexp-function is nil.

@AmaiKinono
Copy link
Owner

forward-sexp-function is nil.

Could you double check this? It's js2-mode-forward-sexp on my side, and if I set it to nil, I can't reproduce.

This is because a problem in the js2-mode-forward-sexp:

v.f|((a) => a);
// forward-sexp
v.f((a) => a);|
// backward-sexp
|v.f((a) => a);
// forward-sexp
v|.f((a) => a);

It treat this line as an sexp when going backward (using ; as a clue), but doesn't when going forward.

Let me think about how to fix this. I also noticed several other problems in js2-mode.

@DamienCassou
Copy link
Contributor Author

forward-sexp-function is nil.
Could you double check this? It's js2-mode-forward-sexp on my side, and if I set it to nil, I can't reproduce.

you are perfectly right. I don't know what happened but forward-sexp-function is indeed equal to js2-mode-forward-sexp.

Let me think about how to fix this. I also noticed several other problems in js2-mode.

thank you very much. Is it something we could fix in js2-mode directly so you don't need to add a workaround in puni?

@AmaiKinono
Copy link
Owner

Is it something we could fix in js2-mode directly so you don't need to add a workaround in puni?

I think it is. But to fix improper (in Puni's opinion) handling of sexps is the goal of Puni. If we patch js2-mode, we fix this one case. But if we patch Puni, we fix similar problems of other major modes too.

@DamienCassou
Copy link
Contributor Author

I agree with you that a general-purpose workaround in Puni can help for other modes. I opened an issue on the js2-mode project anyway because they might still want to fix the problem on their side.

AmaiKinono added a commit that referenced this issue Sep 15, 2021
@AmaiKinono
Copy link
Owner

Should be fixed. Please test.

@DamienCassou
Copy link
Contributor Author

Thank you very much

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

2 participants