xref: /freebsd/crypto/krb5/src/util/krb5-c-style.el (revision 24e4dcf4ba5e9dedcf89efd358ea3e1fe5867020)
1;;; -*- mode: emacs-lisp; indent-tabs-mode: nil -*-
2(defconst krb5-c-style
3  '("bsd"
4    (c-basic-offset     . 4)
5    (c-cleanup-list     . (brace-elseif-brace
6                           brace-else-brace
7                           defun-close-semi))
8    (c-comment-continuation-stars       . "* ")
9    (c-comment-only-line-offset . 0)
10    (c-electric-pound-behavior  . (alignleft))
11    (c-hanging-braces-alist     . ((block-close . c-snug-do-while)
12                                   (brace-list-open)
13                                   (class-open after)
14                                   (extern-lang-open after)
15                                   (substatement-open after)))
16    (c-hanging-colons-alist     . ((case-label after)
17                                   (label after)))
18    (c-hanging-comment-starter-p        . nil)
19    (c-hanging-comment-ender-p          . nil)
20    (c-indent-comments-syntactically-p  . t)
21    (c-label-minimum-indentation        . 0)
22    (c-offsets-alist    . ((inextern-lang . 0)
23                           (arglist-close . 0)))
24    (c-special-indent-hook      . nil)
25    (fill-column                . 79)))
26
27;; Use eval-after-load rather than c-initialization-hook; this ensures
28;; that the style gets defined even if a user loads this file after
29;; initializing cc-mode.
30(eval-after-load 'cc-mode (c-add-style "krb5" krb5-c-style))
31
32;; We don't use a c-file-style file-local variable setting in our
33;; source code, to avoid errors for emacs users who don't define the
34;; "krb5" style.  Instead, use this heuristic.
35;;
36;; TODO: modify to also look for unique files in the source tree.
37(defun krb5-c-mode-hook ()
38  (if (and (eq major-mode 'c-mode)
39           (eq c-basic-offset 4)
40           (eq indent-tabs-mode nil))
41      (c-set-style "krb5")))
42
43;; (add-hook 'c-mode-common-hook 'krb5-c-mode-hook)
44
45;; Use hack-local-variables-hook because the c-mode hooks run before
46;; hack-local-variables runs.
47(add-hook 'hack-local-variables-hook 'krb5-c-mode-hook)
48
49;; emacs-23.x has a buggy cc-mode that incorrectly deals with case
50;; labels with character constants.
51(if (and (string-match "^23\\." emacs-version)
52         (require 'cc-defs)
53         (string-match "5\\.31\\.[0-7]" c-version))
54    (let ((load-path (cons (file-name-directory load-file-name) load-path)))
55      (load "krb5-hack-cc-mode-caselabel")))
56