]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/cc-langs.el
Correctly fontify Java class constructors.
[gnu-emacs] / lisp / progmodes / cc-langs.el
index 76dfb3c7a28ae1827eeac5b7992313491aaf510f..80e6189822b135a35b8dbd87609a5dab046ca54b 100644 (file)
@@ -1,6 +1,6 @@
-;;; cc-langs.el --- language specific settings for CC Mode
+;;; cc-langs.el --- language specific settings for CC Mode -*- coding: utf-8 -*-
 
-;; Copyright (C) 1985, 1987, 1992-201 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1987, 1992-2013 Free Software Foundation, Inc.
 
 ;; Authors:    2002- Alan Mackenzie
 ;;             1998- Martin Stjernholm
@@ -208,9 +208,10 @@ the evaluated constant value at compile time."
 
 ;; Suppress "might not be defined at runtime" warning.
 ;; This file is only used when compiling other cc files.
-(declare-function delete-duplicates "cl-seq" (cl-seq &rest cl-keys))
-(declare-function mapcan "cl-extra" (cl-func cl-seq &rest cl-rest))
-(declare-function cl-macroexpand-all "cl-extra" (form &optional env))
+;; These are defined in cl as aliases to the cl- versions.
+(declare-function delete-duplicates "cl-seq" (cl-seq &rest cl-keys) t)
+(declare-function mapcan "cl-extra" (cl-func cl-seq &rest cl-rest) t)
+(declare-function cl-macroexpand-all "cl" (form &optional env))
 
 (eval-and-compile
   ;; Some helper functions used when building the language constants.
@@ -221,7 +222,7 @@ the evaluated constant value at compile time."
     ;;
     ;; OPS either has the structure of `c-operators', is a single
     ;; group in `c-operators', or is a plain list of operators.
-    ;; 
+    ;;
     ;; OPGROUP-FILTER specifies how to select the operator groups.  It
     ;; can be t to choose all groups, a list of group type symbols
     ;; (such as 'prefix) to accept, or a function which will be called
@@ -433,7 +434,7 @@ element is a cons where the car is the character to modify and the cdr
 the new syntax, as accepted by `modify-syntax-entry'."
   ;; The $ character is not allowed in most languages (one exception
   ;; is Java which allows it for legacy reasons) but we still classify
-  ;; it as an indentifier character since it's often used in various
+  ;; it as an identifier character since it's often used in various
   ;; machine generated identifiers.
   t    '((?_ . "w") (?$ . "w"))
   (objc java) (append '((?@ . "w"))
@@ -459,8 +460,10 @@ so that all identifiers are recognized as words.")
   ;; For documentation see the following c-lang-defvar of the same name.
   ;; The value here may be a list of functions or a single function.
   t nil
-  c++ '(c-extend-region-for-CPP c-before-change-check-<>-operators)
-  (c objc) 'c-extend-region-for-CPP
+  c++ '(c-extend-region-for-CPP
+       c-before-change-check-<>-operators
+       c-invalidate-macro-cache)
+  (c objc) '(c-extend-region-for-CPP c-invalidate-macro-cache)
   ;; java 'c-before-change-check-<>-operators
   awk 'c-awk-record-region-clear-NL)
 (c-lang-defvar c-get-state-before-change-functions
@@ -485,28 +488,56 @@ The functions are called even when font locking isn't enabled.
 When the mode is initialized, the functions are called with
 parameters \(point-min) and \(point-max).")
 
-(c-lang-defconst c-before-font-lock-function
-  "If non-nil, a function called just before font locking.
-Typically it will extend the region about to be fontified \(see
+(c-lang-defconst c-before-font-lock-functions
+  ;; For documentation see the following c-lang-defvar of the same name.
+  ;; The value here may be a list of functions or a single function.
+  t 'c-change-set-fl-decl-start
+  (c c++ objc) '(c-neutralize-syntax-in-and-mark-CPP
+                c-change-set-fl-decl-start)
+  awk 'c-awk-extend-and-syntax-tablify-region)
+(c-lang-defvar c-before-font-lock-functions
+              (let ((fs (c-lang-const c-before-font-lock-functions)))
+                (if (listp fs)
+                    fs
+                  (list fs)))
+  "If non-nil, a list of functions called just before font locking.
+Typically they will extend the region about to be fontified \(see
 below) and will set `syntax-table' text properties on the region.
 
-It takes 3 parameters, the BEG, END, and OLD-LEN supplied to
-every after-change function; point is undefined on both entry and
-exit; on entry, the buffer will have been widened and match-data
-will have been saved; the return value is ignored.
+These functions will be run in the order given.  Each of them
+takes 3 parameters, the BEG, END, and OLD-LEN supplied to every
+after-change function; point is undefined on both entry and exit;
+on entry, the buffer will have been widened and match-data will
+have been saved; the return value is ignored.
 
-The function may extend the region to be fontified by setting the
+The functions may extend the region to be fontified by setting the
 buffer local variables c-new-BEG and c-new-END.
 
-The function is called even when font locking is disabled.
+The functions are called even when font locking is disabled.
 
-When the mode is initialized, this function is called with
-parameters \(point-min), \(point-max) and <buffer size>."
-  t nil
-  (c c++ objc) 'c-neutralize-syntax-in-and-mark-CPP
-  awk 'c-awk-extend-and-syntax-tablify-region)
-(c-lang-defvar c-before-font-lock-function
-              (c-lang-const c-before-font-lock-function))
+When the mode is initialized, these functions are called with
+parameters \(point-min), \(point-max) and <buffer size>.")
+
+(c-lang-defconst c-before-context-fontification-functions
+  awk nil
+  t 'c-context-set-fl-decl-start)
+  ;; For documentation see the following c-lang-defvar of the same name.
+  ;; The value here may be a list of functions or a single function.
+(c-lang-defvar c-before-context-fontification-functions
+  (let ((fs (c-lang-const c-before-context-fontification-functions)))
+    (if (listp fs)
+       fs
+      (list fs)))
+  "If non-nil, a list of functions called just before context (or
+other non-change) fontification is done.  Typically they will
+extend the region.
+
+These functions will be run in the order given.  Each of them
+takes 2 parameters, the BEG and END of the region to be
+fontified.  Point is undefined on both entry and exit.  On entry,
+the buffer will have been widened and match-data will have been
+saved; the return value is a cons of the adjusted
+region, (NEW-BEG . NEW-END).")
 
 \f
 ;;; Syntactic analysis ("virtual semicolons") for line-oriented languages (AWK).
@@ -522,7 +553,7 @@ don't have EOL terminated statements. "
 
 (c-lang-defconst c-vsemi-status-unknown-p-fn
   "Contains a function \"are we unsure whether there is a virtual semicolon on this line?\".
-The (admittedly kludgey) purpose of such a function is to prevent an infinite
+The (admittedly kludgy) purpose of such a function is to prevent an infinite
 recursion in c-beginning-of-statement-1 when point starts at a `while' token.
 The function MUST NOT UNDER ANY CIRCUMSTANCES call c-beginning-of-statement-1,
 even indirectly.  This variable contains nil for languages which don't have
@@ -548,7 +579,7 @@ keyword.  It's unspecified how far it matches.      Does not contain a \\|
 operator at the top level."
   t    (concat "[" c-alpha "_]")
   java (concat "[" c-alpha "_@]")
-  objc (concat "[" c-alpha "@]")
+  objc (concat "[" c-alpha "_@]")
   pike (concat "[" c-alpha "_`]"))
 (c-lang-defvar c-symbol-start (c-lang-const c-symbol-start))
 
@@ -781,8 +812,8 @@ Assumed to not contain any submatches or \\| operators."
 (c-lang-defconst c-anchored-cpp-prefix
   "Regexp matching the prefix of a cpp directive anchored to BOL,
 in the languages that have a macro preprocessor."
-  t (if (c-lang-const c-opt-cpp-prefix)
-       (concat "^" (c-lang-const c-opt-cpp-prefix))))
+  t "^\\s *\\(#\\)\\s *"
+  (java awk) nil)
 (c-lang-defvar c-anchored-cpp-prefix (c-lang-const c-anchored-cpp-prefix))
 
 (c-lang-defconst c-opt-cpp-start
@@ -2132,8 +2163,7 @@ assumed to be set if this isn't nil."
 (c-lang-defconst c-opt-<>-sexp-key
   ;; Adorned regexp matching keywords that can be followed by an angle
   ;; bracket sexp.  Always set when `c-recognize-<>-arglists' is.
-  t (if (c-lang-const c-recognize-<>-arglists)
-       (c-make-keywords-re t (c-lang-const c-<>-sexp-kwds))))
+  t (c-make-keywords-re t (c-lang-const c-<>-sexp-kwds)))
 (c-lang-defvar c-opt-<>-sexp-key (c-lang-const c-opt-<>-sexp-key))
 
 (c-lang-defconst c-brace-id-list-kwds
@@ -2156,6 +2186,18 @@ identifiers that follows the type in a normal declaration."
   t (c-make-keywords-re t (c-lang-const c-block-stmt-1-kwds)))
 (c-lang-defvar c-block-stmt-1-key (c-lang-const c-block-stmt-1-key))
 
+(c-lang-defconst c-block-stmt-1-2-kwds
+  "Statement keywords optionally followed by a paren sexp.
+Keywords here should also be in `c-block-stmt-1-kwds'."
+  t nil
+  java '("try"))
+
+(c-lang-defconst c-block-stmt-1-2-key
+  ;; Regexp matching the start of a statement which may be followed by a
+  ;; paren sexp and will then be followed by a substatement.
+  t (c-make-keywords-re t (c-lang-const c-block-stmt-1-2-kwds)))
+(c-lang-defvar c-block-stmt-1-2-key (c-lang-const c-block-stmt-1-2-key))
+
 (c-lang-defconst c-block-stmt-2-kwds
   "Statement keywords followed by a paren sexp and then by a substatement."
   t    '("for" "if" "switch" "while")
@@ -2242,8 +2284,7 @@ This construct is \"<keyword> <expression> :\"."
 
 (c-lang-defconst c-label-kwds
   "Keywords introducing colon terminated labels in blocks."
-  t '("case" "default")
-  awk nil)
+  t '("case" "default"))
 
 (c-lang-defconst c-label-kwds-regexp
   ;; Adorned regexp matching any keyword that introduces a label.
@@ -2775,7 +2816,8 @@ is in effect when this is matched (see `c-identifier-syntax-table')."
                     "\\>")
                  "")
                "\\)")
-  (java idl) "\\([\[\(]\\)")
+  java "\\([\[\(\)]\\)"
+  idl "\\([\[\(]\\)")
 (c-lang-defvar c-type-decl-suffix-key (c-lang-const c-type-decl-suffix-key)
   'dont-doc)
 
@@ -2789,7 +2831,7 @@ undefined whether identifier syntax (see `c-identifier-syntax-table')
 is in effect or not.
 
 Note that it's used in cases like after \"foo (bar)\" so it should
-only match when it's certain that it's a declaration, e.g \"{\" but
+only match when it's certain that it's a declaration, e.g., \"{\" but
 not \",\" or \";\"."
   t "{"
   ;; If K&R style declarations should be recognized then one could
@@ -2877,7 +2919,7 @@ is in effect or not."
 
 (c-lang-defconst c-special-brace-lists
 "List of open- and close-chars that makes up a pike-style brace list,
-i.e. for a ([ ]) list there should be a cons (?\\[ . ?\\]) in this
+i.e. for a ([ ]) list there should be a cons (?\\[ . ?\\]) in this
 list."
   t    nil
   pike '((?{ . ?}) (?\[ . ?\]) (?< . ?>)))
@@ -2896,7 +2938,7 @@ calls before a brace block.  This setting does not affect declarations
 that are preceded by a declaration starting keyword, so
 e.g. `c-typeless-decl-kwds' may still be used when it's set to nil."
   t nil
-  (c c++ objc) t)
+  (c c++ objc java) t)
 (c-lang-defvar c-recognize-typeless-decls
   (c-lang-const c-recognize-typeless-decls))
 
@@ -2908,9 +2950,16 @@ identifier or one of the keywords on `c-<>-type-kwds' or
 `c-<>-arglist-kwds'.  If there's an identifier before then the whole
 expression is considered to be a type."
   t (or (consp (c-lang-const c-<>-type-kwds))
-       (consp (c-lang-const c-<>-arglist-kwds))))
+       (consp (c-lang-const c-<>-arglist-kwds)))
+  java t)
 (c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists))
 
+(c-lang-defconst c-enums-contain-decls
+  "Non-nil means that an enum structure can contain declarations."
+  t nil
+  java t)
+(c-lang-defvar c-enums-contain-decls (c-lang-const c-enums-contain-decls))
+
 (c-lang-defconst c-recognize-paren-inits
   "Non-nil means that parenthesis style initializers exist,
 i.e. constructs like
@@ -2998,18 +3047,19 @@ 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)))
+  ;; Don't allow string literals, except in AWK.  Character constants are OK.
+  (c objc java pike idl) (concat "\"\\|"
+                                (c-lang-const c-nonlabel-token-key))
   ;; 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++ (concat "\\s\(\\|\"\\|" (c-lang-const c-nonlabel-token-key)))
 (c-lang-defvar c-nonlabel-token-key (c-lang-const c-nonlabel-token-key))
 
 (c-lang-defconst c-nonlabel-token-2-key