Thread: Indent
>From FAQ_DEV: "pgindent will format source files to match our standard format, whichhas four-space tabs, and an indenting format specifiedby flags to theyour operating system's utility indent." Then why are all files indented with eight spaces? I personally like the four spaces, straight bsd style in Emacs and -orig in indent. But at least it should be consistent. Also, how can I prevent this from happening: void print_copyright(void) { puts( " PostgreSQL Data Base Management System Copyright(c) 1996 - 9PostgreSQL Global Development Group instead of void print_copyright(void) { puts( " PostgreSQL Data Base Management System Copyright(c) 1996 - 9 PostgreSQL Global Development Group ? Looks really ugly in the output. -- Peter Eisentraut Sernanders vaeg 10:115 peter_e@gmx.net 75262 Uppsala http://yi.org/peter-e/ Sweden
> >From FAQ_DEV: > > "pgindent will format source files to match our standard format, which > has four-space tabs, and an indenting format specified by flags to the > your operating system's utility indent." > > Then why are all files indented with eight spaces? I personally like the > four spaces, straight bsd style in Emacs and -orig in indent. But at least > it should be consistent. My guess is that you have tabs set to four spaces in your editor. Change it to 4-space tabs and you will be fine. > > Also, how can I prevent this from happening: > > void > print_copyright(void) > { > puts( > " > PostgreSQL Data Base Management System > > Copyright(c) 1996 - 9 PostgreSQL Global Development Group > > instead of > > void > print_copyright(void) > { > puts( > " > PostgreSQL Data Base Management System > > Copyright(c) 1996 - 9 PostgreSQL Global Development Group > > ? > Looks really ugly in the output. Yes, it certainly does. I changed it the quotes to " " newline " ", and committed the cleanup. Ran it through pgindent and it looks fine now. -- Bruce Momjian | http://www.op.net/~candle maillist@candle.pha.pa.us | (610) 853-3000+ If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania19026
> "pgindent will format source files to match our standard format, which > has four-space tabs, and an indenting format specified by flags to the > your operating system's utility indent." > Then why are all files indented with eight spaces? The FAQ isn't clear on this at all. pg_indent *assumes* that all tabs will be four spaces. One must set vi or emacs to tab every four spaces for things to look right. Apparently we never send source code directly to a printer ;) - Thomas -- Thomas Lockhart lockhart@alumni.caltech.edu South Pasadena, California
> > "pgindent will format source files to match our standard format, which > > has four-space tabs, and an indenting format specified by flags to the > > your operating system's utility indent." > > Then why are all files indented with eight spaces? > > The FAQ isn't clear on this at all. pg_indent *assumes* that all tabs > will be four spaces. One must set vi or emacs to tab every four spaces > for things to look right. DEV FAQ says: <I>pgindent</I> will format source files to match our standard format, which has four-space tabs, > > Apparently we never send source code directly to a printer ;) I run it through vgrind or use crisp to print with color syntax highlighting. However, I do convert the tabs to 4-character spaces before printing. It is a pain, but indenting/unindenting without tab=indent level is a pain, and 8-space tabs are too large. -- Bruce Momjian | http://www.op.net/~candle maillist@candle.pha.pa.us | (610) 853-3000+ If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania19026
> > > "pgindent will format source files to match our standard format, which > > > has four-space tabs, and an indenting format specified by flags to the > > > your operating system's utility indent." > > > Then why are all files indented with eight spaces? > > The FAQ isn't clear on this at all. pgindent *assumes* that all tabs > > will be four spaces. One must set vi or emacs to tab every four spaces > > for things to look right. > DEV FAQ says: > <I>pgindent</I> will format source files to match our standard format, > which has four-space tabs, Right, I saw this the first time ;) My point is that this statement is ambiguous, particularly for those who didn't grow up in Pennsylvania or some other all-English locale. "four-space tabs" could imply that all tabs are filled with four spaces, but in fact pgindent replaces every four spaces with a tab. I haven't stumbled across any mention of setting text editors or printing, which if it was mentioned might reduce the possibility for confusion. - Thomas -- Thomas Lockhart lockhart@alumni.caltech.edu South Pasadena, California
> My point is that this statement is ambiguous, particularly for those > who didn't grow up in Pennsylvania or some other all-English locale. > "four-space tabs" could imply that all tabs are filled with four > spaces, but in fact pgindent replaces every four spaces with a tab. > > I haven't stumbled across any mention of setting text editors or > printing, which if it was mentioned might reduce the possibility for > confusion. New DEV FAQ reads: Our standard format is to indent each code level with one tab, where each tab is four spaces. You will need to set your editor to display tabs as four spaces. <I>pgindent</I> will the format code by specifying flags to your operating system's utility <I>indent.</I><P> <I>pgindent</I> is run on all source files just before each beta test -- Bruce Momjian | http://www.op.net/~candle maillist@candle.pha.pa.us | (610) 853-3000+ If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania19026
Thus spake Thomas Lockhart > The FAQ isn't clear on this at all. pg_indent *assumes* that all tabs > will be four spaces. One must set vi or emacs to tab every four spaces > for things to look right. > > Apparently we never send source code directly to a printer ;) Or else we pipe it through "pr -e4" first. -- D'Arcy J.M. Cain <darcy@{druid|vex}.net> | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
Hi Peter,This puzzled me for some time too, I am guessing that you are using emacs to edit the code, and you are being tripped up by emacs use of 8 spaces for a tab symbol. You can change the emacs tab width by configuring the emacs variable tab-width. You can do this on the buffer that you are editing by using C-h v tab-width to pull up a buffer that allows you to customize the variable, or you can use a hook to c-mode to set it whenever you are editing a c-file. I have the following lines in my .emacs file ;;; Set tab-width in c-mode to 4 spaces (add-hook 'c-mode-hook (function (lambda () (set tab-width 4)))) I think that there are some other small differences between emacs c-mode formatting and the indent formatting that PostgreSQL uses, but the 8-space tab is the only one that I have fixed. Bernie
UNSUBSCRIBE ME FROM THIS LIST!!!!!!!!!!!!!
Bernard Frankpitt <frankpit@pop.dn.net> writes: > I have the following lines in my .emacs file > ;;; Set tab-width in c-mode to 4 spaces > (add-hook 'c-mode-hook > (function (lambda () (set tab-width 4)))) > I think that there are some other small differences between emacs c-mode > formatting and the indent formatting that PostgreSQL uses, but the > 8-space tab is the only one that I have fixed. I think I've mentioned this before, but I have the following function for adapting emacs to the Postgres code-formatting conventions: ; Cmd to set tab stops &etc for working with PostgreSQL code (defun pgsql-mode () "Set PostgreSQL C indenting conventions in current buffer." (interactive) (c-mode) ;ensure we're in electric-C mode (setq tab-width 4) (c-set-style "bsd") (c-set-offset 'case-label '+) ) Currently I invoke this command by hand when looking at a Postgres file. I've been meaning to set up a load-time hook to invoke it automatically upon visiting a .c or .h file within my ~postgres directory tree, but haven't got round to that yet. As far as I've noticed, the only significant shortcoming of this mode definition is that it doesn't know that "foreach" should be treated as a block-beginning keyword. This is also fixable with a little elisp hacking, but that hasn't got to the top of the to-do list either. For now I just remember to manually unindent the "{" right below "foreach", and then it carries on correctly for the rest of the block. ObFlameBait: Personally I think we should switch over to standard 8-column tabs, but Bruce is apparently still using some medieval editor in which physical tab widths dictate logical indent levels :-( regards, tom lane
> ObFlameBait: Personally I think we should switch over to standard > 8-column tabs, but Bruce is apparently still using some medieval editor > in which physical tab widths dictate logical indent levels :-( Vadim is also in agreement on this. Not many editors can handle cases where tab size is different from indent size. Emacs obviously can, and Tom has enjoyed pointing out. :-) I am willing to re-open the discussion if we people would prefer something else. -- Bruce Momjian | http://www.op.net/~candle maillist@candle.pha.pa.us | (610) 853-3000+ If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania19026
On Wed, 10 Nov 1999, Bruce Momjian wrote: > > ObFlameBait: Personally I think we should switch over to standard > > 8-column tabs, but Bruce is apparently still using some medieval editor > > in which physical tab widths dictate logical indent levels :-( > > Vadim is also in agreement on this. Not many editors can handle > cases where tab size is different from indent size. Emacs obviously > can, and Tom has enjoyed pointing out. :-) > > I am willing to re-open the discussion if we people would prefer > something else. Trying to redefine a tab to be 4 spaces is asking for trouble. How about making pgindent replace 8 spaces with a tab and 4 spaces with, well, 4 spaces. This is how emacs handles bsd indent style if you don't change the tab sizes. And all other editors should be fine with this. Personally, I'm always in favour of using no tabs at all, because of this very problem, and just because they annoy me. But I tend to be alone with that position. -- Peter Eisentraut Sernanders vaeg 10:115 peter_e@gmx.net 75262 Uppsala http://yi.org/peter-e/ Sweden
> ;;; Set tab-width in c-mode to 4 spaces > (add-hook 'c-mode-hook > (function (lambda () (set tab-width 4)))) Typo: set -> setq (from Tom Lane's code) I'm now a happy emacs camper :) - Thomas -- Thomas Lockhart lockhart@alumni.caltech.edu South Pasadena, California
Peter Eisentraut wrote: > Personally, I'm always in favour of using no tabs at all, because of this > very problem, and just because they annoy me. But I tend to be alone with > that position. No you are not :). Twenty odd years of software development have taught me to remove the tab key from my keyboard. Two spaces do the trick for me and try to avoid at all costs lines over 80 cols. (I use emacs in vi[per] mode), even on win98... Oh how I wish we were back in the days of TECO. -------- Regards Theo
At 09:53 PM 11/11/99 +0200, Theo Kramer wrote: >Peter Eisentraut wrote: >> Personally, I'm always in favour of using no tabs at all, because of this >> very problem, and just because they annoy me. But I tend to be alone with >> that position. > >No you are not :). Twenty odd years of software development have taught me >to remove the tab key from my keyboard. Two spaces do the trick for me and >try to avoid at all costs lines over 80 cols. (I use emacs in vi[per] mode), >even on win98... Oh how I wish we were back in the days of TECO. TECO! If you were to dig up a copy of the original manual for Dec's OS/8 TECO, you'd see a reference to me on the first page. Not by name, but by organization, for having done the first version. Sheesh, those where old days. Anyway, I too avoid tabs. Life's too short to figure out how to make all the tools I use tab the way I want them to. - Don Baccus, Portland OR <dhogaza@pacifier.com> Nature photos, on-line guides, Pacific Northwest Rare Bird Alert Serviceand other goodies at http://donb.photo.net.