Commit 1fede304 authored by Robert Griesemer's avatar Robert Griesemer

more comment formatting:

- preserve (some) indentation of comment text for /*-style comments
  even if the first comment line does not contain any text that might
  suggest the "correct" indentation
- enabled because otherwise existing larger comments get re-formatted
  (this will not introduce a lot of changes since comments of this
  kind - until now - were not changed with respect to indentation)

R=rsc
http://go/go-review/1016047
parent 7f534246
...@@ -443,27 +443,45 @@ func stripCommonPrefix(lines [][]byte) { ...@@ -443,27 +443,45 @@ func stripCommonPrefix(lines [][]byte) {
// Determine the white space on the first line after the /* // Determine the white space on the first line after the /*
// and before the beginning of the comment text, assume two // and before the beginning of the comment text, assume two
// blanks instead of the /* unless the first character after // blanks instead of the /* unless the first character after
// the /* is a tab. This whitespace may be found as suffix // the /* is a tab. If the first comment line is empty but
// in the common prefix. // for the opening /*, assume up to 3 blanks or a tab. This
// whitespace may be found as suffix in the common prefix.
first := lines[0]; first := lines[0];
suffix := make([]byte, len(first)); if isBlank(first[2 : len(first)]) {
n := 2; // no comment text on the first line:
for n < len(first) && first[n] <= ' ' { // reduce prefix by up to 3 blanks or a tab
suffix[n] = first[n]; // if present - this keeps comment text indented
n++; // relative to the /* and */'s if it was indented
} // in the first place
if n > 2 && suffix[2] == '\t' { i := len(prefix);
// assume the '\t' compensates for the /* for n := 0; n < 3 && i > 0 && prefix[i-1] == ' '; n++ {
suffix = suffix[2:n]; i--;
}
if i == len(prefix) && i > 0 && prefix[i-1] == '\t' {
i--;
}
prefix = prefix[0:i];
} else { } else {
// otherwise assume two blanks // comment text on the first line
suffix[0], suffix[1] = ' ', ' '; suffix := make([]byte, len(first));
suffix = suffix[0:n]; n := 2;
} for n < len(first) && first[n] <= ' ' {
// Shorten the computed common prefix by the length of suffix[n] = first[n];
// suffix, if it is found as suffix of the prefix. n++;
if bytes.HasSuffix(prefix, suffix) { }
prefix = prefix[0 : len(prefix) - len(suffix)]; if n > 2 && suffix[2] == '\t' {
// assume the '\t' compensates for the /*
suffix = suffix[2:n];
} else {
// otherwise assume two blanks
suffix[0], suffix[1] = ' ', ' ';
suffix = suffix[0:n];
}
// Shorten the computed common prefix by the length of
// suffix, if it is found as suffix of the prefix.
if bytes.HasSuffix(prefix, suffix) {
prefix = prefix[0 : len(prefix) - len(suffix)];
}
} }
} }
......
...@@ -168,6 +168,53 @@ func _() { ...@@ -168,6 +168,53 @@ func _() {
} }
func _() {
/*
freestanding comment
aligned line
aligned line
*/
}
func _() {
/*
freestanding comment
aligned line
aligned line
*/
}
func _() {
/*
freestanding comment
aligned line
aligned line */
}
func _() {
/*
freestanding comment
aligned line
aligned line
*/
}
func _() {
/*
freestanding comment
aligned line
aligned line
*/
}
func _() {
/*
freestanding comment
aligned line
aligned line */
}
/* /*
* line * line
* of * of
...@@ -194,6 +241,18 @@ blank line in middle: ...@@ -194,6 +241,18 @@ blank line in middle:
with no leading spaces on blank line. with no leading spaces on blank line.
*/ */
/*
aligned in middle
here
not here
*/
/*
blank line in middle:
with no leading spaces on blank line.
*/
func _() { func _() {
/* /*
* line * line
...@@ -202,15 +261,15 @@ func _() { ...@@ -202,15 +261,15 @@ func _() {
*/ */
/* /*
aligned in middle aligned in middle
here here
not here not here
*/ */
/* /*
blank line in middle: blank line in middle:
with no leading spaces on blank line. with no leading spaces on blank line.
*/ */
} }
......
...@@ -168,6 +168,53 @@ func _() { ...@@ -168,6 +168,53 @@ func _() {
} }
func _() {
/*
freestanding comment
aligned line
aligned line
*/
}
func _() {
/*
freestanding comment
aligned line
aligned line
*/
}
func _() {
/*
freestanding comment
aligned line
aligned line */
}
func _() {
/*
freestanding comment
aligned line
aligned line
*/
}
func _() {
/*
freestanding comment
aligned line
aligned line
*/
}
func _() {
/*
freestanding comment
aligned line
aligned line */
}
/* /*
* line * line
* of * of
...@@ -194,6 +241,18 @@ blank line in middle: ...@@ -194,6 +241,18 @@ blank line in middle:
with no leading spaces on blank line. with no leading spaces on blank line.
*/ */
/*
aligned in middle
here
not here
*/
/*
blank line in middle:
with no leading spaces on blank line.
*/
func _() { func _() {
/* /*
* line * line
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment