-
Notifications
You must be signed in to change notification settings - Fork 207
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
Question: is it expected that inner function objects include braces? #112
Comments
They shouldn't include braces. Depending on the grammar this could be easy to fix or not... For js and go, looks like it require for us to support the
Could also be fixed by the grammar to not include braces inside the block node. |
Looks like we have the same problem with C :/ |
I've also noticed this and want to add that i think it would be great if function foo() {
let bar = 42;
return bar;
} pressing function foo() {
} This means that However, I think that there should be an exception for function foo() {
let bar = 42;
return bar;
} pressing function foo() {
|
} This is similar to how Similarly I've noticed that Note also that if there is is no newline after the function, for instance if it's at the end of the file the newline above the function should be selected instead, which is how |
I don't think that linewise makes sense for var x = function() {
console.log("Hello, world")
} I do agree that |
It is a short-coming that we can only select nodes at the moment. We wanted to trim the braces using a regex directive and use that solution also for language injection. Language injection now uses a hack |
I'm not sure that I'm following, could you please elaborate? Also, did you mean to write |
@Melkster
would delete more than just the function. |
Perhaps there should be an additional command for a linewise "around function" text-object, for instance I personally think that it would be a super useful feature to be able to move around functions using a single text-object which gets the whitespace right immediately, just like one can do with paragraphs and |
|
I'm trying to exclude the braces for
And
I have the latest Neovim and all related plugins in my setup. Thank you. |
@arsham I haven't found a solution yet with this repository, but you may find nvim-treesitter-textsubjects helpful. (It only works for a handful of languages so far, but it's inner object works well with go.) |
@stsewd @theHamsta until
|
Would be ok. If possible all "{" should be patched |
Yup, understood. I'm not sure how many of those languages I would immediately recognize as such, but I can do several, start a PR, and then get feedback about others to fill in. I'm happy to do that if it works for people. Update: I've got the following languages drafted. If anyone can think of an obvious brace language that I've missed, please let me know. My plan is to clean these up and submit an initial PR this weekend.
|
This is still broken/wrong for |
Yup. Unfortunately as I mentioned soon after, I didn't think to include Rust. I don't use the language, and I didn't realize that it was affected when I first made the pull request. There are other ways in which my initial pull request probably needs to be expanded. I meant to do that myself, but I frankly forgot. I definitely won't get to this quickly (I'm a teacher, and it's recommendation-writing season), but by looking at the changes I made to other languages, someone else could probably fix Rust pretty quickly. (You can also test it locally on your machine if you follow the instructions to override predefined textobjects.) |
Ah, I see, I missed your comment! |
This PR #314 should solve this issue |
I have the same issue with c# |
I don't use C#, please verify this work for you #318 |
I do not know if it's related but in c/cpp @block.outer includes braces (and @block.inner selects random stuff) #589 |
(Thanks for the plugin: it is a snap to set up and easy to work with so far.)
I was surprised to see that by default, an inner function object in, for example, Go and Javascript includes the braces. I'm guessing that this is expected behavior and probably a result of how treesitter itself works. But I wanted to confirm that before going further.
I ask because my most common use for inner function objects is that I want to change, delete, or yank all the code in the function body, but in those cases I don't normally want to include the braces. So, I'll need to consider whether it's possible to tweak treesitter's results.
The text was updated successfully, but these errors were encountered: