Improve the usability of rust-dbg-wrap-or-unwrap
#498
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While the original implementation of
rust-dbg-wrap-or-unwrap
works in many cases, it has following problems:Issue1. Insertion happens indiscriminately.
For example:
before:
after:
Issue2. Not handling the cursor position after
dbg!()
insertion.Insertion of
dbg!()
indicates that user's intention to debug an expression. if the return value is significant(case 1), the original expression must be surrounded by another expression, which means not handling the cursor position is totally fine, but ifdbg!
's return value is insignificant(case 2), the subsequent action the user will take must be adding an trailing semicolon, for the original implementation in such cases, users must reach the end of line first(C-e or similar) and then add a semicolon.In fact, in practice, the second case is far more common than the first one, we can do some rough statistics on the source files of
rust-lang/rust
:The point is that, whether users insert trailing semicolon or not, moving cursor to the end of
dbg!()
automatically after insertion not only does no harms, but it likely saves one keystroke for most cases.Overall, these patches do nothing more than fixing the issues mentioned above and cutting some unnecessary branches. For the first issue , the result after fixed will be
Other known issues:
rust-dbg-wrap-or-unwrap
still relies onforward/backward-sexp
to move forward/backward the cursor. In some cases where the cursor is inside pattern match arms or a complex structure or similar,C-c C-d
may break the code.