;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to
-;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; along with this program; see the file COPYING. If not, write to
+;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
(cc-require 'cc-align)
(cc-require 'cc-menus)
-;; SILENCE the compiler.
+;; Silence the compiler.
(cc-bytecomp-defvar comment-line-break-function) ; (X)Emacs 20+
(cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs 20+
(cc-bytecomp-defun set-keymap-parents) ; XEmacs
+(cc-bytecomp-defun run-mode-hooks) ; Emacs 21.1+
+(cc-bytecomp-obsolete-fun make-local-hook) ; Marked obsolete in Emacs 21.1.
;; We set these variables during mode init, yet we don't require
;; font-lock.
;; (c-init-language-vars some-mode)
;; (c-common-init 'some-mode) ; Or perhaps (c-basic-common-init 'some-mode)
;;
+;; If you're not writing a derived mode using the language variable
+;; system, then some-mode is one of the language modes directly
+;; supported by CC Mode. You can then use (c-init-language-vars-for
+;; 'some-mode) instead of `c-init-language-vars'.
+;; `c-init-language-vars-for' is a function that avoids the rather
+;; large expansion of `c-init-language-vars'.
+;;
+;; If you use `c-basic-common-init' then you might want to call
+;; `c-font-lock-init' too to set up CC Mode's font lock support.
+;;
;; See cc-langs.el for further info. A small example of a derived mode
;; is also available at <http://cc-mode.sourceforge.net/
;; derived-mode-ex.el>.
(defun c-leave-cc-mode-mode ()
(setq c-buffer-is-cc-mode nil))
+(defun c-init-language-vars-for (mode)
+ "Initialize the language variables for one of the language modes
+directly supported by CC Mode. This can be used instead of the
+`c-init-language-vars' macro if the language you want to use is one of
+those, rather than a derived language defined through the language
+variable system (see \"cc-langs.el\")."
+ ;; This function does not do any hidden buffer changes.
+ (cond ((eq mode 'c-mode) (c-init-language-vars c-mode))
+ ((eq mode 'c++-mode) (c-init-language-vars c++-mode))
+ ((eq mode 'objc-mode) (c-init-language-vars objc-mode))
+ ((eq mode 'java-mode) (c-init-language-vars java-mode))
+ ((eq mode 'idl-mode) (c-init-language-vars idl-mode))
+ ((eq mode 'pike-mode) (c-init-language-vars pike-mode))
+ ((eq mode 'awk-mode) (c-init-language-vars awk-mode))
+ (t (error "Unsupported mode %s" mode))))
+
;;;###autoload
(defun c-initialize-cc-mode (&optional new-style-init)
"Initialize CC Mode for use in the current buffer.
If the optional NEW-STYLE-INIT is nil or left out then all necessary
initialization to run CC Mode for the C language is done. Otherwise
-only some basic setup is done, and a call to `c-init-language-vars',
-is necessary too (which gives more control). See \"cc-mode.el\" for
-more info."
+only some basic setup is done, and a call to `c-init-language-vars' or
+`c-init-language-vars-for' is necessary too (which gives more
+control). See \"cc-mode.el\" for more info."
;;
;; This function does not do any hidden buffer changes.
(put 'c-initialize-cc-mode initprop c-initialization-ok))))
(unless new-style-init
- (c-init-c-language-vars)))
+ (c-init-language-vars-for 'c-mode)))
\f
;;; Common routines.
(defun c-make-inherited-keymap ()
(let ((map (make-sparse-keymap)))
+ ;; Necessary to use `cc-bytecomp-fboundp' below since this
+ ;; function is called from top-level forms that are evaluated
+ ;; while cc-bytecomp is active when one does M-x eval-buffer.
(cond
;; XEmacs
- ((fboundp 'set-keymap-parents)
+ ((cc-bytecomp-fboundp 'set-keymap-parents)
(set-keymap-parents map c-mode-base-map))
;; Emacs
- ((fboundp 'set-keymap-parent)
+ ((cc-bytecomp-fboundp 'set-keymap-parent)
(set-keymap-parent map c-mode-base-map))
;; incompatible
(t (error "CC Mode is incompatible with this version of Emacs")))
;; Install the functions that ensure that various internal caches
;; don't become invalid due to buffer changes.
- (make-local-hook 'after-change-functions)
(add-hook 'after-change-functions 'c-after-change nil t))
(defun c-after-font-lock-init ()
c-beginning-of-syntax
(font-lock-mark-block-function
. c-mark-function)))
-
- (make-local-hook 'font-lock-mode-hook)
(add-hook 'font-lock-mode-hook 'c-after-font-lock-init nil t))
(defun c-setup-doc-comment-style ()
(unless mode
;; Called from an old third party package. The fallback is to
;; initialize for C.
- (c-init-c-language-vars))
+ (c-init-language-vars-for 'c-mode))
(c-basic-common-init mode c-default-style)
(when mode
(let ((rfn (assq mode c-require-final-newline)))
(when rfn
(make-local-variable 'require-final-newline)
- (setq require-final-newline (cdr rfn)))))
+ (and (cdr rfn)
+ (setq require-final-newline mode-require-final-newline)))))
(defun c-postprocess-file-styles ()
"Function that post processes relevant file local variables in CC Mode.
(add-hook 'hack-local-variables-hook 'c-postprocess-file-styles)
+(defmacro c-run-mode-hooks (&rest hooks)
+ ;; Emacs 21.1 has introduced a system with delayed mode hooks that
+ ;; require the use of the new function `run-mode-hooks'.
+ (if (cc-bytecomp-fboundp 'run-mode-hooks)
+ `(run-mode-hooks ,@hooks)
+ `(progn ,@(mapcar (lambda (hook) `(run-hooks ,hook)) hooks))))
+
\f
;; Support for C
;;;###autoload (add-to-list 'auto-mode-alist '("\\.y\\(acc\\)?\\'" . c-mode))
;;;###autoload (add-to-list 'auto-mode-alist '("\\.lex\\'" . c-mode))
-(defun c-init-c-language-vars ()
- (c-init-language-vars c-mode))
-
;;;###autoload
(defun c-mode ()
"Major mode for editing K&R and ANSI C code.
local-abbrev-table c-mode-abbrev-table
abbrev-mode t)
(use-local-map c-mode-map)
- (c-init-c-language-vars)
+ (c-init-language-vars-for 'c-mode)
(c-common-init 'c-mode)
(easy-menu-add c-c-menu)
(cc-imenu-init cc-imenu-c-generic-expression)
- (run-hooks 'c-mode-common-hook)
- (run-hooks 'c-mode-hook)
+ (c-run-mode-hooks 'c-mode-common-hook 'c-mode-hook)
(c-update-modeline))
\f
local-abbrev-table c++-mode-abbrev-table
abbrev-mode t)
(use-local-map c++-mode-map)
- (c-init-language-vars c++-mode)
+ (c-init-language-vars-for 'c++-mode)
(c-common-init 'c++-mode)
(easy-menu-add c-c++-menu)
(cc-imenu-init cc-imenu-c++-generic-expression)
- (run-hooks 'c-mode-common-hook)
- (run-hooks 'c++-mode-hook)
+ (c-run-mode-hooks 'c-mode-common-hook 'c++-mode-hook)
(c-update-modeline))
\f
;; end of the @-style directives.
(setq c-type-decl-end-used t)
(use-local-map objc-mode-map)
- (c-init-language-vars objc-mode)
+ (c-init-language-vars-for 'objc-mode)
(c-common-init 'objc-mode)
(easy-menu-add c-objc-menu)
(cc-imenu-init nil 'cc-imenu-objc-function)
- (run-hooks 'c-mode-common-hook)
- (run-hooks 'objc-mode-hook)
+ (c-run-mode-hooks 'c-mode-common-hook 'objc-mode-hook)
(c-update-modeline))
\f
local-abbrev-table java-mode-abbrev-table
abbrev-mode t)
(use-local-map java-mode-map)
- (c-init-language-vars java-mode)
+ (c-init-language-vars-for 'java-mode)
(c-common-init 'java-mode)
(easy-menu-add c-java-menu)
(cc-imenu-init cc-imenu-java-generic-expression)
- (run-hooks 'c-mode-common-hook)
- (run-hooks 'java-mode-hook)
+ (c-run-mode-hooks 'c-mode-common-hook 'java-mode-hook)
(c-update-modeline))
\f
mode-name "IDL"
local-abbrev-table idl-mode-abbrev-table)
(use-local-map idl-mode-map)
- (c-init-language-vars idl-mode)
+ (c-init-language-vars-for 'idl-mode)
(c-common-init 'idl-mode)
(easy-menu-add c-idl-menu)
;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO
- (run-hooks 'c-mode-common-hook)
- (run-hooks 'idl-mode-hook)
+ (c-run-mode-hooks 'c-mode-common-hook 'idl-mode-hook)
(c-update-modeline))
\f
local-abbrev-table pike-mode-abbrev-table
abbrev-mode t)
(use-local-map pike-mode-map)
- (c-init-language-vars pike-mode)
+ (c-init-language-vars-for 'pike-mode)
(c-common-init 'pike-mode)
(easy-menu-add c-pike-menu)
;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO
- (run-hooks 'c-mode-common-hook)
- (run-hooks 'pike-mode-hook)
+ (c-run-mode-hooks 'c-mode-common-hook 'pike-mode-hook)
(c-update-modeline))
\f
;;; 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.")
+;;;###autoload (autoload 'awk-mode "cc-mode" "Major mode for editing AWK code." t)
(if (not (memq 'syntax-properties c-emacs-features))
(autoload 'awk-mode "awk-mode" "Major mode for editing AWK code." t)
local-abbrev-table awk-mode-abbrev-table
abbrev-mode t)
(use-local-map awk-mode-map)
- (c-init-language-vars awk-mode)
+ (c-init-language-vars-for 'awk-mode)
(c-common-init 'awk-mode)
;; The rest of CC Mode does not (yet) use `font-lock-syntactic-keywords',
;; so it's not set by `c-font-lock-init'.
;; in cc-engine.el, just before (defun c-fast-in-literal ...
(defalias 'c-in-literal 'c-slow-in-literal)
- (run-hooks 'c-mode-common-hook)
- (run-hooks 'awk-mode-hook)
+ (c-run-mode-hooks 'c-mode-common-hook 'awk-mode-hook)
(c-update-modeline))
) ;; closes the (if (not (memq 'syntax-properties c-emacs-features))
\f
(cc-provide 'cc-mode)
+
+;;; arch-tag: 7825e5c4-fd09-439f-a04d-4c13208ba3d7
;;; cc-mode.el ends here