git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] git-diff: complain about >=8 consecutive spaces in initial indent

From
Josh Triplett <josh@freedesktop.org>
Date
Nov 13, 2007, 23:37 UTC
Message-ID
<473A3552.3060907@freedesktop.org>
In-Reply-To
<7vr6j95c84.fsf@gitster.siamese.dyndns.org>

[CCing David Symonds, because the same comment also applies to his patches.]

Junio C Hamano wrote:
Show 12 quoted lines
> This introduces a new whitespace error type, "indent-with-non-tab".
> The error is about starting a line with 8 or more SP, instead of
> indenting it with a HT.
> 
> This is not enabled by default, as some projects employ an
> indenting policy to use only SPs and no HTs.
> 
> The kernel folks and git contributors may want to enable this
> detection with:
> 
> 	[core]
> 		whitespace = indent-with-non-tab

This seems somewhat broken, whether a project uses tabs for indentation or not. Lines can still legitimately start with many spaces. Tab-based indentation should only use tabs to line up with other tabs, not with characters. (Unfortunately most editors get this wrong when indenting with tabs. I use spaces, not because I ideologically oppose tabs, but because I can't get any editor I want to use to do the right thing with tabs.)

My standard test case for this:
fprintf("some very long string",
        arguments);

Type the first line, and press enter. A good editor should indent to the open parenthesis. However, it should not use a tab, because it needs to match up with the length of "fprintf(". All the editors I know of use a tab; they just blindly replace a tab-width worth of spaces with a tab in initial indentation.

That statement would normally appear indented in a function, so the continuation line should have tabs up to the indentation level of the fprintf, and then 8 spaces. An example more likely to appear at the start of the line, where this indent-with-non-tab heuristic would flag it:

#define macro(arg1, arg2) macro_content \
                          more_macro_content
Another example:
some_type function_name(arg1, arg2, argred, argblue,
                        argmore, argless)

Again, the indentation should use spaces if it wants to line up after the open parenthesis, whether the project uses tabs or spaces for indentation.

(Those examples may or may not match all coding styles; some just indent the continuation lines by a fixed number of tabs, and also treat the first line as a continuation line to keep the indentation consistent. Just presenting them as examples.)

- Josh Triplett
Previous: Junio C HamanoNext: Junio C Hamano
Message 3 of 12 in “War on whitespace: first, a bit of retreat.”
  1. 1/2 War on whitespace: first, a bit of retreat.Junio C Hamano, Nov 2, 2007
  2. 2/2 git-diff: complain about >=8 consecutive spaces in initial indentJunio C Hamano, Nov 2, 2007
  3. Josh TriplettNov 13, 2007
  4. Junio C HamanoNov 14, 2007
  5. David SymondsNov 2, 2007
  6. Andreas EricssonNov 2, 2007
  7. David SymondsNov 2, 2007
  8. Jakub NarebskiNov 2, 2007
  9. David SymondsNov 2, 2007
  10. David SymondsNov 2, 2007
  11. J. Bruce FieldsNov 2, 2007
  12. Junio C HamanoNov 3, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.