-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add comment textobject for surround selection and navigation #1605
Add comment textobject for surround selection and navigation #1605
Conversation
Pushed some changes that fix the issue with comment.inside not working for rust by rebinding to We can discuss what the best letter to bind this textobject to is, but I think after that this is no longer a draft and ready for review. |
baea31f
to
a482330
Compare
a482330
to
bcc9e6e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also be mentioned in usage:
Lines 64 to 71 in a76e948
| Key after `mi` or `ma` | Textobject selected | | |
| --- | --- | | |
| `w` | Word | | |
| `W` | WORD | | |
| `(`, `[`, `'`, etc | Specified surround pairs | | |
| `f` | Function | | |
| `c` | Class | | |
| `p` | Parameter | |
Looks good otherwise 🎉
This is to avoid conflicts with non-alphanumeric characters. There are two reasons why this matters: 1. If `/` is bound, it won't be possible to `mi/` to purposefully match inside of something like a regex, where you may actually mean to do so. 2. In some cases (e.g. Rust), the logic for surround selection seems to miss that there is a binding for `/` and behave as in (1) instead. `o` is chosen because it is a vowel inside "comment", although it could easily be changed to `t` or even `e` if we think that is less likely to conflict with future desired textobject bindings.
There is open question on how to match an entire group of adjacent (comment) nodes, as each sub-comment also gets matched in the capture, effectively negating the group selection. Until we can figure that out, we can't define any sensible `@comment.around` rules in any language.
bcc9e6e
to
acc4f41
Compare
| `]o` | Go to next comment (**TS**) | `goto_next_comment` | | ||
| `[o` | Go to previous comment (**TS**) | `goto_prev_comment` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem intuitive for me, I think ]#
might be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only problem with # is that it is a shifted key usually, making it harder to quickly use, and breaks the pattern of using a letter for the other textobjects. That said, maybe we open an issue for further discussion?
This attempts to add a comment textobject to the surround matching logic. This seems like it would be an easy add, but I'm having trouble getting it to behave at all in Rust. In PHP @comment.inside works fine, but @comment.around does not.
I'm intending to support both @comment.inside and @comment.around, where the difference is that @comment.around should select adjacent line comments, so line comments like the following will match in total:
.. whereas the .inside will only select one such line comment. Both methods are intended identical for block comments.
Once we figure this out it should partially address #1505.