AmaiKinono / puni

Structured editing (soft deletion, expression navigating & manipulating) that supports many major modes out of the box.
GNU General Public License v3.0
393 stars 20 forks source link

puni-slurp-forward unexpected behavior for <> #28

Open jiacai2050 opened 2 years ago

jiacai2050 commented 2 years ago

This happens in rust-mode. | is where cursor is.

Option<|>Result<i64>
// puni-slurp-forward,expected
Option<|Result><i64>
// puni-slurp-forward,unexpected,it should be Option<|Result<i64>>
Option<|Result<>i64>
AmaiKinono commented 2 years ago

Looks like a rust-mode bug to me.

Option<Result>|<i64>
// `forward-sexp`
Option<Result><i64|>
// `backward-sexp`
Option<Result><|i64>

puni-strict-forward-sexp thinks the < after point is a balanced sexp, because it thinks it's just a punctuation. Puni does this because forward-sexp often flies over the following punctuation, see this (in text-mode):

Bar|. Foo bar.
// `forward-sexp`
Bar. Foo| bar.
// `backward-sexp`
Bar. |Foo bar.

And, puni does nothing wrong since it actually is a punctuation!

Option|<Result><i64>
// `describe-char` outputs:
// ... syntax: (>    which means: open, matches > ...
Option<Result>|<i64>
// `describe-char` outputs:
// ... syntax: .    which means: punctuation

My guess is it's a rust-mode bug, or the intermediate state Option<Result><i64> is not valid rust code so rust-mode can't parse it. If this is the case, currently I don't know how to fix it on Puni's side.