Feature request: style consistency checking and mimicking an existing file's style

View: New views
3 Messages — Rating Filter:   Alert me  

Feature request: style consistency checking and mimicking an existing file's style

by Dan Hipschman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi all.

This is just a thought, and I know it would be a fair bit of work, which
I don't myself have time for right now, but what do you think of two new
options for GNU indent, --check and --mimic?  First I'll describe
--mimic.  It would read in a sample C file, figure out the style options
that would be used to produce such output, and then use those options
for the remaining (normal) input files.

For example, if foo.c is:

void foo(void)
{
  if (blah) {
    bonk();
  }
}

then 'indent --mimic foo.c' would be equivalent to
'indent -br -npcs -npsl'.  This makes it a lot easier to figure out the
correct options to indent since it's WYSIWYG.  Of course, the style that
is being mimicked needs to be consistent, which brings me to --check.
This would not output anything, but would check that the input has a
consistent style.  That is, there exists a single set of options that
could produce that style.  Implementing --check and --mimic boil down to
pretty much the same thing since to check for consistency we need to
remember what style we see in the file, and once we have that it is not
hard to use it for the output.

Of course, trying to understand arbitrary style could be difficult, if
it happens to fall outside the range of what indent can currently
produce yet still be consistent.  However in that case it could be fair
to simply report that there are no set of options to produce such
output, since we are not really losing any functionality over what we
currently have, but it would reduce headaches for people searching for a
nonexistent set of options.

Apologies if something like this has been proposed; I didn't go through
all the mailing list archives.

Dan


_______________________________________________
bug-indent mailing list
bug-indent@...
http://lists.gnu.org/mailman/listinfo/bug-indent

Re: Feature request: style consistency checking and mimicking an existing file's style

by David Ingamells :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dan Hipschman wrote:

> Hi all.
>
> This is just a thought, and I know it would be a fair bit of work, which
> I don't myself have time for right now, but what do you think of two new
> options for GNU indent, --check and --mimic?  First I'll describe
> --mimic.  It would read in a sample C file, figure out the style options
> that would be used to produce such output, and then use those options
> for the remaining (normal) input files.
>
> For example, if foo.c is:
>
> void foo(void)
> {
>   if (blah) {
>     bonk();
>   }
> }
>
> then 'indent --mimic foo.c' would be equivalent to
> 'indent -br -npcs -npsl'.  This makes it a lot easier to figure out the
> correct options to indent since it's WYSIWYG.  Of course, the style that
> is being mimicked needs to be consistent, which brings me to --check.
> This would not output anything, but would check that the input has a
> consistent style.  That is, there exists a single set of options that
> could produce that style.  Implementing --check and --mimic boil down to
> pretty much the same thing since to check for consistency we need to
> remember what style we see in the file, and once we have that it is not
> hard to use it for the output.
>
> Of course, trying to understand arbitrary style could be difficult, if
> it happens to fall outside the range of what indent can currently
> produce yet still be consistent.  However in that case it could be fair
> to simply report that there are no set of options to produce such
> output, since we are not really losing any functionality over what we
> currently have, but it would reduce headaches for people searching for a
> nonexistent set of options.
>
> Apologies if something like this has been proposed; I didn't go through
> all the mailing list archives.
>
> Dan
>
>
> _______________________________________________
> bug-indent mailing list
> bug-indent@...
> http://lists.gnu.org/mailman/listinfo/bug-indent
>
>
>  
It looks to me like you're proposing something larger than indent itself!
I can't see anyone taking up the challenge, however if they do I'd suggest
that they write an independent program to generate the indent command line
from a given source file.


_______________________________________________
bug-indent mailing list
bug-indent@...
http://lists.gnu.org/mailman/listinfo/bug-indent

Re: Feature request: style consistency checking and mimicking an existing file's style

by Dan Hipschman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Jun 09, 2008 at 08:13:11PM +0200, david ingamells wrote:
> >  
> It looks to me like you're proposing something larger than indent itself!
> I can't see anyone taking up the challenge, however if they do I'd suggest
> that they write an independent program to generate the indent command line
> from a given source file.

I don't think it would be that hard.  I haven't looked at the indent
source, but it seems it must include a C parser that is at least complex
enough to understand what a function looks like, where a block of code
that needs to be indented starts and ends, and things like that.  All
this new feature would require would be to keep track of whitespace in
the input as well, which indent already seems to do a little bit of, at
least WRT newlines.

For example, when indent comes across, say, a comment in the input, it
must be smart enough to know how much to indent it based on the value of
the -c option.  All it would need to do to fill this value in itself is
see how far it is already indented in the mimicked input.  Replace "look
up value of -c and output indented comment" with "check consistency with
existing value of -c if any, and set value of -c."

I haven't gone through every option in the man page and thought about
how to implement it, but skimming through them it seems they mostly fit
the approach above.  It would be a bit of grunt work, but not hard, and
certainly not doubling the size of indent.

This would require far too much duplication to justify a separate
program, and would also require maintenance to be kept up-to-date with
indent.


_______________________________________________
bug-indent mailing list
bug-indent@...
http://lists.gnu.org/mailman/listinfo/bug-indent
LightInTheBox - Buy quality products at wholesale price!