| 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-statement-offset 2) |
| 51 |
(setq perl-continued-brace-offset (- perl-continued-statement-offset)) |
| 52 |
(setq perl-indent-level 4) |
| 53 |
(setq perl-label-offset -2) |
| 54 |
;; Next two aren't marked safe-local-variable, so .dir-locals.el omits them. |
| 55 |
(setq perl-indent-continued-arguments 4) |
| 56 |
(setq perl-indent-parens-as-block t) |
| 57 |
(setq indent-tabs-mode t) |
| 58 |
(setq tab-width 4)) |
| 59 |
|
| 60 |
(add-hook 'perl-mode-hook |
| 61 |
(defun postgresql-perl-mode-hook () |
| 62 |
(when (string-match "/postgres\\(ql\\)?/" buffer-file-name) |
| 63 |
(pgsql-perl-style)))) |
| 64 |
|
| 65 |
|
| 66 |
;;; documentation files |
| 67 |
|
| 68 |
;; *.sgml files are actually XML |
| 69 |
(add-to-list 'auto-mode-alist '("/postgres\\(ql\\)?/.*\\.sgml\\'" . nxml-mode)) |
| 70 |
|
| 71 |
(add-hook 'nxml-mode-hook |
| 72 |
(defun postgresql-xml-mode-hook () |
| 73 |
(when (string-match "/postgres\\(ql\\)?/" buffer-file-name) |
| 74 |
(setq fill-column 78) |
| 75 |
(setq indent-tabs-mode nil)))) |
| 76 |
|
| 77 |
;; The *.xsl files use 2-space indent, which is consistent with |
| 78 |
;; docbook-xsl sources and also the nxml-mode default. But the *.sgml |
| 79 |
;; files use 1-space indent, mostly for historical reasons at this |
| 80 |
;; point. |
| 81 |
(add-hook 'nxml-mode-hook |
| 82 |
(defun postgresql-xml-src-mode-hook () |
| 83 |
(when (string-match "/postgres\\(ql\\)?/.*\\.sgml\\'" buffer-file-name) |
| 84 |
(setq nxml-child-indent 1)))) |
| 85 |
|
| 86 |
|
| 87 |
;;; Makefiles |
| 88 |
|
| 89 |
;; use GNU make mode instead of plain make mode |
| 90 |
(add-to-list 'auto-mode-alist '("/postgres\\(ql\\)?/.*Makefile.*" . makefile-gmake-mode)) |
| 91 |
(add-to-list 'auto-mode-alist '("/postgres\\(ql\\)?/.*\\.mk\\'" . makefile-gmake-mode)) |