Re: [HACKERS] Source code format votes
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Peter Mount <petermount@it.maidstone.gov.uk>
Cc: "'Bruce Momjian'" <pgman@candle.pha.pa.us>, PostgreSQL-development <pgsql-hackers@postgreSQL.org>
Date: 1999-12-24T15:06:36Z
Lists: pgsql-hackers
Peter Mount <petermount@it.maidstone.gov.uk> writes:
> I'd prefer 8-space tabs, mainly because I have to set emacs to 4-space
> every time I enter a source file :-)
Not if you know how to configure Emacs properly ;-)
You need to put two things in your ~/.emacs. First you need a
suitable mode-setting command, for which I use
; Cmd to set tab stops &etc for working with PostgreSQL code
(defun pgsql-c-mode ()
"Set PostgreSQL C indenting conventions in current buffer."
(interactive)
(c-mode) ; make sure major mode is right
(setq tab-width 4) ; adjust to nonstandard tab width
(c-set-style "bsd") ; indent conventions are BSD
(c-set-offset 'case-label '+) ; except we indent case labels
)
Now the above can be invoked by hand, but Peter E. showed me the
following trick for having it called automatically: add entries to your
auto-mode-alist that match both the start and end of the pathname,
so that pgsql-c-mode is automatically called for C files living in a
particular region of your filesystem. Mine looks like
(setq auto-mode-alist
(cons '("\\`/home/postgres/.*\\.[chyl]\\'" . pgsql-c-mode)
(cons '("\\`/home/tgl/pgsql/.*\\.[chyl]\\'" . pgsql-c-mode)
auto-mode-alist)))
This has the effect of setting Pgsql mode automatically for any .c, .h,
.y, or .l file underneath either /home/postgres/ or /home/tgl/pgsql/.
Adjust to taste and never think about tabs again.
BTW, Bruce suggested adding Local-variables settings to all the source
files to push Emacs into making the right settings, but I much prefer
doing it as above. Local-variables is an insecure feature if you ask
me; I keep it disabled.
regards, tom lane