Tom Lane wrote:
> Andrew Dunstan <andrew@dunslane.net> writes:
>
>> Looking at this further, I am wondering if it would not be better to put
>> sample .emacs and .vimrc files in the source (in, say, src.tools).
>>
>
> Seems reasonable. I was about to say "what if they're just looking at
> the docs and don't have a source tree?" ... but anyone editing the code
> has got a copy of the source tree ...
>
>
here is the proposed patch.
cheers
andrew
Index: doc/src/FAQ/FAQ_DEV.html
===================================================================
RCS file: /cvsroot/pgsql/doc/src/FAQ/FAQ_DEV.html,v
retrieving revision 1.114
diff -c -c -r1.114 FAQ_DEV.html
*** doc/src/FAQ/FAQ_DEV.html 12 Aug 2006 03:48:32 -0000 1.114
--- doc/src/FAQ/FAQ_DEV.html 6 Sep 2006 18:34:16 -0000
***************
*** 357,365 ****
can be applied to the distribution. This produces context diffs,
which is our preferred format.</P>
! <P>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:<BR>
</P>
<PRE>
vi in ~/.exrc:
--- 357,365 ----
can be applied to the distribution. This produces context diffs,
which is our preferred format.</P>
! <P>Our standard format <I>BSD</I> style, with each level of code indented
! one tab, where each tab is four spaces. You will need to set your editor
! or file viewer to display tabs as four spaces:<BR>
</P>
<PRE>
vi in ~/.exrc:
***************
*** 369,408 ****
more -x4
less:
less -x4
- emacs:
- M-x set-variable tab-width
-
- or
-
- (c-add-style "pgsql"
- '("bsd"
- (indent-tabs-mode . t)
- (c-basic-offset . 4)
- (tab-width . 4)
- (c-offsets-alist .
- ((case-label . +)))
- )
- nil ) ; t = set this style, nil = don't
-
- (defun pgsql-c-mode ()
- (c-mode)
- (c-set-style "pgsql")
- )
-
- and add this to your autoload list (modify file path in macro):
-
- (setq auto-mode-alist
- (cons '("\\`/home/andrew/pgsql/.*\\.[chyl]\\'" . pgsql-c-mode)
- auto-mode-alist))
- or
- /*
- * Local variables:
- * tab-width: 4
- * c-indent-level: 4
- * c-basic-offset: 4
- * End:
- */
</PRE>
<BR>
<I>pgindent</I> will the format code by specifying flags to your
operating system's utility <I>indent.</I> This <A href=
--- 369,379 ----
more -x4
less:
less -x4
</PRE>
+ <P>The <I>tools</I> directory of the latest sources contains sample
+ settings that can be used with the <I>emacs, xemacs</I> and <I>vim</I>
+ editors, that assist in keeping to PostgreSQL coding standards.
+ </P>
<BR>
<I>pgindent</I> will the format code by specifying flags to your
operating system's utility <I>indent.</I> This <A href=
Index: doc/src/sgml/sources.sgml
===================================================================
RCS file: /cvsroot/pgsql/doc/src/sgml/sources.sgml,v
retrieving revision 2.17
diff -c -c -r2.17 sources.sgml
*** doc/src/sgml/sources.sgml 10 Mar 2006 19:10:49 -0000 2.17
--- doc/src/sgml/sources.sgml 6 Sep 2006 18:34:16 -0000
***************
*** 21,64 ****
</para>
<para>
! For <productname>Emacs</productname>, add the following (or
! something similar) to your <filename>~/.emacs</filename>
! initialization file:
!
! <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
! </programlisting>
! </para>
!
! <para>
! For <application>vi</application>, your
! <filename>~/.vimrc</filename> or equivalent file should contain
! the following:
!
! <programlisting>
! set tabstop=4
! </programlisting>
!
! or equivalently from within <application>vi</application>, try
!
! <programlisting>
! :set ts=4
! </programlisting>
</para>
<para>
--- 21,31 ----
</para>
<para>
! The <filename>src/tools</filename> directory contains sample settings
! files that can be used with the <productname>emacs</productname>,
! <productname>xemacs</productname> or <productname>vim</productname>
! editors to help ensure that they format code according to these
! conventions.
</para>
<para>
*** /dev/null 2006-09-01 11:10:52.339368250 -0400
--- src/tools/emacs.samples 2006-09-06 13:47:11.000000000 -0400
***************
*** 0 ****
--- 1,78 ----
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+ ;;;
+ ;;; This file contains several examples of how to set up emacs and/or xemacs
+ ;;; to edit PostgreSQL code.
+ ;;;
+ ;;; Whichever set you choose would go in your .emacs file or equivalent.
+ ;;;
+ ;;; You only need one of these.
+ ;;;
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+ ;;; This set is known to work with old versions of emacs
+
+ (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
+
+
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+ ;;; Similar approach, known to work with xemacs
+ ;;; Use of a named style makes it easy to use the style elsewhere
+
+ (c-add-style "pgsql"
+ '("bsd"
+ (indent-tabs-mode . t)
+ (c-basic-offset . 4)
+ (tab-width . 4)
+ (c-offsets-alist .
+ ((case-label . +)))
+ )
+ nil ) ; t = set this mode, nil = don't
+
+ (defun pgsql-c-mode ()
+ (c-mode)
+ (c-set-style "pgsql")
+ )
+
+ (setq auto-mode-alist
+ (cons '("\\(postgres\\|pgsql\\).*\\.[chyl]\\'" . pgsql-c-mode)
+ auto-mode-alist))
+ (setq auto-mode-alist
+ (cons '("\\(postgres\\|pgsql\\).*\\.cc\\'" . pgsql-c-mode)
+ auto-mode-alist))
+
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+ ;;; Slightly different approach - use a hook instead of a mode
+
+ (add-hook 'c-mode-hook
+ (function
+ (lambda nil
+ (if (string-match "pgsql" buffer-file-name)
+ (progn
+ (c-set-style "bsd")
+ (setq c-basic-offset 4)
+ (setq tab-width 4)
+ (c-set-offset 'case-label '+)
+ (setq indent-tabs-mode t)
+ )
+ ))))
+
+ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
*** /dev/null 2006-09-01 11:10:52.339368250 -0400
--- src/tools/vim.samples 2006-09-06 13:51:09.000000000 -0400
***************
*** 0 ****
--- 1,18 ----
+
+ """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+ "
+ " These settings are appropriate for editing PostgreSQL code with vim
+ "
+ " You would copy this into your .vimrc or equivalent
+ "
+ """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+ :if match(getcwd(), "/pgsql") >=0 || match(getcwd(), "/postgresql") >= 0
+
+ : set cinoptions=(0
+ : set tabstop=4
+ : set shiftwidth=4
+
+ :endif
+
+ """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""