Path: blob/main/crypto/krb5/src/util/krb5-hack-cc-mode-caselabel.el
34914 views
;;; -*- mode: emacs-lisp; indent-tabs-mode: nil -*-12;; emacs-23.x has a bug in cc-mode that that incorrectly deals with3;; case labels with character constants.45(require 'cl)6(require 'cc-defs)7(require 'cc-vars)8(require 'cc-langs)910;; Hack load-in-progress to silence the c-lang-defconst error. For11;; some reason, load-in-progress is nil at some times when it12;; shouldn't be, at least on released emacs-23.1.1.13(let ((load-in-progress t))1415;; Updated c-nonlabel-token-key based on cc-langs.el 5.267.2.22, to16;; allow character constants in case labels.17(c-lang-defconst c-nonlabel-token-key18"Regexp matching things that can't occur in generic colon labels,19neither in a statement nor in a declaration context. The regexp is20tested at the beginning of every sexp in a suspected label,21i.e. before \":\". Only used if `c-recognize-colon-labels' is set."22t (concat23;; Don't allow string literals.24"\"\\|"25;; All keywords except `c-label-kwds' and `c-protection-kwds'.26(c-make-keywords-re t27(set-difference (c-lang-const c-keywords)28(append (c-lang-const c-label-kwds)29(c-lang-const c-protection-kwds))30:test 'string-equal)))31;; Also check for open parens in C++, to catch member init lists in32;; constructors. We normally allow it so that macros with arguments33;; work in labels.34c++ (concat "\\s\(\\|" (c-lang-const c-nonlabel-token-key)))35(c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key))3637;; Monkey-patch by way of c-mode-common-hook, as the byte-compiled38;; version of c-init-language-vars will have the old value. This39;; avoids finding some way to re-evaluate the defun for40;; c-init-language-vars.41(defun krb5-c-monkey-patch-caselabel ()42(setq c-nonlabel-token-key (c-lang-const c-nonlabel-token-key)))43(add-hook 'c-mode-common-hook 'krb5-c-monkey-patch-caselabel))444546