summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Yu <tlyu@mit.edu>2009-11-03 03:14:41 +0000
committerTom Yu <tlyu@mit.edu>2009-11-03 03:14:41 +0000
commit6412be9b2a5a21470ef9a94cf78870d525be3115 (patch)
tree4f00bcebda02af886d820dbcf2819f970722da7e
parent3f9a584e767baf09ac0bc91359235bea6f9520fe (diff)
downloadkrb5-6412be9b2a5a21470ef9a94cf78870d525be3115.tar.gz
krb5-6412be9b2a5a21470ef9a94cf78870d525be3115.tar.xz
krb5-6412be9b2a5a21470ef9a94cf78870d525be3115.zip
Monkey patch for the cc-mode that comes with emacs-23.x; that version
of cc-mode has a bug that causes incorrect indentation of case labels containing character constants. Already fixed upstream in unreleased cc-mode sources. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23122 dc483132-0cff-0310-8789-dd5450dbe970
-rw-r--r--src/util/krb5-c-style.el8
-rw-r--r--src/util/krb5-hack-cc-mode-caselabel.el44
2 files changed, 52 insertions, 0 deletions
diff --git a/src/util/krb5-c-style.el b/src/util/krb5-c-style.el
index 2aa7dfce6..b060e8803 100644
--- a/src/util/krb5-c-style.el
+++ b/src/util/krb5-c-style.el
@@ -45,3 +45,11 @@
;; 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)
+
+;; emacs-23.x has a buggy cc-mode that incorrectly deals with case
+;; labels with character constants.
+(if (and (string-match "^23\." emacs-version)
+ (require 'cc-defs)
+ (string-match "5.31.[0-7]" c-version))
+ (let ((load-path (cons (file-name-directory load-file-name) load-path)))
+ (load "krb5-hack-cc-mode-caselabel")))
diff --git a/src/util/krb5-hack-cc-mode-caselabel.el b/src/util/krb5-hack-cc-mode-caselabel.el
new file mode 100644
index 000000000..4857c5351
--- /dev/null
+++ b/src/util/krb5-hack-cc-mode-caselabel.el
@@ -0,0 +1,44 @@
+;;; -*- mode: emacs-lisp; indent-tabs-mode: nil -*-
+
+;; emacs-23.x has a bug in cc-mode that that incorrectly deals with
+;; case labels with character constants.
+
+(require 'cl)
+(require 'cc-defs)
+(require 'cc-vars)
+(require 'cc-langs)
+
+;; Hack load-in-progress to silence the c-lang-defconst error. For
+;; some reason, load-in-progress is nil at some times when it
+;; shouldn't be, at least on released emacs-23.1.1.
+(let ((load-in-progress t))
+
+ ;; Updated c-nonlabel-token-key based on cc-langs.el 5.267.2.22, to
+ ;; allow character constants in case labels.
+ (c-lang-defconst c-nonlabel-token-key
+ "Regexp matching things that can't occur in generic colon labels,
+neither in a statement nor in a declaration context. The regexp is
+tested at the beginning of every sexp in a suspected label,
+i.e. before \":\". Only used if `c-recognize-colon-labels' is set."
+ t (concat
+ ;; Don't allow string literals.
+ "\"\\|"
+ ;; All keywords except `c-label-kwds' and `c-protection-kwds'.
+ (c-make-keywords-re t
+ (set-difference (c-lang-const c-keywords)
+ (append (c-lang-const c-label-kwds)
+ (c-lang-const c-protection-kwds))
+ :test 'string-equal)))
+ ;; Also check for open parens in C++, to catch member init lists in
+ ;; constructors. We normally allow it so that macros with arguments
+ ;; work in labels.
+ c++ (concat "\\s\(\\|" (c-lang-const c-nonlabel-token-key)))
+ (c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key))
+
+ ;; Monkey-patch by way of c-mode-common-hook, as the byte-compiled
+ ;; version of c-init-language-vars will have the old value. This
+ ;; avoids finding some way to re-evaluate the defun for
+ ;; c-init-language-vars.
+ (defun krb5-c-monkey-patch-caselabel ()
+ (setq c-nonlabel-token-key (c-lang-const c-nonlabel-token-key)))
+ (add-hook 'c-mode-common-hook 'krb5-c-monkey-patch-caselabel))