|
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 |
| -;;; Mode for C files to match src/tools/pgindent/pgindent formatting |
16 |
| - |
17 |
| -;;; This set is known to work with old versions of emacs |
18 |
| - |
19 |
| -(setq auto-mode-alist |
20 |
| - (cons '("\\(postgres\\|pgsql\\).*\\.[ch]\\'" . pgsql-c-mode) |
21 |
| - auto-mode-alist)) |
22 |
| -(setq auto-mode-alist |
23 |
| - (cons '("\\(postgres\\|pgsql\\).*\\.cc\\'" . pgsql-c-mode) |
24 |
| - auto-mode-alist)) |
25 |
| - |
26 |
| -(defun pgsql-c-mode () |
27 |
| - ;; sets up formatting for PostgreSQL C code |
28 |
| - (interactive) |
29 |
| - (c-mode) |
30 |
| - (setq-default tab-width 4) |
31 |
| - (c-set-style "bsd") ; set c-basic-offset to 4, plus other stuff |
32 |
| - (c-set-offset 'case-label '+) ; tweak case indent to match PG custom |
33 |
| - (setq fill-column 79) ; matches what pgindent does |
34 |
| - (setq indent-tabs-mode t)) ; make sure we keep tabs when indenting |
35 |
| - |
36 |
| - |
37 |
| -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
38 |
| - |
39 |
| -;;; Similar approach, known to work with xemacs |
40 |
| -;;; Use of a named style makes it easy to use the style elsewhere |
41 |
| - |
42 |
| -(c-add-style "pgsql" |
43 |
| - '("bsd" |
44 |
| - (fill-column . 79) |
45 |
| - (indent-tabs-mode . t) |
46 |
| - (c-basic-offset . 4) |
47 |
| - (tab-width . 4) |
48 |
| - (c-offsets-alist . |
49 |
| - ((case-label . +))) |
50 |
| - ) |
51 |
| - nil ) ; t = set this mode, nil = don't |
52 |
| - |
53 |
| -(defun pgsql-c-mode () |
54 |
| - (c-mode) |
55 |
| - (c-set-style "pgsql") |
56 |
| -) |
57 |
| - |
58 |
| -(setq auto-mode-alist |
59 |
| - (cons '("\\(postgres\\|pgsql\\).*\\.[chyl]\\'" . pgsql-c-mode) |
60 |
| - auto-mode-alist)) |
61 |
| -(setq auto-mode-alist |
62 |
| - (cons '("\\(postgres\\|pgsql\\).*\\.cc\\'" . pgsql-c-mode) |
63 |
| - auto-mode-alist)) |
64 |
| - |
65 |
| -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
66 |
| - |
67 |
| -;;; Slightly different approach - use a hook instead of a mode |
| 1 | +;; -*- mode: emacs-lisp -*- |
| 2 | + |
| 3 | +;; This file contains code to set up Emacs to edit PostgreSQL source |
| 4 | +;; code. Copy these snippets into your .emacs file or equivalent, or |
| 5 | +;; use load-file to load this file directly. |
| 6 | +;; |
| 7 | +;; Note also that there is a .dir-locals.el file at the top of the |
| 8 | +;; PostgreSQL source tree, which contains many of the settings shown |
| 9 | +;; here (but not all, mainly because not all settings are allowed as |
| 10 | +;; local variables). So for light editing, you might not need any |
| 11 | +;; additional Emacs configuration. |
| 12 | + |
| 13 | + |
| 14 | +;;; C files |
| 15 | + |
| 16 | +;; Style that matches the formatting used by |
| 17 | +;; src/tools/pgindent/pgindent. Many extension projects also use this |
| 18 | +;; style. |
| 19 | +(c-add-style "postgresql" |
| 20 | + '("bsd" |
| 21 | + (c-auto-align-backslashes . nil) |
| 22 | + (c-basic-offset . 4) |
| 23 | + (c-offsets-alist . ((case-label . +) |
| 24 | + (label . -) |
| 25 | + (statement-case-open . +))) |
| 26 | + (fill-column . 78) |
| 27 | + (indent-tabs-mode . t) |
| 28 | + (tab-width . 4))) |
68 | 29 |
|
69 | 30 | (add-hook 'c-mode-hook
|
70 |
| - (function |
71 |
| - (lambda nil |
72 |
| - (if (string-match "postgresql" buffer-file-name) |
73 |
| - (progn |
74 |
| - (c-set-style "bsd") |
75 |
| - (setq c-basic-offset 4) |
76 |
| - (setq tab-width 4) |
77 |
| - (c-set-offset 'case-label '+) |
78 |
| - (setq fill-column 79) |
79 |
| - (setq indent-tabs-mode t) |
80 |
| - ) |
81 |
| - )))) |
| 31 | + (defun postgresql-c-mode-hook () |
| 32 | + (when (string-match "/postgres\\(ql\\)?/" buffer-file-name) |
| 33 | + (c-set-style "postgresql")))) |
82 | 34 |
|
83 |
| -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
84 | 35 |
|
85 |
| -;;; Mode for Perl files to match src/tools/pgindent/perltidyrc formatting |
| 36 | +;;; Perl files |
86 | 37 |
|
| 38 | +;; Style that matches the formatting used by |
| 39 | +;; src/tools/pgindent/perltidyrc. |
87 | 40 | (defun pgsql-perl-style ()
|
88 | 41 | "Perl style adjusted for PostgreSQL project"
|
89 | 42 | (interactive)
|
90 |
| - (setq tab-width 4) |
91 |
| - (setq perl-indent-level 4) |
92 |
| - (setq perl-continued-statement-offset 4) |
93 |
| - (setq perl-continued-brace-offset 4) |
94 |
| - (setq perl-brace-offset 0) |
95 | 43 | (setq perl-brace-imaginary-offset 0)
|
96 |
| - (setq perl-label-offset -2)) |
| 44 | + (setq perl-brace-offset 0) |
| 45 | + (setq perl-continued-brace-offset 4) |
| 46 | + (setq perl-continued-statement-offset 4) |
| 47 | + (setq perl-indent-level 4) |
| 48 | + (setq perl-label-offset -2) |
| 49 | + (setq tab-width 4)) |
97 | 50 |
|
98 | 51 | (add-hook 'perl-mode-hook
|
99 |
| - (lambda () |
100 |
| - (if (string-match "postgresql" buffer-file-name) |
101 |
| - (pgsql-perl-style)))) |
| 52 | + (defun postgresql-perl-mode-hook () |
| 53 | + (when (string-match "/postgres\\(ql\\)?/" buffer-file-name) |
| 54 | + (pgsql-perl-style)))) |
102 | 55 |
|
103 |
| -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
104 | 56 |
|
105 |
| -;;; To work on the documentation, the following (or a variant, as above) |
106 |
| -;;; can be helpful. |
| 57 | +;;; documentation files |
107 | 58 |
|
108 |
| -(defun pgsql-sgml-mode () |
109 |
| - "SGML mode adjusted for PostgreSQL project" |
110 |
| - (interactive) |
111 |
| - (sgml-mode) |
| 59 | +(add-hook 'sgml-mode-hook |
| 60 | + (defun postgresql-sgml-mode-hook () |
| 61 | + (when (string-match "/postgres\\(ql\\)?/" buffer-file-name) |
| 62 | + (setq fill-column 78) |
| 63 | + (setq indent-tabs-mode nil) |
| 64 | + (setq sgml-basic-offset 1)))) |
112 | 65 |
|
113 |
| - (setq indent-tabs-mode nil) |
114 |
| - (setq sgml-basic-offset 1) |
115 |
| -) |
116 | 66 |
|
117 |
| -(setq auto-mode-alist |
118 |
| - (cons '("\\(postgres\\|pgsql\\).*\\.sgml\\'" . pgsql-sgml-mode) |
119 |
| - auto-mode-alist)) |
| 67 | +;;; Makefiles |
120 | 68 |
|
121 |
| -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 69 | +;; use GNU make mode instead of plain make mode |
| 70 | +(add-to-list 'auto-mode-alist '("/postgres\\(ql\\)?/.*Makefile.*" . makefile-gmake-mode)) |
| 71 | +(add-to-list 'auto-mode-alist '("/postgres\\(ql\\)?/.*\\.mk\\'" . makefile-gmake-mode)) |
0 commit comments