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)))
29
30(add-hook 'c-mode-hook
31          (defun postgresql-c-mode-hook ()
32            (when (string-match "/postgres\\(ql\\)?/" buffer-file-name)
33              (c-set-style "postgresql")
34              ;; Don't override the style we just set with the style in
35              ;; `dir-locals-file'.  Emacs 23.4.1 needs this; it is obsolete,
36              ;; albeit harmless, by Emacs 24.3.1.
37              (set (make-local-variable 'ignored-local-variables)
38                   (append '(c-file-style) ignored-local-variables)))))
39
40
41;;; Perl files
42
43;; Style that matches the formatting used by
44;; src/tools/pgindent/perltidyrc.
45(defun pgsql-perl-style ()
46  "Perl style adjusted for PostgreSQL project"
47  (interactive)
48  (setq perl-brace-imaginary-offset 0)
49  (setq perl-brace-offset 0)
50  (setq perl-continued-brace-offset 4)
51  (setq perl-continued-statement-offset 4)
52  (setq perl-indent-level 4)
53  (setq perl-label-offset -2)
54  (setq indent-tabs-mode t)
55  (setq tab-width 4))
56
57(add-hook 'perl-mode-hook
58          (defun postgresql-perl-mode-hook ()
59             (when (string-match "/postgres\\(ql\\)?/" buffer-file-name)
60               (pgsql-perl-style))))
61
62
63;;; documentation files
64
65(add-hook 'sgml-mode-hook
66          (defun postgresql-sgml-mode-hook ()
67             (when (string-match "/postgres\\(ql\\)?/" buffer-file-name)
68               (setq fill-column 78)
69               (setq indent-tabs-mode nil)
70               (setq sgml-basic-offset 1))))
71
72
73;;; Makefiles
74
75;; use GNU make mode instead of plain make mode
76(add-to-list 'auto-mode-alist '("/postgres\\(ql\\)?/.*Makefile.*" . makefile-gmake-mode))
77(add-to-list 'auto-mode-alist '("/postgres\\(ql\\)?/.*\\.mk\\'" . makefile-gmake-mode))
78