]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/cc-mode.el
Merge from origin/emacs-24
[gnu-emacs] / lisp / progmodes / cc-mode.el
index 36c9f72fa18dfaa325bb5ea00039d10b23e584a5..01e93b3f202087454ac498dc7b5c7b959889d482 100644 (file)
@@ -1,6 +1,6 @@
 ;;; cc-mode.el --- major mode for editing C and similar languages
 
-;; Copyright (C) 1985, 1987, 1992-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1987, 1992-2015 Free Software Foundation, Inc.
 
 ;; Authors:    2003- Alan Mackenzie
 ;;             1998- Martin Stjernholm
@@ -75,7 +75,7 @@
 
 ;; For Emacs < 22.2.
 (eval-and-compile
-  (unless (fboundp 'declare-function) (defmacro declare-function (&rest r))))
+  (unless (fboundp 'declare-function) (defmacro declare-function (&rest _r))))
 
 (eval-when-compile
   (let ((load-path
 ;; with your version of Emacs, you are incompatible!
 (cc-external-require 'easymenu)
 
-;; Autoload directive for emacsen that doesn't have an older CC Mode
-;; version in the dist.
-(autoload 'subword-mode "subword"
-  "Mode enabling subword movement and editing keys." t)
-
 ;; Load cc-fonts first after font-lock is loaded, since it isn't
 ;; necessary until font locking is requested.
 ; (eval-after-load "font-lock" ; 2006-07-09: font-lock is now preloaded.
@@ -185,10 +180,14 @@ control).  See \"cc-mode.el\" for more info."
            (run-hooks 'c-initialization-hook)
            ;; Fix obsolete variables.
            (if (boundp 'c-comment-continuation-stars)
-               (setq c-block-comment-prefix
-                     (symbol-value 'c-comment-continuation-stars)))
+               (setq c-block-comment-prefix c-comment-continuation-stars))
            (add-hook 'change-major-mode-hook 'c-leave-cc-mode-mode)
-           (setq c-initialization-ok t))
+           (setq c-initialization-ok t)
+           ;; Connect up with Emacs's electric-indent-mode, for >= Emacs 24.4
+            (when (fboundp 'electric-indent-local-mode)
+             (add-hook 'electric-indent-mode-hook 'c-electric-indent-mode-hook)
+              (add-hook 'electric-indent-local-mode-hook
+                        'c-electric-indent-local-mode-hook)))
        ;; Will try initialization hooks again if they failed.
        (put 'c-initialize-cc-mode initprop c-initialization-ok))))
 
@@ -217,12 +216,16 @@ control).  See \"cc-mode.el\" for more info."
      (t (error "CC Mode is incompatible with this version of Emacs")))
     map))
 
-(defun c-define-abbrev-table (name defs)
+(defun c-define-abbrev-table (name defs &optional doc)
   ;; Compatibility wrapper for `define-abbrev' which passes a non-nil
   ;; sixth argument for SYSTEM-FLAG in emacsen that support it
   ;; (currently only Emacs >= 21.2).
-  (let ((table (or (symbol-value name)
-                  (progn (define-abbrev-table name nil)
+  (let ((table (or (and (boundp name) (symbol-value name))
+                  (progn (condition-case nil
+                              (define-abbrev-table name nil doc)
+                            (wrong-number-of-arguments ;E.g. Emacs<23.
+                             (eval `(defvar ,name nil ,doc))
+                             (define-abbrev-table name nil)))
                          (symbol-value name)))))
     (while defs
       (condition-case nil
@@ -371,7 +374,7 @@ control).  See \"cc-mode.el\" for more info."
   ;; conflicts with OOBR
   ;;(define-key c-mode-base-map "\C-c\C-v"  'c-version)
   ;; (define-key c-mode-base-map "\C-c\C-y"  'c-toggle-hungry-state)  Commented out by ACM, 2005-11-22.
-  (define-key c-mode-base-map "\C-c\C-w" 'subword-mode)
+  (define-key c-mode-base-map "\C-c\C-w" 'c-subword-mode)
   )
 
 ;; We don't require the outline package, but we configure it a bit anyway.
@@ -463,6 +466,14 @@ preferably use the `c-mode-menu' language constant directly."
 (defvar c-maybe-stale-found-type nil)
 (make-variable-buffer-local 'c-maybe-stale-found-type)
 
+(defvar c-just-done-before-change nil)
+(make-variable-buffer-local 'c-just-done-before-change)
+;; This variable is set to t by `c-before-change' and to nil by
+;; `c-after-change'.  It is used to detect a spurious invocation of
+;; `before-change-functions' directly following on from a correct one.  This
+;; happens in some Emacsen, for example when `basic-save-buffer' does (insert
+;; ?\n) when `require-final-newline' is non-nil.
+
 (defun c-basic-common-init (mode default-style)
   "Do the necessary initialization for the syntax handling routines
 and the line breaking/filling code.  Intended to be used by other
@@ -533,10 +544,11 @@ that requires a literal mode spec at compile time."
   ;; Use this in Emacs 21+ to avoid meddling with the rear-nonsticky
   ;; property on each character.
   (when (boundp 'text-property-default-nonsticky)
+    (make-local-variable 'text-property-default-nonsticky)
     (mapc (lambda (tprop)
            (unless (assq tprop text-property-default-nonsticky)
-             (set (make-local-variable 'text-property-default-nonsticky)
-                   (cons `(,tprop . t) text-property-default-nonsticky))))
+             (setq text-property-default-nonsticky
+                    (cons `(,tprop . t) text-property-default-nonsticky))))
          '(syntax-table category c-type)))
 
   ;; In Emacs 21 and later it's possible to turn off the ad-hoc
@@ -574,6 +586,15 @@ that requires a literal mode spec at compile time."
   ;; setup the comment indent variable in a Emacs version portable way
   (set (make-local-variable 'comment-indent-function) 'c-comment-indent)
 
+  ;; In Emacs 24.4 onwards, prevent Emacs's built in electric indentation from
+  ;; messing up CC Mode's, and set `c-electric-flag' if `electric-indent-mode'
+  ;; has been called by the user.
+  (when (boundp 'electric-indent-inhibit) (setq electric-indent-inhibit t))
+  ;; CC-mode should obey Emacs's generic preferences, tho only do it if
+  ;; Emacs's generic preferences can be set per-buffer (Emacs>=24.4).
+  (when (fboundp 'electric-indent-local-mode)
+    (setq c-electric-flag electric-indent-mode))
+
 ;;   ;; Put submode indicators onto minor-mode-alist, but only once.
 ;;   (or (assq 'c-submode-indicators minor-mode-alist)
 ;;       (setq minor-mode-alist
@@ -587,10 +608,12 @@ that requires a literal mode spec at compile time."
     (make-local-hook 'before-change-functions)
     (make-local-hook 'after-change-functions))
   (add-hook 'before-change-functions 'c-before-change nil t)
+  (setq c-just-done-before-change nil)
   (add-hook 'after-change-functions 'c-after-change nil t)
-  (set (make-local-variable 'font-lock-extend-after-change-region-function)
-       'c-extend-after-change-region)) ; Currently (2009-05) used by all
-                       ; languages with #define (C, C++,; ObjC), and by AWK.
+  (when (boundp 'font-lock-extend-after-change-region-function)
+    (set (make-local-variable 'font-lock-extend-after-change-region-function)
+         'c-extend-after-change-region))) ; Currently (2009-05) used by all
+                          ; languages with #define (C, C++,; ObjC), and by AWK.
 
 (defun c-setup-doc-comment-style ()
   "Initialize the variables that depend on the value of `c-doc-comment-style'."
@@ -651,9 +674,11 @@ compatible with old code; callers should always specify it."
         (or (c-cpp-define-name) (c-defun-name))))
   (let ((rfn (assq mode c-require-final-newline)))
     (when rfn
-      (and (cdr rfn)
-          (set (make-local-variable 'require-final-newline)
-                mode-require-final-newline)))))
+      (if (boundp 'mode-require-final-newline)
+          (and (cdr rfn)
+               (set (make-local-variable 'require-final-newline)
+                    mode-require-final-newline))
+        (set (make-local-variable 'require-final-newline) (cdr rfn))))))
 
 (defun c-count-cfss (lv-alist)
   ;; LV-ALIST is an alist like `file-local-variables-alist'.  Count how many
@@ -803,7 +828,7 @@ Note that the style variables are always made local to the buffer."
     `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks))))
 
 \f
-;;; Change hooks, linking with Font Lock.
+;;; Change hooks, linking with Font Lock and electric-indent-mode.
 
 ;; Buffer local variables recording Beginning/End-of-Macro position before a
 ;; change, when a macro straddles, respectively, the BEG or END (or both) of
@@ -930,7 +955,11 @@ Note that the style variables are always made local to the buffer."
          c-new-END (min (cdr new-bounds) (c-determine-+ve-limit 500 endd)))
     ;; Clear all old relevant properties.
     (c-clear-char-property-with-value c-new-BEG c-new-END 'syntax-table '(1))
-    (c-clear-char-property-with-value c-new-BEG c-new-END 'category 'c-cpp-delimiter)
+
+    ;; CPP "comment" markers:
+    (if (eval-when-compile (memq 'category-properties c-emacs-features));Emacs.
+       (c-clear-char-property-with-value
+        c-new-BEG c-new-END 'category 'c-cpp-delimiter))
     ;; FIXME!!!  What about the "<" and ">" category properties?  2009-11-16
 
     ;; Add needed properties to each CPP construct in the region.
@@ -949,8 +978,10 @@ Note that the style variables are always made local to the buffer."
          (setq mbeg (point))
          (if (> (c-syntactic-end-of-macro) mbeg)
              (progn
-               (c-neutralize-CPP-line mbeg (point))
-               (c-set-cpp-delimiters mbeg (point)))
+               (c-neutralize-CPP-line mbeg (point)) ; "punctuation" properties
+               (if (eval-when-compile
+                      (memq 'category-properties c-emacs-features)) ;Emacs.
+                   (c-set-cpp-delimiters mbeg (point)))) ; "comment" markers
            (forward-line))           ; no infinite loop with, e.g., "#//"
          )))))
 
@@ -970,74 +1001,82 @@ Note that the style variables are always made local to the buffer."
   ;; it/them from the cache.  Don't worry about being inside a string
   ;; or a comment - "wrongly" removing a symbol from `c-found-types'
   ;; isn't critical.
-  (setq c-maybe-stale-found-type nil)
-  (save-restriction
-    (save-match-data
-      (widen)
-      (save-excursion
-       ;; Are we inserting/deleting stuff in the middle of an identifier?
-       (c-unfind-enclosing-token beg)
-       (c-unfind-enclosing-token end)
-       ;; Are we coalescing two tokens together, e.g. "fo o" -> "foo"?
-       (when (< beg end)
-         (c-unfind-coalesced-tokens beg end))
-       ;; Are we (potentially) disrupting the syntactic context which
-       ;; makes a type a type?  E.g. by inserting stuff after "foo" in
-       ;; "foo bar;", or before "foo" in "typedef foo *bar;"?
-       ;;
-       ;; We search for appropriate c-type properties "near" the change.
-       ;; First, find an appropriate boundary for this property search.
-       (let (lim
-             type type-pos
-             marked-id term-pos
-             (end1
-              (or (and (eq (get-text-property end 'face) 'font-lock-comment-face)
-                       (previous-single-property-change end 'face))
-                  end)))
-         (when (>= end1 beg) ; Don't hassle about changes entirely in comments.
-           ;; Find a limit for the search for a `c-type' property
-           (while
-               (and (/= (skip-chars-backward "^;{}") 0)
-                    (> (point) (point-min))
-                    (memq (c-get-char-property (1- (point)) 'face)
-                          '(font-lock-comment-face font-lock-string-face))))
-           (setq lim (max (point-min) (1- (point))))
-
-           ;; Look for the latest `c-type' property before end1
-           (when (and (> end1 (point-min))
-                      (setq type-pos
-                            (if (get-text-property (1- end1) 'c-type)
-                                end1
-                              (previous-single-property-change end1 'c-type nil lim))))
-             (setq type (get-text-property (max (1- type-pos) lim) 'c-type))
-
-             (when (memq type '(c-decl-id-start c-decl-type-start))
-               ;; Get the identifier, if any, that the property is on.
-               (goto-char (1- type-pos))
-               (setq marked-id
-                     (when (looking-at "\\(\\sw\\|\\s_\\)")
-                       (c-beginning-of-current-token)
-                       (buffer-substring-no-properties (point) type-pos)))
-
-               (goto-char end1)
-               (skip-chars-forward "^;{}") ; FIXME!!!  loop for comment, maybe
-               (setq lim (point))
-               (setq term-pos
-                     (or (next-single-property-change end 'c-type nil lim) lim))
-               (setq c-maybe-stale-found-type
-                     (list type marked-id
-                           type-pos term-pos
-                           (buffer-substring-no-properties type-pos term-pos)
-                           (buffer-substring-no-properties beg end)))))))
-
-       (if c-get-state-before-change-functions
-           (mapc (lambda (fn)
-                   (funcall fn beg end))
-                 c-get-state-before-change-functions))
-       )))
-  ;; The following must be done here rather than in `c-after-change' because
-  ;; newly inserted parens would foul up the invalidation algorithm.
-  (c-invalidate-state-cache beg))
+  (unless c-just-done-before-change  ; Guard against a spurious second
+                             ; invocation of before-change-functions.
+    (setq c-just-done-before-change t)
+    (setq c-maybe-stale-found-type nil)
+    (save-restriction
+      (save-match-data
+       (widen)
+       (save-excursion
+         ;; Are we inserting/deleting stuff in the middle of an identifier?
+         (c-unfind-enclosing-token beg)
+         (c-unfind-enclosing-token end)
+         ;; Are we coalescing two tokens together, e.g. "fo o" -> "foo"?
+         (when (< beg end)
+           (c-unfind-coalesced-tokens beg end))
+         ;; Are we (potentially) disrupting the syntactic context which
+         ;; makes a type a type?  E.g. by inserting stuff after "foo" in
+         ;; "foo bar;", or before "foo" in "typedef foo *bar;"?
+         ;;
+         ;; We search for appropriate c-type properties "near" the change.
+         ;; First, find an appropriate boundary for this property search.
+         (let (lim
+               type type-pos
+               marked-id term-pos
+               (end1
+                (or (and (eq (get-text-property end 'face)
+                             'font-lock-comment-face)
+                         (previous-single-property-change end 'face))
+                    end)))
+           (when (>= end1 beg) ; Don't hassle about changes entirely in comments.
+             ;; Find a limit for the search for a `c-type' property
+             (while
+                 (and (/= (skip-chars-backward "^;{}") 0)
+                      (> (point) (point-min))
+                      (memq (c-get-char-property (1- (point)) 'face)
+                            '(font-lock-comment-face font-lock-string-face))))
+             (setq lim (max (point-min) (1- (point))))
+
+             ;; Look for the latest `c-type' property before end1
+             (when (and (> end1 (point-min))
+                        (setq type-pos
+                              (if (get-text-property (1- end1) 'c-type)
+                                  end1
+                                (previous-single-property-change end1 'c-type
+                                                                 nil lim))))
+               (setq type (get-text-property (max (1- type-pos) lim) 'c-type))
+
+               (when (memq type '(c-decl-id-start c-decl-type-start))
+                 ;; Get the identifier, if any, that the property is on.
+                 (goto-char (1- type-pos))
+                 (setq marked-id
+                       (when (looking-at "\\(\\sw\\|\\s_\\)")
+                         (c-beginning-of-current-token)
+                         (buffer-substring-no-properties (point) type-pos)))
+
+                 (goto-char end1)
+                 (skip-chars-forward "^;{}") ;FIXME!!! loop for comment, maybe
+                 (setq lim (point))
+                 (setq term-pos
+                       (or (c-next-single-property-change end 'c-type nil lim)
+                           lim))
+                 (setq c-maybe-stale-found-type
+                       (list type marked-id
+                             type-pos term-pos
+                             (buffer-substring-no-properties type-pos
+                                                             term-pos)
+                             (buffer-substring-no-properties beg end)))))))
+
+         (if c-get-state-before-change-functions
+             (let (open-paren-in-column-0-is-defun-start)
+               (mapc (lambda (fn)
+                       (funcall fn beg end))
+                     c-get-state-before-change-functions)))
+         )))
+    ;; The following must be done here rather than in `c-after-change' because
+    ;; newly inserted parens would foul up the invalidation algorithm.
+    (c-invalidate-state-cache beg)))
 
 (defvar c-in-after-change-fontification nil)
 (make-variable-buffer-local 'c-in-after-change-fontification)
@@ -1058,7 +1097,8 @@ Note that the style variables are always made local to the buffer."
   ;; This calls the language variable c-before-font-lock-functions, if non nil.
   ;; This typically sets `syntax-table' properties.
 
-  (c-save-buffer-state (case-fold-search)
+  (setq c-just-done-before-change nil)
+  (c-save-buffer-state (case-fold-search open-paren-in-column-0-is-defun-start)
     ;; When `combine-after-change-calls' is used we might get calls
     ;; with regions outside the current narrowing.  This has been
     ;; observed in Emacs 20.7.
@@ -1078,11 +1118,12 @@ Note that the style variables are always made local to the buffer."
        ;; C-y is capable of spuriously converting category properties
        ;; c-</>-as-paren-syntax and c-cpp-delimiter into hard syntax-table
        ;; properties.  Remove these when it happens.
-       (c-clear-char-property-with-value beg end 'syntax-table
-                                         c-<-as-paren-syntax)
-       (c-clear-char-property-with-value beg end 'syntax-table
-                                         c->-as-paren-syntax)
-       (c-clear-char-property-with-value beg end 'syntax-table nil)
+       (when (eval-when-compile (memq 'category-properties c-emacs-features))
+         (c-clear-char-property-with-value beg end 'syntax-table
+                                           c-<-as-paren-syntax)
+         (c-clear-char-property-with-value beg end 'syntax-table
+                                           c->-as-paren-syntax)
+         (c-clear-char-property-with-value beg end 'syntax-table nil))
 
        (c-trim-found-types beg end old-len) ; maybe we don't need all of these.
        (c-invalidate-sws-region-after beg end)
@@ -1146,7 +1187,7 @@ Note that the style variables are always made local to the buffer."
       (backward-char))
     new-pos))                          ; back over (, [, <.
 
-(defun c-change-set-fl-decl-start (beg end old-len)
+(defun c-change-set-fl-decl-start (_beg _end _old-len)
   ;; Set c-new-BEG to the beginning of a "local" declaration if it('s BOL) is
   ;; inside one.  This is called from an after-change-function, but the
   ;; parameters BEG END and OLD-LEN are ignored.  See `c-set-fl-decl-start'
@@ -1174,7 +1215,8 @@ Note that the style variables are always made local to the buffer."
   ;; 
   ;; Type a space in the first blank line, and the fontification of the next
   ;; line was fouled up by context fontification.
-  (let ((new-beg beg) (new-end end) new-region case-fold-search)
+  (let ((new-beg beg) (new-end end) new-region case-fold-search
+       open-paren-in-column-0-is-defun-start)
     (if c-in-after-change-fontification
        (setq c-in-after-change-fontification nil)
       (save-restriction
@@ -1219,7 +1261,8 @@ This function is called from `c-common-init', once per mode initialization."
       (make-local-hook 'font-lock-mode-hook))
   (add-hook 'font-lock-mode-hook 'c-after-font-lock-init nil t))
 
-(defun c-extend-after-change-region (beg end old-len)
+;; Emacs 22 and later.
+(defun c-extend-after-change-region (_beg _end _old-len)
   "Extend the region to be fontified, if necessary."
   ;; Note: the parameters are ignored here.  This somewhat indirect
   ;; implementation exists because it is minimally different from the
@@ -1232,30 +1275,59 @@ This function is called from `c-common-init', once per mode initialization."
   ;; function.
   (cons c-new-BEG c-new-END))
 
+;; Emacs < 22 and XEmacs
+(defmacro c-advise-fl-for-region (function)
+  `(defadvice ,function (before get-awk-region activate)
+     ;; Make sure that any string/regexp is completely font-locked.
+     (when c-buffer-is-cc-mode
+       (save-excursion
+        (ad-set-arg 1 c-new-END)   ; end
+        (ad-set-arg 0 c-new-BEG)))))   ; beg
+
+(unless (boundp 'font-lock-extend-after-change-region-function)
+  (c-advise-fl-for-region font-lock-after-change-function)
+  (c-advise-fl-for-region jit-lock-after-change)
+  (c-advise-fl-for-region lazy-lock-defer-rest-after-change)
+  (c-advise-fl-for-region lazy-lock-defer-line-after-change))
+
+;; Connect up to `electric-indent-mode' (Emacs 24.4 and later).
+(defun c-electric-indent-mode-hook ()
+  ;; Emacs has en/disabled `electric-indent-mode'.  Propagate this through to
+  ;; each CC Mode buffer.
+  (mapc (lambda (buf)
+          (with-current-buffer buf
+            (when c-buffer-is-cc-mode
+              ;; Don't use `c-toggle-electric-state' here due to recursion.
+              (setq c-electric-flag electric-indent-mode)
+              (c-update-modeline))))
+        (buffer-list)))
+
+(defun c-electric-indent-local-mode-hook ()
+  ;; Emacs has en/disabled `electric-indent-local-mode' for this buffer.
+  ;; Propagate this through to this buffer's value of `c-electric-flag'
+  (when c-buffer-is-cc-mode
+    (setq c-electric-flag electric-indent-mode)
+    (c-update-modeline)))
+
 \f
 ;; Support for C
 
-;;;###autoload
-(defvar c-mode-syntax-table nil
+(defvar c-mode-syntax-table
+  (funcall (c-lang-const c-make-mode-syntax-table c))
   "Syntax table used in c-mode buffers.")
-(or c-mode-syntax-table
-    (setq c-mode-syntax-table
-         (funcall (c-lang-const c-make-mode-syntax-table c))))
 
-(defvar c-mode-abbrev-table nil
-  "Abbreviation table used in c-mode buffers.")
 (c-define-abbrev-table 'c-mode-abbrev-table
   '(("else" "else" c-electric-continued-statement 0)
-    ("while" "while" c-electric-continued-statement 0)))
+    ("while" "while" c-electric-continued-statement 0))
+  "Abbreviation table used in c-mode buffers.")
 
-(defvar c-mode-map ()
+(defvar c-mode-map
+  (let ((map (c-make-inherited-keymap)))
+    ;; Add bindings which are only useful for C.
+    (define-key map "\C-c\C-e"  'c-macro-expand)
+    map)
   "Keymap used in c-mode buffers.")
-(if c-mode-map
-    nil
-  (setq c-mode-map (c-make-inherited-keymap))
-  ;; add bindings which are only useful for C
-  (define-key c-mode-map "\C-c\C-e"  'c-macro-expand)
-  )
+
 
 (easy-menu-define c-c-menu c-mode-map "C Mode Commands"
                  (cons "C" (c-lang-const c-mode-menu c)))
@@ -1288,6 +1360,7 @@ This function is called from `c-common-init', once per mode initialization."
 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.i\\'" . c-mode))
 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.ii\\'" . c++-mode))
 
+(unless (fboundp 'prog-mode) (defalias 'prog-mode 'fundamental-mode))
 
 ;;;###autoload
 (define-derived-mode c-mode prog-mode "C"
@@ -1320,30 +1393,25 @@ Key bindings:
 \f
 ;; Support for C++
 
-;;;###autoload
-(defvar c++-mode-syntax-table nil
+(defvar c++-mode-syntax-table
+  (funcall (c-lang-const c-make-mode-syntax-table c++))
   "Syntax table used in c++-mode buffers.")
-(or c++-mode-syntax-table
-    (setq c++-mode-syntax-table
-         (funcall (c-lang-const c-make-mode-syntax-table c++))))
 
-(defvar c++-mode-abbrev-table nil
-  "Abbreviation table used in c++-mode buffers.")
 (c-define-abbrev-table 'c++-mode-abbrev-table
   '(("else" "else" c-electric-continued-statement 0)
     ("while" "while" c-electric-continued-statement 0)
-    ("catch" "catch" c-electric-continued-statement 0)))
+    ("catch" "catch" c-electric-continued-statement 0))
+  "Abbreviation table used in c++-mode buffers.")
 
-(defvar c++-mode-map ()
+(defvar c++-mode-map
+  (let ((map (c-make-inherited-keymap)))
+    ;; Add bindings which are only useful for C++.
+    (define-key map "\C-c\C-e" 'c-macro-expand)
+    (define-key map "\C-c:"    'c-scope-operator)
+    (define-key map "<"        'c-electric-lt-gt)
+    (define-key map ">"        'c-electric-lt-gt)
+    map)
   "Keymap used in c++-mode buffers.")
-(if c++-mode-map
-    nil
-  (setq c++-mode-map (c-make-inherited-keymap))
-  ;; add bindings which are only useful for C++
-  (define-key c++-mode-map "\C-c\C-e" 'c-macro-expand)
-  (define-key c++-mode-map "\C-c:"    'c-scope-operator)
-  (define-key c++-mode-map "<"        'c-electric-lt-gt)
-  (define-key c++-mode-map ">"        'c-electric-lt-gt))
 
 (easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
                  (cons "C++" (c-lang-const c-mode-menu c++)))
@@ -1380,26 +1448,21 @@ Key bindings:
 \f
 ;; Support for Objective-C
 
-;;;###autoload
-(defvar objc-mode-syntax-table nil
+(defvar objc-mode-syntax-table
+  (funcall (c-lang-const c-make-mode-syntax-table objc))
   "Syntax table used in objc-mode buffers.")
-(or objc-mode-syntax-table
-    (setq objc-mode-syntax-table
-         (funcall (c-lang-const c-make-mode-syntax-table objc))))
 
-(defvar objc-mode-abbrev-table nil
-  "Abbreviation table used in objc-mode buffers.")
 (c-define-abbrev-table 'objc-mode-abbrev-table
   '(("else" "else" c-electric-continued-statement 0)
-    ("while" "while" c-electric-continued-statement 0)))
+    ("while" "while" c-electric-continued-statement 0))
+  "Abbreviation table used in objc-mode buffers.")
 
-(defvar objc-mode-map ()
+(defvar objc-mode-map
+  (let ((map (c-make-inherited-keymap)))
+    ;; Add bindings which are only useful for Objective-C.
+    (define-key map "\C-c\C-e" 'c-macro-expand)
+    map)
   "Keymap used in objc-mode buffers.")
-(if objc-mode-map
-    nil
-  (setq objc-mode-map (c-make-inherited-keymap))
-  ;; add bindings which are only useful for Objective-C
-  (define-key objc-mode-map "\C-c\C-e" 'c-macro-expand))
 
 (easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
                  (cons "ObjC" (c-lang-const c-mode-menu objc)))
@@ -1438,28 +1501,22 @@ Key bindings:
 \f
 ;; Support for Java
 
-;;;###autoload
-(defvar java-mode-syntax-table nil
+(defvar java-mode-syntax-table
+  (funcall (c-lang-const c-make-mode-syntax-table java))
   "Syntax table used in java-mode buffers.")
-(or java-mode-syntax-table
-    (setq java-mode-syntax-table
-         (funcall (c-lang-const c-make-mode-syntax-table java))))
 
-(defvar java-mode-abbrev-table nil
-  "Abbreviation table used in java-mode buffers.")
 (c-define-abbrev-table 'java-mode-abbrev-table
   '(("else" "else" c-electric-continued-statement 0)
     ("while" "while" c-electric-continued-statement 0)
     ("catch" "catch" c-electric-continued-statement 0)
-    ("finally" "finally" c-electric-continued-statement 0)))
+    ("finally" "finally" c-electric-continued-statement 0))
+  "Abbreviation table used in java-mode buffers.")
 
-(defvar java-mode-map ()
+(defvar java-mode-map
+  (let ((map (c-make-inherited-keymap)))
+    ;; Add bindings which are only useful for Java.
+    map)
   "Keymap used in java-mode buffers.")
-(if java-mode-map
-    nil
-  (setq java-mode-map (c-make-inherited-keymap))
-  ;; add bindings which are only useful for Java
-  )
 
 ;; Regexp trying to describe the beginning of a Java top-level
 ;; definition.  This is not used by CC Mode, nor is it maintained
@@ -1504,24 +1561,18 @@ Key bindings:
 \f
 ;; Support for CORBA's IDL language
 
-;;;###autoload
-(defvar idl-mode-syntax-table nil
+(defvar idl-mode-syntax-table
+  (funcall (c-lang-const c-make-mode-syntax-table idl))
   "Syntax table used in idl-mode buffers.")
-(or idl-mode-syntax-table
-    (setq idl-mode-syntax-table
-         (funcall (c-lang-const c-make-mode-syntax-table idl))))
 
-(defvar idl-mode-abbrev-table nil
+(c-define-abbrev-table 'idl-mode-abbrev-table nil
   "Abbreviation table used in idl-mode buffers.")
-(c-define-abbrev-table 'idl-mode-abbrev-table nil)
 
-(defvar idl-mode-map ()
+(defvar idl-mode-map
+  (let ((map (c-make-inherited-keymap)))
+    ;; Add bindings which are only useful for IDL.
+    map)
   "Keymap used in idl-mode buffers.")
-(if idl-mode-map
-    nil
-  (setq idl-mode-map (c-make-inherited-keymap))
-  ;; add bindings which are only useful for IDL
-  )
 
 (easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
                  (cons "IDL" (c-lang-const c-mode-menu idl)))
@@ -1558,26 +1609,21 @@ Key bindings:
 \f
 ;; Support for Pike
 
-;;;###autoload
-(defvar pike-mode-syntax-table nil
+(defvar pike-mode-syntax-table
+  (funcall (c-lang-const c-make-mode-syntax-table pike))
   "Syntax table used in pike-mode buffers.")
-(or pike-mode-syntax-table
-    (setq pike-mode-syntax-table
-         (funcall (c-lang-const c-make-mode-syntax-table pike))))
 
-(defvar pike-mode-abbrev-table nil
-  "Abbreviation table used in pike-mode buffers.")
 (c-define-abbrev-table 'pike-mode-abbrev-table
   '(("else" "else" c-electric-continued-statement 0)
-    ("while" "while" c-electric-continued-statement 0)))
+    ("while" "while" c-electric-continued-statement 0))
+  "Abbreviation table used in pike-mode buffers.")
 
-(defvar pike-mode-map ()
+(defvar pike-mode-map
+  (let ((map (c-make-inherited-keymap)))
+    ;; Additional bindings.
+    (define-key map "\C-c\C-e" 'c-macro-expand)
+    map)
   "Keymap used in pike-mode buffers.")
-(if pike-mode-map
-    nil
-  (setq pike-mode-map (c-make-inherited-keymap))
-  ;; additional bindings
-  (define-key pike-mode-map "\C-c\C-e" 'c-macro-expand))
 
 (easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands"
                  (cons "Pike" (c-lang-const c-mode-menu pike)))
@@ -1622,32 +1668,26 @@ Key bindings:
 ;;;###autoload (add-to-list 'interpreter-mode-alist '("nawk" . awk-mode))
 ;;;###autoload (add-to-list 'interpreter-mode-alist '("gawk" . awk-mode))
 
-;;; Autoload directives must be on the top level, so we construct an
-;;; autoload form instead.
-;;;###autoload (autoload 'awk-mode "cc-mode" "Major mode for editing AWK code." t)
-
-(defvar awk-mode-abbrev-table nil
-  "Abbreviation table used in awk-mode buffers.")
 (c-define-abbrev-table 'awk-mode-abbrev-table
   '(("else" "else" c-electric-continued-statement 0)
-    ("while" "while" c-electric-continued-statement 0)))
+    ("while" "while" c-electric-continued-statement 0))
+  "Abbreviation table used in awk-mode buffers.")
 
-(defvar awk-mode-map ()
+(defvar awk-mode-map
+  (let ((map (c-make-inherited-keymap)))
+    ;; Add bindings which are only useful for awk.
+    (define-key map "#" 'self-insert-command)
+    (define-key map "/" 'self-insert-command)
+    (define-key map "*" 'self-insert-command)
+    (define-key map "\C-c\C-n" 'undefined) ; #if doesn't exist in awk.
+    (define-key map "\C-c\C-p" 'undefined)
+    (define-key map "\C-c\C-u" 'undefined)
+    (define-key map "\M-a" 'c-beginning-of-statement) ; 2003/10/7
+    (define-key map "\M-e" 'c-end-of-statement)       ; 2003/10/7
+    (define-key map "\C-\M-a" 'c-awk-beginning-of-defun)
+    (define-key map "\C-\M-e" 'c-awk-end-of-defun)
+    map)
   "Keymap used in awk-mode buffers.")
-(if awk-mode-map
-    nil
-  (setq awk-mode-map (c-make-inherited-keymap))
-  ;; add bindings which are only useful for awk.
-  (define-key awk-mode-map "#" 'self-insert-command)
-  (define-key awk-mode-map "/" 'self-insert-command)
-  (define-key awk-mode-map "*" 'self-insert-command)
-  (define-key awk-mode-map "\C-c\C-n" 'undefined) ; #if doesn't exist in awk.
-  (define-key awk-mode-map "\C-c\C-p" 'undefined)
-  (define-key awk-mode-map "\C-c\C-u" 'undefined)
-  (define-key awk-mode-map "\M-a" 'c-beginning-of-statement) ; 2003/10/7
-  (define-key awk-mode-map "\M-e" 'c-end-of-statement) ; 2003/10/7
-  (define-key awk-mode-map "\C-\M-a" 'c-awk-beginning-of-defun)
-  (define-key awk-mode-map "\C-\M-e" 'c-awk-end-of-defun))
 
 (easy-menu-define c-awk-menu awk-mode-map "AWK Mode Commands"
                  (cons "AWK" (c-lang-const c-mode-menu awk)))
@@ -1765,6 +1805,7 @@ Key bindings:
                filladapt-mode
                defun-prompt-regexp
                font-lock-mode
+               auto-fill-mode
                font-lock-maximum-decoration
                parse-sexp-lookup-properties
                lookup-syntax-properties))
@@ -1777,4 +1818,8 @@ Key bindings:
 \f
 (cc-provide 'cc-mode)
 
+;;; Local Variables:
+;;; indent-tabs-mode: t
+;;; tab-width: 8
+;;; End:
 ;;; cc-mode.el ends here