logo       

Re: Indenting the source: msg#00035

lang.nasm.devel

Subject: Re: Indenting the source

H. Peter Anvin wrote:
Okay, I personally find the style used in outbin.c (and quite possibly other files) to be atrocious; it's hard to read and even harder to make emacs not to butcher.

I would like to propose making the following GNU indent command the preferred style:

indent -kr -i4 -ts8 -nut -sob -ss -ncs

... it is very simple K&R-style indent with 4 spaces indentation. It's not the one I usually use, but my preferred style is hard to generate for non-Emacs uses.

The commands mean, in order:

-kr -- K&R style
-i4 -- indent is 4 spaces
-ts8 -- a tab character is 8 spaces
-nut -- don't generate tab characters
-sob -- swallow optional blank lines
-ss -- space before semicolons in one-line for and while
-ncs -- no space after casts

This is similar to what the Linux kernel uses, except the indentation is 4. I'm proposing to not use tabs simply because it makes life harder for some editors to have indent != tab size, if people disagree then I'd remove that. I really want to avoid tab size != 8 though.

About 3.5 years ago, I proposed something very similar and still think it's worthwhile. At that time, (see http://groups.yahoo.com/group/nasm-devel/message/759 ) I advocated:

indent -i4 -br -brs -npsl -npcs -nut -c33 -ce -cd33 -nlp -ci8 *.c

Some of these (-i4 and -nut) are the same; the others are as follows:

-br -- braces on if line
-brs -- braces on struct declaration line
-c33 -- comment indentation of 33 spaces
-ce -- cuddle else and preceding '}'
-cd33 -- declaration comment column = 33
-ci8 -- continuation indentation of 8 spaces
-nlp -- don't line up parentheses
-npcs -- no space after function call names
-npsl -- don't break procedure type

Also note that -kr is basically just an abbreviation for:

-nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0
-cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs
-nprs -npsl -saf -sai -saw -nsc -nsob -nss

The net effect, therefore of HPA's line is:

-nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0
-cp33 -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs
-nprs -npsl -saf -sai -saw -nsc -ts8 -nut -sob -ss -ncs

And the net effect of mine would be:

-br -brs -ci8 -i4 -c33 -ce -cd33 -npsl -npcs -nut -nlp

Therefore, while HPA's line specifies more (which is a good thing, IMHO) the only actual *differences* are as follows:

Ed: -ci8 -nlp
HPA: -ci4 -lp

To borrow an example from the indent man pages, the difference would look like this with -ci8 -nlp:

p1 = first_procedure (second_procedure (p2, p3),
third_procedure (p4, p5));

With -ci4 -lp in effect the code looks like this:

p1 = first_procedure (second_procedure (p2, p3),
third_procedure (p4, p5));


Because these are minor differences, I could endorse either, but I would very much like to have one consistently applied style throughout, no matter what that style.

Ed



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise