aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorTom Yu <tlyu@mit.edu>2009-10-28 17:18:04 +0000
committerTom Yu <tlyu@mit.edu>2009-10-28 17:18:04 +0000
commitca0304526a518b2419eee3c0aad569b50d9009ef (patch)
tree88243113d0d595596676a97637f999110af02a7c /src/util
parentd0cd0d58a684ca3f10800aef11a80f5c8d625796 (diff)
downloadkrb5-ca0304526a518b2419eee3c0aad569b50d9009ef.zip
krb5-ca0304526a518b2419eee3c0aad569b50d9009ef.tar.gz
krb5-ca0304526a518b2419eee3c0aad569b50d9009ef.tar.bz2
Update to use heuristics for setting "krb5" style based on file local
variable settings. Improve friendliness of variant loading orders. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23078 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/util')
-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)