Mercurial > emacs
comparison lisp/progmodes/cc-mode.el @ 52108:5a4fdabed57e
2003-08-03 Martin Stjernholm <bug-cc-mode@gnu.org>
* cc-mode.el (c-init-language-vars-for): Add argument MODE.
Renamed from c-init-c-language-vars'.
(c-initialize-cc-mode): Change accordingly.
(c-common-init): Ditto.
(c-mode): Ditto.
(c++-mode): Use function.
(objc-mode): Ditto.
(java-mode): Ditto.
(idl-mode): Ditto.
(pike-mode): Ditto.
(awk-mode): Ditto.
author | Martin Stjernholm <mast@lysator.liu.se> |
---|---|
date | Sun, 03 Aug 2003 12:30:34 +0000 |
parents | b4fb79bf98ba |
children | 695cf19ef79e |
comparison
equal
deleted
inserted
replaced
52107:3a5379a0d7f3 | 52108:5a4fdabed57e |
---|---|
126 ;; | 126 ;; |
127 ;; (c-initialize-cc-mode t) | 127 ;; (c-initialize-cc-mode t) |
128 ;; (c-init-language-vars some-mode) | 128 ;; (c-init-language-vars some-mode) |
129 ;; (c-common-init 'some-mode) ; Or perhaps (c-basic-common-init 'some-mode) | 129 ;; (c-common-init 'some-mode) ; Or perhaps (c-basic-common-init 'some-mode) |
130 ;; | 130 ;; |
131 ;; If you're not writing a derived mode using the language variable | |
132 ;; system, then some-mode is one of the language modes directly | |
133 ;; supported by CC Mode. You can then use (c-init-language-vars-for | |
134 ;; 'some-mode) instead of `c-init-language-vars'. | |
135 ;; `c-init-language-vars-for' is a function that avoids the rather | |
136 ;; large expansion of `c-init-language-vars'. | |
137 ;; | |
138 ;; If you use `c-basic-common-init' then you might want to call | |
139 ;; `c-font-lock-init' too to set up CC Mode's font lock support. | |
140 ;; | |
131 ;; See cc-langs.el for further info. A small example of a derived mode | 141 ;; See cc-langs.el for further info. A small example of a derived mode |
132 ;; is also available at <http://cc-mode.sourceforge.net/ | 142 ;; is also available at <http://cc-mode.sourceforge.net/ |
133 ;; derived-mode-ex.el>. | 143 ;; derived-mode-ex.el>. |
134 | 144 |
135 (defun c-leave-cc-mode-mode () | 145 (defun c-leave-cc-mode-mode () |
136 (setq c-buffer-is-cc-mode nil)) | 146 (setq c-buffer-is-cc-mode nil)) |
147 | |
148 (defun c-init-language-vars-for (mode) | |
149 "Initialize the language variables for one of the language modes | |
150 directly supported by CC Mode. This can be used instead of the | |
151 `c-init-language-vars' macro if the language you want to use is one of | |
152 those, rather than a derived language defined through the language | |
153 variable system (see \"cc-langs.el\")." | |
154 ;; This function does not do any hidden buffer changes. | |
155 (cond ((eq mode 'c-mode) (c-init-language-vars c-mode)) | |
156 ((eq mode 'c++-mode) (c-init-language-vars c++-mode)) | |
157 ((eq mode 'objc-mode) (c-init-language-vars objc-mode)) | |
158 ((eq mode 'java-mode) (c-init-language-vars java-mode)) | |
159 ((eq mode 'idl-mode) (c-init-language-vars idl-mode)) | |
160 ((eq mode 'pike-mode) (c-init-language-vars pike-mode)) | |
161 ((eq mode 'awk-mode) (c-init-language-vars awk-mode)) | |
162 (t (error "Unsupported mode %s" mode)))) | |
137 | 163 |
138 ;;;###autoload | 164 ;;;###autoload |
139 (defun c-initialize-cc-mode (&optional new-style-init) | 165 (defun c-initialize-cc-mode (&optional new-style-init) |
140 "Initialize CC Mode for use in the current buffer. | 166 "Initialize CC Mode for use in the current buffer. |
141 If the optional NEW-STYLE-INIT is nil or left out then all necessary | 167 If the optional NEW-STYLE-INIT is nil or left out then all necessary |
142 initialization to run CC Mode for the C language is done. Otherwise | 168 initialization to run CC Mode for the C language is done. Otherwise |
143 only some basic setup is done, and a call to `c-init-language-vars', | 169 only some basic setup is done, and a call to `c-init-language-vars' or |
144 is necessary too (which gives more control). See \"cc-mode.el\" for | 170 `c-init-language-vars-for' is necessary too (which gives more |
145 more info." | 171 control). See \"cc-mode.el\" for more info." |
146 ;; | 172 ;; |
147 ;; This function does not do any hidden buffer changes. | 173 ;; This function does not do any hidden buffer changes. |
148 | 174 |
149 (setq c-buffer-is-cc-mode t) | 175 (setq c-buffer-is-cc-mode t) |
150 | 176 |
163 (setq c-initialization-ok t)) | 189 (setq c-initialization-ok t)) |
164 ;; Will try initialization hooks again if they failed. | 190 ;; Will try initialization hooks again if they failed. |
165 (put 'c-initialize-cc-mode initprop c-initialization-ok)))) | 191 (put 'c-initialize-cc-mode initprop c-initialization-ok)))) |
166 | 192 |
167 (unless new-style-init | 193 (unless new-style-init |
168 (c-init-c-language-vars))) | 194 (c-init-language-vars-for 'c-mode))) |
169 | 195 |
170 | 196 |
171 ;;; Common routines. | 197 ;;; Common routines. |
172 | 198 |
173 (defvar c-mode-base-map () | 199 (defvar c-mode-base-map () |
517 This function does not do any hidden buffer changes." | 543 This function does not do any hidden buffer changes." |
518 | 544 |
519 (unless mode | 545 (unless mode |
520 ;; Called from an old third party package. The fallback is to | 546 ;; Called from an old third party package. The fallback is to |
521 ;; initialize for C. | 547 ;; initialize for C. |
522 (c-init-c-language-vars)) | 548 (c-init-language-vars-for 'c-mode)) |
523 | 549 |
524 (c-basic-common-init mode c-default-style) | 550 (c-basic-common-init mode c-default-style) |
525 (when mode | 551 (when mode |
526 ;; Only initialize font locking if we aren't called from an old package. | 552 ;; Only initialize font locking if we aren't called from an old package. |
527 (c-font-lock-init)) | 553 (c-font-lock-init)) |
613 ;; is not really suitable for those formats. Anyway, afaik there's | 639 ;; is not really suitable for those formats. Anyway, afaik there's |
614 ;; currently no better mode for them, and besides this is legacy. | 640 ;; currently no better mode for them, and besides this is legacy. |
615 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.y\\(acc\\)?\\'" . c-mode)) | 641 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.y\\(acc\\)?\\'" . c-mode)) |
616 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.lex\\'" . c-mode)) | 642 ;;;###autoload (add-to-list 'auto-mode-alist '("\\.lex\\'" . c-mode)) |
617 | 643 |
618 (defun c-init-c-language-vars () | |
619 (c-init-language-vars c-mode)) | |
620 | |
621 ;;;###autoload | 644 ;;;###autoload |
622 (defun c-mode () | 645 (defun c-mode () |
623 "Major mode for editing K&R and ANSI C code. | 646 "Major mode for editing K&R and ANSI C code. |
624 To submit a problem report, enter `\\[c-submit-bug-report]' from a | 647 To submit a problem report, enter `\\[c-submit-bug-report]' from a |
625 c-mode buffer. This automatically sets up a mail buffer with version | 648 c-mode buffer. This automatically sets up a mail buffer with version |
640 (setq major-mode 'c-mode | 663 (setq major-mode 'c-mode |
641 mode-name "C" | 664 mode-name "C" |
642 local-abbrev-table c-mode-abbrev-table | 665 local-abbrev-table c-mode-abbrev-table |
643 abbrev-mode t) | 666 abbrev-mode t) |
644 (use-local-map c-mode-map) | 667 (use-local-map c-mode-map) |
645 (c-init-c-language-vars) | 668 (c-init-language-vars-for 'c-mode) |
646 (c-common-init 'c-mode) | 669 (c-common-init 'c-mode) |
647 (easy-menu-add c-c-menu) | 670 (easy-menu-add c-c-menu) |
648 (cc-imenu-init cc-imenu-c-generic-expression) | 671 (cc-imenu-init cc-imenu-c-generic-expression) |
649 (run-hooks 'c-mode-common-hook) | 672 (run-hooks 'c-mode-common-hook) |
650 (run-hooks 'c-mode-hook) | 673 (run-hooks 'c-mode-hook) |
704 (setq major-mode 'c++-mode | 727 (setq major-mode 'c++-mode |
705 mode-name "C++" | 728 mode-name "C++" |
706 local-abbrev-table c++-mode-abbrev-table | 729 local-abbrev-table c++-mode-abbrev-table |
707 abbrev-mode t) | 730 abbrev-mode t) |
708 (use-local-map c++-mode-map) | 731 (use-local-map c++-mode-map) |
709 (c-init-language-vars c++-mode) | 732 (c-init-language-vars-for 'c++-mode) |
710 (c-common-init 'c++-mode) | 733 (c-common-init 'c++-mode) |
711 (easy-menu-add c-c++-menu) | 734 (easy-menu-add c-c++-menu) |
712 (cc-imenu-init cc-imenu-c++-generic-expression) | 735 (cc-imenu-init cc-imenu-c++-generic-expression) |
713 (run-hooks 'c-mode-common-hook) | 736 (run-hooks 'c-mode-common-hook) |
714 (run-hooks 'c++-mode-hook) | 737 (run-hooks 'c++-mode-hook) |
769 abbrev-mode t) | 792 abbrev-mode t) |
770 ;; The `c-type' text property with `c-decl-end' is used to mark the | 793 ;; The `c-type' text property with `c-decl-end' is used to mark the |
771 ;; end of the @-style directives. | 794 ;; end of the @-style directives. |
772 (setq c-type-decl-end-used t) | 795 (setq c-type-decl-end-used t) |
773 (use-local-map objc-mode-map) | 796 (use-local-map objc-mode-map) |
774 (c-init-language-vars objc-mode) | 797 (c-init-language-vars-for 'objc-mode) |
775 (c-common-init 'objc-mode) | 798 (c-common-init 'objc-mode) |
776 (easy-menu-add c-objc-menu) | 799 (easy-menu-add c-objc-menu) |
777 (cc-imenu-init nil 'cc-imenu-objc-function) | 800 (cc-imenu-init nil 'cc-imenu-objc-function) |
778 (run-hooks 'c-mode-common-hook) | 801 (run-hooks 'c-mode-common-hook) |
779 (run-hooks 'objc-mode-hook) | 802 (run-hooks 'objc-mode-hook) |
840 (setq major-mode 'java-mode | 863 (setq major-mode 'java-mode |
841 mode-name "Java" | 864 mode-name "Java" |
842 local-abbrev-table java-mode-abbrev-table | 865 local-abbrev-table java-mode-abbrev-table |
843 abbrev-mode t) | 866 abbrev-mode t) |
844 (use-local-map java-mode-map) | 867 (use-local-map java-mode-map) |
845 (c-init-language-vars java-mode) | 868 (c-init-language-vars-for 'java-mode) |
846 (c-common-init 'java-mode) | 869 (c-common-init 'java-mode) |
847 (easy-menu-add c-java-menu) | 870 (easy-menu-add c-java-menu) |
848 (cc-imenu-init cc-imenu-java-generic-expression) | 871 (cc-imenu-init cc-imenu-java-generic-expression) |
849 (run-hooks 'c-mode-common-hook) | 872 (run-hooks 'c-mode-common-hook) |
850 (run-hooks 'java-mode-hook) | 873 (run-hooks 'java-mode-hook) |
899 (set-syntax-table idl-mode-syntax-table) | 922 (set-syntax-table idl-mode-syntax-table) |
900 (setq major-mode 'idl-mode | 923 (setq major-mode 'idl-mode |
901 mode-name "IDL" | 924 mode-name "IDL" |
902 local-abbrev-table idl-mode-abbrev-table) | 925 local-abbrev-table idl-mode-abbrev-table) |
903 (use-local-map idl-mode-map) | 926 (use-local-map idl-mode-map) |
904 (c-init-language-vars idl-mode) | 927 (c-init-language-vars-for 'idl-mode) |
905 (c-common-init 'idl-mode) | 928 (c-common-init 'idl-mode) |
906 (easy-menu-add c-idl-menu) | 929 (easy-menu-add c-idl-menu) |
907 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO | 930 ;;(cc-imenu-init cc-imenu-idl-generic-expression) ;TODO |
908 (run-hooks 'c-mode-common-hook) | 931 (run-hooks 'c-mode-common-hook) |
909 (run-hooks 'idl-mode-hook) | 932 (run-hooks 'idl-mode-hook) |
962 (setq major-mode 'pike-mode | 985 (setq major-mode 'pike-mode |
963 mode-name "Pike" | 986 mode-name "Pike" |
964 local-abbrev-table pike-mode-abbrev-table | 987 local-abbrev-table pike-mode-abbrev-table |
965 abbrev-mode t) | 988 abbrev-mode t) |
966 (use-local-map pike-mode-map) | 989 (use-local-map pike-mode-map) |
967 (c-init-language-vars pike-mode) | 990 (c-init-language-vars-for 'pike-mode) |
968 (c-common-init 'pike-mode) | 991 (c-common-init 'pike-mode) |
969 (easy-menu-add c-pike-menu) | 992 (easy-menu-add c-pike-menu) |
970 ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO | 993 ;;(cc-imenu-init cc-imenu-pike-generic-expression) ;TODO |
971 (run-hooks 'c-mode-common-hook) | 994 (run-hooks 'c-mode-common-hook) |
972 (run-hooks 'pike-mode-hook) | 995 (run-hooks 'pike-mode-hook) |
1037 (setq major-mode 'awk-mode | 1060 (setq major-mode 'awk-mode |
1038 mode-name "AWK" | 1061 mode-name "AWK" |
1039 local-abbrev-table awk-mode-abbrev-table | 1062 local-abbrev-table awk-mode-abbrev-table |
1040 abbrev-mode t) | 1063 abbrev-mode t) |
1041 (use-local-map awk-mode-map) | 1064 (use-local-map awk-mode-map) |
1042 (c-init-language-vars awk-mode) | 1065 (c-init-language-vars-for 'awk-mode) |
1043 (c-common-init 'awk-mode) | 1066 (c-common-init 'awk-mode) |
1044 ;; The rest of CC Mode does not (yet) use `font-lock-syntactic-keywords', | 1067 ;; The rest of CC Mode does not (yet) use `font-lock-syntactic-keywords', |
1045 ;; so it's not set by `c-font-lock-init'. | 1068 ;; so it's not set by `c-font-lock-init'. |
1046 (make-local-variable 'font-lock-syntactic-keywords) | 1069 (make-local-variable 'font-lock-syntactic-keywords) |
1047 (setq font-lock-syntactic-keywords | 1070 (setq font-lock-syntactic-keywords |