--- src/pkg/go/printer/printer.go.nextline 2009-11-12 07:34:11.000000000 +0100 +++ src/pkg/go/printer/printer.go 2009-11-12 14:41:25.000000000 +0100 @@ -893,6 +893,7 @@ GenHTML uint = 1 << iota; // generate HTML RawFormat; // do not use a tabwriter; if set, UseSpaces is ignored UseSpaces; // use spaces instead of tabs for indentation and alignment + NextLine; // put left brace/parenthesis on the next line ) --- src/pkg/go/printer/nodes.go.nextline 2009-11-12 11:26:00.000000000 +0100 +++ src/pkg/go/printer/nodes.go 2009-11-12 14:28:57.000000000 +0100 @@ -339,7 +339,11 @@ } // at least one entry or incomplete - p.print(blank, lbrace, token.LBRACE, indent, formfeed); + if p.Mode&NextLine != 0 { + p.print(newline, lbrace, token.LBRACE, indent, formfeed); + } else { + p.print(blank, lbrace, token.LBRACE, indent, formfeed); + } if ctxt&structType != 0 { sep := vtab; @@ -802,6 +806,9 @@ // block prints an *ast.BlockStmt; it always spans at least two lines. func (p *printer) block(s *ast.BlockStmt, indent int) { + if p.Mode&NextLine != 0 { + p.print(newline); + } p.print(s.Pos(), token.LBRACE); p.stmtList(s.List, indent); p.linebreak(s.Rbrace.Line, 1, maxStmtNewlines, ignore, true); @@ -932,7 +939,11 @@ *multiLine = true; optSemi = true; if s.Else != nil { - p.print(blank, token.ELSE, blank); + if p.Mode&NextLine != 0 { + p.print(newline, token.ELSE); + } else { + p.print(blank, token.ELSE, blank); + } switch s.Else.(type) { case *ast.BlockStmt, *ast.IfStmt: optSemi = p.stmt(s.Else, ignoreMultiLine) @@ -1136,6 +1147,9 @@ if d.Lparen.IsValid() { // group of parenthesized declarations + if p.Mode&NextLine != 0 { + p.print(newline); + } p.print(d.Lparen, token.LPAREN); if len(d.Specs) > 0 { p.print(indent, formfeed); --- src/cmd/gofmt/gofmt.go.nextline 2009-11-12 07:34:10.000000000 +0100 +++ src/cmd/gofmt/gofmt.go 2009-11-12 14:41:49.000000000 +0100 @@ -31,6 +31,7 @@ align = flag.Bool("align", true, "align columns"); tabwidth = flag.Int("tabwidth", 8, "tab width"); usespaces = flag.Bool("spaces", false, "align with spaces instead of tabs"); + nextline = flag.Bool("nextline", false, "put left brace/parenthesis on the next line"); ) @@ -69,6 +70,9 @@ if *usespaces { mode |= printer.UseSpaces } + if *nextline { + mode |= printer.NextLine + } return mode; }