(untabify (point-min) (point-max)))
;; Only reindent if the file C style is guessed to be "krb5".
- (if (and (eq c-basic-offset 4)
- (eq indent-tabs-mode nil))
- (progn
- (c-set-style "krb5")
- (c-indent-region (point-min) (point-max))))
+ ;; Note that krb5-c-style.el already has a heuristic for setting
+ ;; the C style if the file has "c-basic-offset: 4;
+ ;; indent-tabs-mode: nil".
+ (if (equal c-indentation-style "krb5")
+ (c-indent-region (point-min) (point-max)))
(whitespace-cleanup)
(c-special-indent-hook . nil)
(fill-column . 79)))
-(defun krb5-c-hook ()
- (c-add-style "krb5" krb5-c-style))
+;; Use eval-after-load rather than c-initialization-hook; this ensures
+;; that the style gets defined even if a user loads this file after
+;; initializing cc-mode.
+(eval-after-load 'cc-mode (c-add-style "krb5" krb5-c-style))
-(add-hook 'c-initialization-hook 'krb5-c-hook)
+;; We don't use a c-file-style file-local variable setting in our
+;; source code, to avoid errors for emacs users who don't define the
+;; "krb5" style. Instead, use this heuristic.
+;;
+;; TODO: modify to also look for unique files in the source tree.
+(defun krb5-c-mode-hook ()
+ (if (and (eq major-mode 'c-mode)
+ (eq c-basic-offset 4)
+ (eq indent-tabs-mode nil))
+ (c-set-style "krb5")))
+
+;; (add-hook 'c-mode-common-hook 'krb5-c-mode-hook)
+
+;; Use hack-local-variables-hook because the c-mode hooks run before
+;; hack-local-variables runs.
+(add-hook 'hack-local-variables-hook 'krb5-c-mode-hook)