<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <HTML ><HEAD ><TITLE >PostgreSQL Coding Conventions</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK REV="MADE" HREF="mailto:pgsql-docs@postgresql.org"><LINK REL="HOME" TITLE="PostgreSQL 7.4.1 Documentation" HREF="index.html"><LINK REL="UP" TITLE="Internals" HREF="internals.html"><LINK REL="PREVIOUS" TITLE="Summary of Changes since Protocol 2.0" HREF="protocol-changes.html"><LINK REL="NEXT" TITLE="Reporting Errors Within the Server" HREF="error-message-reporting.html"><LINK REL="STYLESHEET" TYPE="text/css" HREF="stylesheet.css"><META NAME="creation" CONTENT="2003-12-22T03:48:47"></HEAD ><BODY CLASS="CHAPTER" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="5" ALIGN="center" VALIGN="bottom" >PostgreSQL 7.4.1 Documentation</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A HREF="protocol-changes.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="10%" ALIGN="left" VALIGN="top" ><A HREF="protocol.html" >Fast Backward</A ></TD ><TD WIDTH="60%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="top" ><A HREF="nls.html" >Fast Forward</A ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="top" ><A HREF="error-message-reporting.html" ACCESSKEY="N" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><DIV CLASS="CHAPTER" ><H1 ><A NAME="SOURCE" ></A >Chapter 45. PostgreSQL Coding Conventions</H1 ><DIV CLASS="TOC" ><DL ><DT ><B >Table of Contents</B ></DT ><DT >45.1. <A HREF="source.html#SOURCE-FORMAT" >Formatting</A ></DT ><DT >45.2. <A HREF="error-message-reporting.html" >Reporting Errors Within the Server</A ></DT ><DT >45.3. <A HREF="error-style-guide.html" >Error Message Style Guide</A ></DT ><DD ><DL ><DT >45.3.1. <A HREF="error-style-guide.html#AEN54020" >What goes where</A ></DT ><DT >45.3.2. <A HREF="error-style-guide.html#AEN54029" >Formatting</A ></DT ><DT >45.3.3. <A HREF="error-style-guide.html#AEN54033" >Quotation marks</A ></DT ><DT >45.3.4. <A HREF="error-style-guide.html#AEN54037" >Use of quotes</A ></DT ><DT >45.3.5. <A HREF="error-style-guide.html#AEN54043" >Grammar and punctuation</A ></DT ><DT >45.3.6. <A HREF="error-style-guide.html#AEN54049" >Upper case vs. lower case</A ></DT ><DT >45.3.7. <A HREF="error-style-guide.html#AEN54053" >Avoid passive voice</A ></DT ><DT >45.3.8. <A HREF="error-style-guide.html#AEN54059" >Present vs past tense</A ></DT ><DT >45.3.9. <A HREF="error-style-guide.html#AEN54069" >Type of the object</A ></DT ><DT >45.3.10. <A HREF="error-style-guide.html#AEN54074" >Brackets</A ></DT ><DT >45.3.11. <A HREF="error-style-guide.html#AEN54078" >Assembling error messages</A ></DT ><DT >45.3.12. <A HREF="error-style-guide.html#AEN54083" >Reasons for errors</A ></DT ><DT >45.3.13. <A HREF="error-style-guide.html#AEN54087" >Function names</A ></DT ><DT >45.3.14. <A HREF="error-style-guide.html#AEN54094" >Tricky words to avoid</A ></DT ><DT >45.3.15. <A HREF="error-style-guide.html#AEN54126" >Proper spelling</A ></DT ><DT >45.3.16. <A HREF="error-style-guide.html#AEN54141" >Localization</A ></DT ></DL ></DD ></DL ></DIV ><DIV CLASS="SECT1" ><H1 CLASS="SECT1" ><A NAME="SOURCE-FORMAT" >45.1. Formatting</A ></H1 ><P > Source code formatting uses 4 column tab spacing, with tabs preserved (i.e. tabs are not expanded to spaces). Each logical indentation level is one additional tab stop. Layout rules (brace positioning, etc) follow BSD conventions. </P ><P > While submitted patches do not absolutely have to follow these formatting rules, it's a good idea to do so. Your code will get run through <SPAN CLASS="APPLICATION" >pgindent</SPAN >, so there's no point in making it look nice under some other set of formatting conventions. </P ><P > For Emacs, add the following (or something similar) to your <TT CLASS="FILENAME" >~/.emacs</TT > initialization file: </P><PRE CLASS="PROGRAMLISTING" >;; check for files with a path containing "postgres" or "pgsql" (setq auto-mode-alist (cons '("\\(postgres\\|pgsql\\).*\\.[ch]\\'" . pgsql-c-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\\(postgres\\|pgsql\\).*\\.cc\\'" . pgsql-c-mode) auto-mode-alist)) (defun pgsql-c-mode () ;; sets up formatting for PostgreSQL C code (interactive) (c-mode) (setq-default tab-width 4) (c-set-style "bsd") ; set c-basic-offset to 4, plus other stuff (c-set-offset 'case-label '+) ; tweak case indent to match PG custom (setq indent-tabs-mode t)) ; make sure we keep tabs when indenting</PRE ><P> </P ><P > For <SPAN CLASS="APPLICATION" >vi</SPAN >, your <TT CLASS="FILENAME" >~/.vimrc</TT > or equivalent file should contain the following: </P><PRE CLASS="PROGRAMLISTING" >set tabstop=4</PRE ><P> or equivalently from within vi, try </P><PRE CLASS="PROGRAMLISTING" >:set ts=4</PRE ><P> </P ><P > The text browsing tools <SPAN CLASS="APPLICATION" >more</SPAN > and <SPAN CLASS="APPLICATION" >less</SPAN > can be invoked as </P><PRE CLASS="PROGRAMLISTING" >more -x4 less -x4</PRE ><P> to make them show tabs appropriately. </P ></DIV ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="protocol-changes.html" ACCESSKEY="P" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="error-message-reporting.html" ACCESSKEY="N" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >Summary of Changes since Protocol 2.0</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="internals.html" ACCESSKEY="U" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >Reporting Errors Within the Server</TD ></TR ></TABLE ></DIV ></BODY ></HTML >