Update Emacs/vim editor info.
authorBruce Momjian
Thu, 7 Sep 2006 00:10:46 +0000 (00:10 +0000)
committerBruce Momjian
Thu, 7 Sep 2006 00:10:46 +0000 (00:10 +0000)
doc/src/FAQ/FAQ_DEV.html
doc/src/sgml/sources.sgml
src/tools/editors/emacs.samples [new file with mode: 0644]
src/tools/editors/vim.samples [new file with mode: 0644]

index 5a99a0badc43763ae86b511b119e36b0b7ae6e28..d68bf48041fbf2f3b7dfe8c626a7e568c629b6a6 100644 (file)
     less:
             less -x4
 
-   

The tools directory of the latest sources contains sample 

+   

The tools/editors directory of the latest sources contains sample 

    settings that can be used with the emacs, xemacs and vim 
    editors, that assist in keeping to PostgreSQL coding standards.
    

index 8187f05546cc791a2fde1e1cb5bd5af84a9e3e36..58d5d5635ce734c2ee1b002ac86f4c15a1503278 100644 (file)
@@ -1,4 +1,4 @@
-
+
 
  
   PostgreSQL Coding Conventions
    
 
    
-    For Emacs, add the following (or
-    something similar) to your ~/.emacs 
-    initialization file:
-
-
-;; 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
-
-   
-
-   
-    For vi, your
-    ~/.vimrc or equivalent file should contain
-    the following:
-
-
-set tabstop=4
-
-
-    or equivalently from within vi, try
-
-
-:set ts=4
-
+    The src/tools directory contains sample settings 
+   files that can be used with the emacs
+   xemacs or vim 
+   editors to help ensure that they format code according to these 
+   conventions.
    
 
    
diff --git a/src/tools/editors/emacs.samples b/src/tools/editors/emacs.samples
new file mode 100644 (file)
index 0000000..a4d00be
--- /dev/null
@@ -0,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)
+          )
+          ))))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/src/tools/editors/vim.samples b/src/tools/editors/vim.samples
new file mode 100644 (file)
index 0000000..210d9a3
--- /dev/null
@@ -0,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
+
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""