"Johannes Schindelin via GitGitGadget" <gitgitgad...@gmail.com>
writes:

> @@ -177,8 +178,16 @@ static unsigned ws_check_emit_1(const char *line, int 
> len, unsigned ws_rule,
>       if (trailing_whitespace == -1)
>               trailing_whitespace = len;
>  
> +     if ((ws_rule & WS_IGNORE_FIRST_SPACE) && len && line[0] == ' ') {
> +             if (stream)
> +                     fwrite(line, 1, 1, stream);
> +             written++;
> +             if (!trailing_whitespace)
> +                     trailing_whitespace++;
> +     }
> +
>       /* Check indentation */
> -     for (i = 0; i < trailing_whitespace; i++) {
> +     for (i = written; i < trailing_whitespace; i++) {

It is pleasing to see that with a surprisingly clean and small
change like this we can exempt the initial space byte from
SP-before-HT check and from Indent-with-non-tab at the same time.

Very nice.

One reason why a surprisingly small special case is required is
perhaps because we are blessed with the original code being clean
[*1*], and the fact that a line[0] that is not ' ' will not trigger
any indentation related whitespace errors without this special case,
I guess.

>               if (line[i] == ' ')
>                       continue;
>               if (line[i] != '\t')


[Footnote]

*1* ws.c used to be almost all my code long time ago, but most of
    the shape of the current whitespace_error checking code comes from
    c1795bb08aa which is not mine, and I can say good things about it
    without feeling embarrassingly boasty ;-)

Reply via email to