aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/util/krb5-batch-reindent.el10
-rw-r--r--src/util/krb5-c-style.el23
2 files changed, 25 insertions, 8 deletions
diff --git a/src/util/krb5-batch-reindent.el b/src/util/krb5-batch-reindent.el
index ec33555..2a4c768 100644
--- a/src/util/krb5-batch-reindent.el
+++ b/src/util/krb5-batch-reindent.el
@@ -20,11 +20,11 @@
(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)
diff --git a/src/util/krb5-c-style.el b/src/util/krb5-c-style.el
index e366b84..2aa7dfc 100644
--- a/src/util/krb5-c-style.el
+++ b/src/util/krb5-c-style.el
@@ -24,7 +24,24 @@
(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)