More Generic
Opened this issue · 2 comments
It's not an issue as such, more a suggestion. I like this plugin but I'm wondering why it cares about what's before the block boundary (for example, the opening parenthesis in "function( foo, bar, baz)"). The first thing I tested the plugin with was this, and it didn't work:
my ( $self, $foo, $bar ) = @_;
I'd have thought it would be a lot easier to write if it didn't care what was outside of the block. In fact, why care about boundaries at all? Why not have it just move the bits around delimited commas in, for example, this: "foo, bar, baz"?
I've just pushed a commit that should fix your example. It was an oversight on my part -- forgot to think about extra whitespace here and there :). Thanks for reporting.
As to why I'm checking for the beginning and end, it's because I'd like the plugin to be smarter than a simple "find the closest comma". There are several use cases I can think of that require knowledge of "beginning" and "end":
foo(1, bar(2, 3), 4)
In this case, you have nested function calls. If I didn't check for boundaries, moving the "2" to the left would place it out of its function call.
foo(1, 2) + bar(3, 4)
Pretty much the same case -- moving the "3" would really not make sense if I didn't know that the round brace is the limit of this list of items.
foo(1, 2, 3)
And then there's cycling. In this example, if you move the "1" leftwise, it goes arround and arrives after the "3". If you don't know when the list starts and ends, you don't know how to move an item to the beginning or to the end, unless it's alone on a line.
The list you show, "foo, bar, baz" is probably easy enough to achieve by setting the "start" to ^
and the end to $
(haven't actually tried it, mind you). That is, if it's just that on a single line. But if there's more content around them, then, in order to know that this list starts from "foo" and not from, say "(foo", I need to know that the (
denotes the start of a delimited list. Of course, maybe I'm missing something -- I'd be glad to learn that there's a much easier way to do what I'm doing, so could you elaborate on that?
In any case, my intention with this plugin is to make it easier to slice and dice function arguments, particularly in ruby. It's a bit complicated over there, what with the lack of round braces, but I'd like to eventually get it working for ruby function arguments as well. To do this, I'm going to iterate on this idea and see what I can achieve. A simple "swap two items by comma" is easy enough to do -- there was a nice reddit thread here. It's just that I want to handle more complex cases that I tend to encounter, and I think it's completely doable. Of course, there will be bumps along the way, as you noticed yourself :).
Ah, that's cool. I didn't realise it was a whitespace issue in my example. I might have been under the naive impression that it was for some reason trying to recognise the "my" keyword!