go/printer, gofmt: rely on existing line breaks when formatting expression lists

No impact on existing sources.

Fixes #1632.

R=rsc
CC=golang-dev
https://golang.org/cl/4271083
diff --git a/src/pkg/go/printer/nodes.go b/src/pkg/go/printer/nodes.go
index 8f0d74c..2f12038 100644
--- a/src/pkg/go/printer/nodes.go
+++ b/src/pkg/go/printer/nodes.go
@@ -160,19 +160,7 @@
 	// the first linebreak is always a formfeed since this section must not
 	// depend on any previous formatting
 	prevBreak := -1 // index of last expression that was followed by a linebreak
-	linebreakMin := 1
-	if mode&periodSep != 0 {
-		// Make fragments like
-		//
-		// a.Bar(1,
-		//   2).Foo
-		//
-		// format correctly (a linebreak shouldn't be added before Foo) when
-		// doing period-separated expr lists by setting minimum linebreak to 0
-		// lines for them.
-		linebreakMin = 0
-	}
-	if prev.IsValid() && prev.Line < line && p.linebreak(line, linebreakMin, ws, true) {
+	if prev.IsValid() && prev.Line < line && p.linebreak(line, 0, ws, true) {
 		ws = ignore
 		*multiLine = true
 		prevBreak = 0
@@ -237,7 +225,7 @@
 				// lines are broken using newlines so comments remain aligned
 				// unless forceFF is set or there are multiple expressions on
 				// the same line in which case formfeed is used
-				if p.linebreak(line, linebreakMin, ws, useFF || prevBreak+1 < i) {
+				if p.linebreak(line, 0, ws, useFF || prevBreak+1 < i) {
 					ws = ignore
 					*multiLine = true
 					prevBreak = i
diff --git a/src/pkg/go/printer/testdata/expressions.golden b/src/pkg/go/printer/testdata/expressions.golden
index 314d321..788b9cd 100644
--- a/src/pkg/go/printer/testdata/expressions.golden
+++ b/src/pkg/go/printer/testdata/expressions.golden
@@ -619,3 +619,13 @@
 		b.(T).
 		c
 }
+
+
+// Don't introduce extra newlines in strangely formatted expression lists.
+func f() {
+	// os.Open parameters should remain on two lines
+	if writer, err = os.Open(outfile, s.O_WRONLY|os.O_CREATE|
+		os.O_TRUNC,0666); err != nil {
+		log.Fatal(err)
+	}
+}
diff --git a/src/pkg/go/printer/testdata/expressions.input b/src/pkg/go/printer/testdata/expressions.input
index cac22af..2c2ebce 100644
--- a/src/pkg/go/printer/testdata/expressions.input
+++ b/src/pkg/go/printer/testdata/expressions.input
@@ -625,3 +625,13 @@
 	(T).
 	c
 }
+
+
+// Don't introduce extra newlines in strangely formatted expression lists.
+func f() {
+	// os.Open parameters should remain on two lines
+	if writer, err = os.Open(outfile, s.O_WRONLY|os.O_CREATE|
+		os.O_TRUNC, 0666); err != nil {
+	    log.Fatal(err)
+	}
+}
diff --git a/src/pkg/go/printer/testdata/expressions.raw b/src/pkg/go/printer/testdata/expressions.raw
index f22ceeb..0d22779 100644
--- a/src/pkg/go/printer/testdata/expressions.raw
+++ b/src/pkg/go/printer/testdata/expressions.raw
@@ -618,3 +618,13 @@
 		b.(T).
 		c
 }
+
+
+// Don't introduce extra newlines in strangely formatted expression lists.
+func f() {
+	// os.Open parameters should remain on two lines
+	if writer, err = os.Open(outfile, s.O_WRONLY|os.O_CREATE|
+		os.O_TRUNC,0666); err != nil {
+		log.Fatal(err)
+	}
+}