Re: [PATCH 1/4] gitweb: Whitespace cleanup - tabs are for indent, spaces are for align (2)
- From
Junio C Hamano <junkio@cox.net>
- Date
- Oct 22, 2006, 20:22 UTC
- Message-ID
- <7v3b9g5cde.fsf@assigned-by-dhcp.cox.net>
- In-Reply-To
- <200610211752.19891.jnareb@gmail.com>
Jakub Narebski <jnareb@gmail.com> writes:
> Code should be aligned the same way, regardless of tab size. > Use tabs for indent, but spaces for align.
I do not necessarily agree with that policy; the result of applying this patch is still inconsistent in some places, and I think that is primarily because the policy itself is flawed.
For example, a part of sub format_paging_nav looks like this:
sub format_paging_nav {
>>>>>>>>my ($action, $hash, $head, $page, $nrevs) = @_;
...
>>>>>>>>if ($page > 0) {
>>>>>>>>>>>>>>>>$paging_nav .= " ⋅ " .
>>>>>>>>>>>>>>>>>>>>>>>>$cgi->a({-href => href(action=>$a
>>>>>>>>>>>>>>>>>>>>>>>> -accesskey => "p", -titl
>>>>>>>>} else {
...If your policy is to indent continuation lines (which is why you have a TAB before "$cgi->a"), not having a TAB before the continued parameter list for the $cgi->a() call look inconsistent.
If on the other hand your policy is to align parameters to an operator that are spread over multiple lines, " ⋅ " and "$cgi-a(..." are left and right parameters to the string concatenation operator "." in between them, so "$cgi->a" should be pushed back with a run of SP starting at the column that begins $paging_nav and aligned with the DQ at the beginning of the " ⋅ " string.
By the way, is there a handy way to view something like the above with "cat" (like "cat -e" is an easy way to find trailing whitespace problems)? I usually end up running this but I feel that there ought to be a canned command.
#!/usr/bin/perl
my $monochrome = 0; my $tab = 8; my $tab_color = "\033[44m"; my $reset_color = "\033[0m"; my $tab_padchar = ' ';
if ($monochrome) {
$tab_color = $reset_color = '';
$tab_padchar = '>';
}while (<>) {
chomp;
my (@frag) = split(/\t/, $_);
my $pos = 0;
for (my $i = 0; $i < @frag; $i++) {
if ($i) {
my $len = 8 - $pos % 8;
print $tab_color;
print $tab_padchar x $len;
print $reset_color;
$pos += $len;
}
print $frag[$i];
$pos += length($frag[$i]);} print "\n"; }