;;; cc-mode.el --- major mode for editing C and similar languages
-;; Copyright (C) 1985, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-;; 2010 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1987, 1992-2011 Free Software Foundation, Inc.
;; Authors: 2003- Alan Mackenzie
;; 1998- Martin Stjernholm
(cc-require 'cc-cmds)
(cc-require 'cc-align)
(cc-require 'cc-menus)
+(cc-require 'cc-guess)
;; Silence the compiler.
(cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs
; '
(require 'cc-fonts) ;)
-;; cc-langs isn't loaded when we're byte compiled, so add autoload
-;; directives for the interface functions.
-(autoload 'c-make-init-lang-vars-fun "cc-langs")
-(autoload 'c-init-language-vars "cc-langs" nil nil 'macro)
-
\f
;; Other modes and packages which depend on CC Mode should do the
;; following to make sure everything is loaded and available for their
;; these variables should always be buffer local; they do not affect
;; indentation style.
- (make-local-variable 'parse-sexp-ignore-comments)
- (make-local-variable 'indent-line-function)
- (make-local-variable 'indent-region-function)
- (make-local-variable 'normal-auto-fill-function)
(make-local-variable 'comment-start)
(make-local-variable 'comment-end)
(make-local-variable 'comment-start-skip)
- (make-local-variable 'comment-multi-line)
- (make-local-variable 'comment-line-break-function)
+
(make-local-variable 'paragraph-start)
(make-local-variable 'paragraph-separate)
(make-local-variable 'paragraph-ignore-fill-prefix)
(make-local-variable 'adaptive-fill-regexp)
;; now set their values
- (setq parse-sexp-ignore-comments t
- indent-line-function 'c-indent-line
- indent-region-function 'c-indent-region
- normal-auto-fill-function 'c-do-auto-fill
- comment-multi-line t
- comment-line-break-function 'c-indent-new-comment-line)
+ (set (make-local-variable 'parse-sexp-ignore-comments) t)
+ (set (make-local-variable 'indent-line-function) 'c-indent-line)
+ (set (make-local-variable 'indent-region-function) 'c-indent-region)
+ (set (make-local-variable 'normal-auto-fill-function) 'c-do-auto-fill)
+ (set (make-local-variable 'comment-multi-line) t)
+ (set (make-local-variable 'comment-line-break-function)
+ 'c-indent-new-comment-line)
;; Install `c-fill-paragraph' on `fill-paragraph-function' so that a
;; direct call to `fill-paragraph' behaves better. This still
;; doesn't work with filladapt but it's better than nothing.
- (make-local-variable 'fill-paragraph-function)
- (setq fill-paragraph-function 'c-fill-paragraph)
+ (set (make-local-variable 'fill-paragraph-function) 'c-fill-paragraph)
;; Initialise the cache of brace pairs, and opening braces/brackets/parens.
(c-state-cache-init)
;; Emacs.
(when (boundp 'parse-sexp-lookup-properties)
- (make-local-variable 'parse-sexp-lookup-properties)
- (setq parse-sexp-lookup-properties t))
+ (set (make-local-variable 'parse-sexp-lookup-properties) t))
;; Same as above for XEmacs.
(when (boundp 'lookup-syntax-properties)
- (make-local-variable 'lookup-syntax-properties)
- (setq lookup-syntax-properties t)))
+ (set (make-local-variable 'lookup-syntax-properties) t)))
;; 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)
- (setq text-property-default-nonsticky
- (cons `(,tprop . t) text-property-default-nonsticky))))
+ (set (make-local-variable '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
(c-clear-found-types)
;; now set the mode style based on default-style
- (let ((style (if (stringp default-style)
- default-style
- (or (cdr (assq mode default-style))
- (cdr (assq 'other default-style))
- "gnu"))))
+ (let ((style (cc-choose-style-for-mode mode default-style)))
;; Override style variables if `c-old-style-variable-behavior' is
;; set. Also override if we are using global style variables,
;; have already initialized a style once, and are switching to a
(setq c-offsets-alist (copy-alist c-offsets-alist))
;; setup the comment indent variable in a Emacs version portable way
- (make-local-variable 'comment-indent-function)
- (setq comment-indent-function 'c-comment-indent)
+ (set (make-local-variable 'comment-indent-function) 'c-comment-indent)
;; ;; Put submode indicators onto minor-mode-alist, but only once.
;; (or (assq 'c-submode-indicators minor-mode-alist)
(funcall c-before-font-lock-function (point-min) (point-max)
(- (point-max) (point-min))))))
- (make-local-variable 'outline-regexp)
- (make-local-variable 'outline-level)
- (setq outline-regexp "[^#\n\^M]"
- outline-level 'c-outline-level)
+ (set (make-local-variable 'outline-regexp) "[^#\n\^M]")
+ (set (make-local-variable 'outline-level) 'c-outline-level)
(let ((rfn (assq mode c-require-final-newline)))
(when rfn
- (make-local-variable 'require-final-newline)
(and (cdr rfn)
- (setq require-final-newline mode-require-final-newline)))))
+ (set (make-local-variable 'require-final-newline)
+ mode-require-final-newline)))))
(defun c-count-cfss (lv-alist)
;; LV-ALIST is an alist like `file-local-variables-alist'. Count how many
(c-count-cfss file-local-variables-alist))
(cfs-in-dir-count (c-count-cfss dir-local-variables-alist)))
(c-set-style stile
- (= cfs-in-file-and-dir-count cfs-in-dir-count)))
+ (and (= cfs-in-file-and-dir-count cfs-in-dir-count)
+ 'keep-defaults)))
(c-set-style stile)))
(when offsets
(mapc
This does not load the font-lock package. Use after
`c-basic-common-init' and after cc-fonts has been loaded."
- (make-local-variable 'font-lock-defaults)
- (setq font-lock-defaults
+ (set (make-local-variable 'font-lock-defaults)
`(,(if (c-major-mode-is 'awk-mode)
;; awk-mode currently has only one font lock level.
'awk-font-lock-keywords
;;;###autoload
-(defun c-mode ()
+(define-derived-mode c-mode prog-mode "C"
"Major mode for editing K&R and ANSI C code.
To submit a problem report, enter `\\[c-submit-bug-report]' from a
c-mode buffer. This automatically sets up a mail buffer with version
Key bindings:
\\{c-mode-map}"
- (interactive)
- (kill-all-local-variables)
(c-initialize-cc-mode t)
(set-syntax-table c-mode-syntax-table)
- (setq major-mode 'c-mode
- mode-name "C"
- local-abbrev-table c-mode-abbrev-table
+ (setq local-abbrev-table c-mode-abbrev-table
abbrev-mode t)
(use-local-map c-mode-map)
(c-init-language-vars-for 'c-mode)
+ (c-make-macro-with-semi-re) ; matches macro names whose expansion ends with ;
(c-common-init 'c-mode)
(easy-menu-add c-c-menu)
(cc-imenu-init cc-imenu-c-generic-expression)
(cons "C++" (c-lang-const c-mode-menu c++)))
;;;###autoload
-(defun c++-mode ()
+(define-derived-mode c++-mode prog-mode "C++"
"Major mode for editing C++ code.
To submit a problem report, enter `\\[c-submit-bug-report]' from a
c++-mode buffer. This automatically sets up a mail buffer with
Key bindings:
\\{c++-mode-map}"
- (interactive)
- (kill-all-local-variables)
(c-initialize-cc-mode t)
(set-syntax-table c++-mode-syntax-table)
- (setq major-mode 'c++-mode
- mode-name "C++"
- local-abbrev-table c++-mode-abbrev-table
+ (setq local-abbrev-table c++-mode-abbrev-table
abbrev-mode t)
(use-local-map c++-mode-map)
(c-init-language-vars-for 'c++-mode)
+ (c-make-macro-with-semi-re) ; matches macro names whose expansion ends with ;
(c-common-init 'c++-mode)
(easy-menu-add c-c++-menu)
(cc-imenu-init cc-imenu-c++-generic-expression)
;;;###autoload (add-to-list 'auto-mode-alist '("\\.m\\'" . objc-mode))
;;;###autoload
-(defun objc-mode ()
+(define-derived-mode objc-mode prog-mode "ObjC"
"Major mode for editing Objective C code.
To submit a problem report, enter `\\[c-submit-bug-report]' from an
objc-mode buffer. This automatically sets up a mail buffer with
Key bindings:
\\{objc-mode-map}"
- (interactive)
- (kill-all-local-variables)
(c-initialize-cc-mode t)
(set-syntax-table objc-mode-syntax-table)
- (setq major-mode 'objc-mode
- mode-name "ObjC"
- local-abbrev-table objc-mode-abbrev-table
+ (setq local-abbrev-table objc-mode-abbrev-table
abbrev-mode t)
(use-local-map objc-mode-map)
(c-init-language-vars-for 'objc-mode)
+ (c-make-macro-with-semi-re) ; matches macro names whose expansion ends with ;
(c-common-init 'objc-mode)
(easy-menu-add c-objc-menu)
(cc-imenu-init nil 'cc-imenu-objc-function)
;;;###autoload (add-to-list 'auto-mode-alist '("\\.java\\'" . java-mode))
;;;###autoload
-(defun java-mode ()
+(define-derived-mode java-mode prog-mode "Java"
"Major mode for editing Java code.
To submit a problem report, enter `\\[c-submit-bug-report]' from a
java-mode buffer. This automatically sets up a mail buffer with
Key bindings:
\\{java-mode-map}"
- (interactive)
- (kill-all-local-variables)
(c-initialize-cc-mode t)
(set-syntax-table java-mode-syntax-table)
- (setq major-mode 'java-mode
- mode-name "Java"
- local-abbrev-table java-mode-abbrev-table
+ (setq local-abbrev-table java-mode-abbrev-table
abbrev-mode t)
(use-local-map java-mode-map)
(c-init-language-vars-for 'java-mode)
;;;###autoload (add-to-list 'auto-mode-alist '("\\.idl\\'" . idl-mode))
;;;###autoload
-(defun idl-mode ()
+(define-derived-mode idl-mode prog-mode "IDL"
"Major mode for editing CORBA's IDL, PSDL and CIDL code.
To submit a problem report, enter `\\[c-submit-bug-report]' from an
idl-mode buffer. This automatically sets up a mail buffer with
Key bindings:
\\{idl-mode-map}"
- (interactive)
- (kill-all-local-variables)
(c-initialize-cc-mode t)
(set-syntax-table idl-mode-syntax-table)
- (setq major-mode 'idl-mode
- mode-name "IDL"
- local-abbrev-table idl-mode-abbrev-table)
+ (setq local-abbrev-table idl-mode-abbrev-table)
(use-local-map idl-mode-map)
(c-init-language-vars-for 'idl-mode)
(c-common-init 'idl-mode)
;;;###autoload (add-to-list 'interpreter-mode-alist '("pike" . pike-mode))
;;;###autoload
-(defun pike-mode ()
+(define-derived-mode pike-mode prog-mode "Pike"
"Major mode for editing Pike code.
To submit a problem report, enter `\\[c-submit-bug-report]' from a
pike-mode buffer. This automatically sets up a mail buffer with
Key bindings:
\\{pike-mode-map}"
- (interactive)
- (kill-all-local-variables)
(c-initialize-cc-mode t)
(set-syntax-table pike-mode-syntax-table)
- (setq major-mode 'pike-mode
- mode-name "Pike"
- local-abbrev-table pike-mode-abbrev-table
+ (setq local-abbrev-table pike-mode-abbrev-table
abbrev-mode t)
(use-local-map pike-mode-map)
(c-init-language-vars-for 'pike-mode)
(defvar awk-mode-syntax-table)
(declare-function c-awk-unstick-NL-prop "cc-awk" ())
-(defun awk-mode ()
+;;;###autoload
+(define-derived-mode awk-mode prog-mode "AWK"
"Major mode for editing AWK code.
To submit a problem report, enter `\\[c-submit-bug-report]' from an
awk-mode buffer. This automatically sets up a mail buffer with version
Key bindings:
\\{awk-mode-map}"
- (interactive)
+ ;; We need the next line to stop the macro defining
+ ;; `awk-mode-syntax-table'. This would mask the real table which is
+ ;; declared in cc-awk.el and hasn't yet been loaded.
+ :syntax-table nil
(require 'cc-awk) ; Added 2003/6/10.
- (kill-all-local-variables)
(c-initialize-cc-mode t)
(set-syntax-table awk-mode-syntax-table)
- (setq major-mode 'awk-mode
- mode-name "AWK"
- local-abbrev-table awk-mode-abbrev-table
+ (setq local-abbrev-table awk-mode-abbrev-table
abbrev-mode t)
(use-local-map awk-mode-map)
(c-init-language-vars-for 'awk-mode)
adaptive-fill-regexp)
nil)))
(mapc (lambda (var) (unless (boundp var)
- (setq vars (delq var vars))))
+ (setq vars (delq var vars))))
'(signal-error-on-buffer-boundary
filladapt-mode
defun-prompt-regexp
\f
(cc-provide 'cc-mode)
-;; arch-tag: 7825e5c4-fd09-439f-a04d-4c13208ba3d7
;;; cc-mode.el ends here