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

Make separator objects respect parentheses #56

Closed
elzibubble opened this issue Apr 24, 2014 · 8 comments · Fixed by #79
Closed

Make separator objects respect parentheses #56

elzibubble opened this issue Apr 24, 2014 · 8 comments · Fixed by #79

Comments

@elzibubble
Copy link

https://asciinema.org/a/9101 - in which I thrash around trying to use these text objects without very much success

As far as I can pin down, separator objects don't respect their context very well. IE a comma-separated list extends through parentheses. I'd love to be able to "da," to delete a function parameter, but this doesn't work for the first or last right now.

If parentheses-respect were an option, that'd be OK, although it'd be nice if you could pick sane behaviour based on filetype.

Besides (), I'd also expect a comma list to end at [], {}, "", '', colon, semicolon and almost certainly others.

@wellle
Copy link
Owner

wellle commented Apr 24, 2014

I definitely agree that it would be useful to have a text object for function arguments. Right now this is not supported. Separator text objects use a very simple mechanic and all actions seen in your screencast are working as expected.

It might be possible to use a more complex logic to account for the use case you mentioned, but that could have implications regarding seeking. Also just ignoring any parentheses might not be enough. In this example I would have to handle matching pairs and skip over separators:

foo(a, 4 + bar(c[0], x), d)

I would like to make handling of arguments possible with targets.vim, but at the moment I don't have a clear idea about what would be reasonable.

If you have any more input on this, please let me know!

I also commented on this topic in #14 (comment):

To be fair, separator text objects can't target the first and last arguments because they are surrounded by different delimiters. I had many thoughts about some special argument text objects because it would be really useful in combination with next and last text objects. An easy way might be to introduce separator classes so that different characters could be used as separators for one text objects. For example dana could delete the next element in a list separated by either of these characters: ,(). But this would not handle nested function calls properly. Doing it right would be much more complicated.

@elzibubble
Copy link
Author

Fair enough, thanks for your response.

@wellle
Copy link
Owner

wellle commented May 5, 2014

Just wanting to let you know that I started working on this. It would be a new text objects a that selects an argument. An argument is text between a pair ((), {}, []), separators (,,, ;;) or a mix of them ((,, ;], ...). It also includes matching pairs inside of an argument, like in the example I gave above.

Besides (), I'd also expect a comma list to end at [], {}, "", '', colon, semicolon and almost certainly others.

I disagree on ", ' and :, because they should be included in an arguments in cases like these:

foo(a, b + "bar", c)
foo(a, b + 'x', c)
foo(a, std::bar, c)

Do you agree on the separators I listed and the behavior I described?

@elzibubble
Copy link
Author

Fantastic news, I hope it goes well!

Re: quotes, I mostly agree on your cases. std::bar is a corner case because
in normal English a colon terminates a list, I don't suppose you want to
get into tailoring separators per file-type though. If you do, you might
want to think about Haskell/Lisps where arguments are space-delimited while
respecting matching pairs. Maybe existing filetype plugins offer some
clues? Ideally clues available at runtime.

The case where there's a parenthetical end-of-line comment is hard to
distinguish from a parenthetical on the last item; suggest you ignore EOL
comments :)

How will you handle a, b, "c, d", e? On c, ia should select just c. Could
aoa be on the cards ('a' object, 'o' outer, 'a' argument) to select "c, d"?
Maybe up to aoooooa? AIUI it's hard to provide an arbitrary length.

Watching my screencast again, I'm not sure why from foo(aaa, bbb, ccc),
da, on aaa deletes bbb? That seems wrong even given separator objects are
very simple. In fact this fails just on aaa, bbb, ccc.

On 6 May 2014 00:25, Christian Wellenbrock notifications@github.com wrote:

Just wanting to let you know that I started working on this. It would be a
new text objects a that selects an argument. An argument is text between
a pair ((), {}, []), separators (,,, ;;) or a mix of them ((,, ;], ...).
It also includes matching pairs inside of an argument, like in the example
I gave above.

Besides (), I'd also expect a comma list to end at [], {}, "", '', colon,
semicolon and almost certainly others.

I disagree on ", ' and :, because they should be included in an arguments
in cases like these:

foo(a, b + "bar", c)foo(a, b + 'x', c)foo(a, std::bar, c)

Do you agree on the separators I listed and the behavior I described?


Reply to this email directly or view it on GitHubhttps://github.com//issues/56#issuecomment-42252737
.

Cheers,
Alexis

@bentomas
Copy link

+1 for function arguments operator. That would be really cool.

@UnrealQuester
Copy link
Contributor

For function arguments there is already PeterRincker/vim-argumentative. Incorporating this functionality in targets.vim might be difficult. I suggest staying true to the 'Do one thing and do it well' philosophy.

@elzibubble
Copy link
Author

I agree - let's close this?

On 29 May 2014 17:13, UnrealQuester notifications@github.com wrote:

For function arguments there is already PeterRincker/vim-argumentative.
Incorporating this functionality in targets.vim might be difficult. I
suggest staying true to the 'Do one thing and do it well' philosophy.


Reply to this email directly or view it on GitHub
#56 (comment).

Cheers,
Alexis

@wellle
Copy link
Owner

wellle commented Jun 4, 2014

@UnrealQuester @lxsli In general I agree. But I think that next and last argument text objects are really useful. I am making good progress in implementing them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants