]> granicus.if.org Git - postgresql/blob - src/tools/editors/emacs.samples
Add some instructions on how to customize emacs for working on the SGML
[postgresql] / src / tools / editors / emacs.samples
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;;;
3 ;;; This file contains several examples of how to set up emacs and/or xemacs
4 ;;; to edit PostgreSQL code.
5 ;;;
6 ;;; Whichever set you choose would go in your .emacs file or equivalent.
7 ;;;
8 ;;; You only need one of these.
9 ;;;
10 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
11
12
13 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14
15 ;;; This set is known to work with old versions of emacs
16
17 (setq auto-mode-alist
18   (cons '("\\(postgres\\|pgsql\\).*\\.[ch]\\'" . pgsql-c-mode)
19         auto-mode-alist))
20 (setq auto-mode-alist
21   (cons '("\\(postgres\\|pgsql\\).*\\.cc\\'" . pgsql-c-mode)
22         auto-mode-alist))
23
24 (defun pgsql-c-mode ()
25   ;; sets up formatting for PostgreSQL C code
26   (interactive)
27   (c-mode)
28   (setq-default tab-width 4)
29   (c-set-style "bsd")             ; set c-basic-offset to 4, plus other stuff
30   (c-set-offset 'case-label '+)   ; tweak case indent to match PG custom
31   (setq indent-tabs-mode t))      ; make sure we keep tabs when indenting
32
33
34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
35
36 ;;; Similar approach, known to work with xemacs
37 ;;; Use of a named style makes it easy to use the style elsewhere
38
39 (c-add-style "pgsql"
40                       '("bsd"
41                                  (indent-tabs-mode . t)
42                                  (c-basic-offset   . 4)
43                                  (tab-width . 4)
44                                  (c-offsets-alist .
45                                             ((case-label . +)))
46                       )
47                       nil ) ; t = set this mode, nil = don't
48
49 (defun pgsql-c-mode ()
50   (c-mode)
51   (c-set-style "pgsql")
52 )
53
54 (setq auto-mode-alist
55   (cons '("\\(postgres\\|pgsql\\).*\\.[chyl]\\'" . pgsql-c-mode)
56         auto-mode-alist))
57 (setq auto-mode-alist
58   (cons '("\\(postgres\\|pgsql\\).*\\.cc\\'" . pgsql-c-mode)
59         auto-mode-alist))
60
61 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
62
63 ;;; Slightly different approach - use a hook instead of a mode
64
65 (add-hook 'c-mode-hook
66           (function
67            (lambda nil 
68              (if (string-match "pgsql" buffer-file-name)
69                  (progn
70                    (c-set-style "bsd")
71                    (setq c-basic-offset 4) 
72                    (setq tab-width 4)
73                    (c-set-offset 'case-label '+)
74                    (setq indent-tabs-mode t)
75                    )
76                ))))
77
78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
79
80 ;;; To work on the documentation, the following (or a variant, as above)
81 ;;; can be helpful.
82
83 (defun pgsql-sgml-mode ()
84   "SGML mode adjusted for PostgreSQL project"
85   (interactive)
86   (sgml-mode)
87
88   (setq sgml-basic-offset 1)
89 )
90
91 (setq auto-mode-alist
92   (cons '("\\(postgres\\|pgsql\\).*\\.sgml\\'" . pgsql-c-mode)
93         auto-mode-alist))
94
95 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;