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

Anonymous function arguments are mangled in a very annoying way #21

Closed
maxaf opened this issue May 19, 2011 · 7 comments
Closed

Anonymous function arguments are mangled in a very annoying way #21

maxaf opened this issue May 19, 2011 · 7 comments

Comments

@maxaf
Copy link

maxaf commented May 19, 2011

I've found that anonymous functions with arguments that aren't on the same line as the opening curly bracket end up moved to that line. There also doesn't appear to be a way to configure this behavior.

Am I missing an existing configuration option, or could one be added that would allow me to turn this off?

Here's an example of what I mean:

Before:

object HelloThere {
  val Things = "a" :: "b" :: Nil
  def foo {
    Things.foreach {
      thing =>
        println("_%s".format(thing))
    }
  }
}

After:

object HelloThere {
  val Things = "a" :: "b" :: Nil
  def foo {
    Things.foreach { thing =>
      println("_%s".format(thing))
    }
  }
}
@mdr
Copy link
Collaborator

mdr commented May 19, 2011

Hmm, yeah, there's no option to control that right now. I think the best solution would be simply to have it leave the argument wherever it was originally.

@maxaf
Copy link
Author

maxaf commented May 19, 2011

That would work for me. Thanks!
On May 19, 2011 5:48 PM, "mdr" <
reply@reply.github.com>
wrote:

@mdr mdr closed this as completed in 2c30ab9 Jul 18, 2011
@rktoomey
Copy link
Contributor

Hi, I see that CompactEnsuringGap appears in 2c30ab9 but there doesn't appear to be a supported config param for it yet?

I can try to take care of this any send you a pull request if you like.

@mdr
Copy link
Collaborator

mdr commented Jul 26, 2011

Yeah...the fix was just to preserve whatever was in the code -- i.e. output a newline before the parameter if and only if there was one in the source already. So no extra preference option needed to be added.

Are you saying you'd like a feature where the user could force it one way or the other with a preference?

@rktoomey
Copy link
Contributor

oh yes - we absolutely hate having our anonymous function arguments
slurped back up to the preceding line.

coll.map {
v => v.somethingOrOther(blah, blah)
}

forcibly turns into

coll.map { v =>
v.somethingOrOther(blah, blah)
}

which i personally dislike, although i wasn't willing to go to the
wall for it like i was with the compact control readability style....
:)

i know how to add the preference everywhere from the so i could easily
put together a pull request for you tonight if that's ok.

On 26 July 2011 15:36, mdr
reply@reply.github.com
wrote:

Yeah...the fix was just to preserve whatever was in the code -- i.e. output a newline before the parameter if and only if there was one in the source already. So no extra preference option needed to be added.

Are you saying you'd like a feature where the user could force it one way or the other with a preference?

Reply to this email directly or view it on GitHub:
#21 (comment)

@mdr
Copy link
Collaborator

mdr commented Jul 26, 2011

OK, cool...but just to make sure we're on the same page: the behaviour now is that it won't forcibly move the argument -- it will be left right where it is. It's "preserve" behaviour.

Adding a new preference then becomes a little more tricky because it's a tri-state: either force a newline before the parameter, force no newline before the parameter, or preserve a newline if there.

Your example reveals another problem I hadn't noticed -- the newline after the arrow. We now transform:

coll.map {
  v => v.somethingOrOther(blah, blah)
}

into

coll.map {
  v => 
    v.somethingOrOther(blah, blah)
}

Which I think is a mistake -- it should keep it on one line.

@rktoomey
Copy link
Contributor

Actually, no need for anything - I reformatted the code last night
against 1.1-SNAPSHOT built from your latest checkin and everything
looks great!

On 26 July 2011 16:00, mdr
reply@reply.github.com
wrote:

OK, cool...but just to make sure we're on the same page: the behaviour now is that it won't forcibly move the argument -- it will be left right where it is. It's "preserve" behaviour.

Adding a new preference then becomes a little more tricky because it's a tri-state: either force a newline before the parameter, force no newline before the parameter, or preserve a newline if there.

Your example reveals another problem I hadn't noticed --  the newline after the arrow. We now transform:

coll.map {
 v => v.somethingOrOther(blah, blah)
}

into

coll.map {
 v =>
   v.somethingOrOther(blah, blah)
}

Which I think is a mistake -- it should keep it on one line.

Reply to this email directly or view it on GitHub:
#21 (comment)

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

No branches or pull requests

3 participants