Skip to content

Commit 5e3e8e4

Browse files
committed
Update Emacs configuration
Update emacs.samples with new configuration snippets that match pgindent et al. formatting more accurately and follow Emacs Lisp best practices better. Add .dir-locals.el with a subset of that configuration for casual editing and viewing. Reviewed-by: Dimitri Fontaine <[email protected]> Reviewed-by: Noah Misch <[email protected]>
1 parent 3d5282c commit 5e3e8e4

File tree

2 files changed

+72
-104
lines changed

2 files changed

+72
-104
lines changed

.dir-locals.el

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
;; see also src/tools/editors/emacs.samples for more complete settings
2+
3+
((c-mode . ((c-basic-offset . 4)
4+
(c-file-style . "bsd")
5+
(fill-column . 78)
6+
(indent-tabs-mode . t)
7+
(tab-width . 4)))
8+
(dsssl-mode . ((indent-tabs-mode . nil)))
9+
(nxml-mode . ((indent-tabs-mode . nil)))
10+
(perl-mode . ((perl-indent-level . 4)
11+
(perl-continued-statement-offset . 4)
12+
(perl-continued-brace-offset . 4)
13+
(perl-brace-offset . 0)
14+
(perl-brace-imaginary-offset . 0)
15+
(perl-label-offset . -2)
16+
(tab-width . 4)))
17+
(sgml-mode . ((fill-column . 78)
18+
(indent-tabs-mode . nil))))

src/tools/editors/emacs.samples

+54-104
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,71 @@
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)))
6829

6930
(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"))))
8234

83-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8435

85-
;;; Mode for Perl files to match src/tools/pgindent/perltidyrc formatting
36+
;;; Perl files
8637

38+
;; Style that matches the formatting used by
39+
;; src/tools/pgindent/perltidyrc.
8740
(defun pgsql-perl-style ()
8841
"Perl style adjusted for PostgreSQL project"
8942
(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)
9543
(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))
9750

9851
(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))))
10255

103-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
10456

105-
;;; To work on the documentation, the following (or a variant, as above)
106-
;;; can be helpful.
57+
;;; documentation files
10758

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))))
11265

113-
(setq indent-tabs-mode nil)
114-
(setq sgml-basic-offset 1)
115-
)
11666

117-
(setq auto-mode-alist
118-
(cons '("\\(postgres\\|pgsql\\).*\\.sgml\\'" . pgsql-sgml-mode)
119-
auto-mode-alist))
67+
;;; Makefiles
12068

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

Comments
 (0)