From: Tom Yu Date: Wed, 28 Oct 2009 17:18:04 +0000 (+0000) Subject: Update to use heuristics for setting "krb5" style based on file local X-Git-Tag: krb5-1.8-alpha1~255 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ca0304526a518b2419eee3c0aad569b50d9009ef;p=krb5.git 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 --- diff --git a/src/util/krb5-batch-reindent.el b/src/util/krb5-batch-reindent.el index ec33555ae..2a4c7682b 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 e366b8410..2aa7dfce6 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)