Mercurial > hg > xemacs-beta
comparison lisp/modes/cc-mode.el @ 4:b82b59fe008d r19-15b3
Import from CVS: tag r19-15b3
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:46:56 +0200 |
parents | ac2d302a0011 |
children | 27bc7f280385 |
comparison
equal
deleted
inserted
replaced
3:30df88044ec6 | 4:b82b59fe008d |
---|---|
4 | 4 |
5 ;; Authors: 1992-1996 Barry A. Warsaw | 5 ;; Authors: 1992-1996 Barry A. Warsaw |
6 ;; 1987 Dave Detlefs and Stewart Clamen | 6 ;; 1987 Dave Detlefs and Stewart Clamen |
7 ;; 1985 Richard M. Stallman | 7 ;; 1985 Richard M. Stallman |
8 ;; Created: a long, long, time ago. adapted from the original c-mode.el | 8 ;; Created: a long, long, time ago. adapted from the original c-mode.el |
9 ;; Version: 4.315 | 9 ;; Version: 4.322 |
10 ;; Last Modified: 1996/08/20 21:08:13 | 10 ;; Last Modified: 1996/10/04 20:28:14 |
11 ;; Keywords: c languages oop | 11 ;; Keywords: c languages oop |
12 | 12 |
13 ;; NOTE: Read the commentary below for the right way to submit bug reports! | 13 ;; NOTE: Read the commentary below for the right way to submit bug reports! |
14 ;; NOTE: See the accompanying texinfo manual for details on using this mode! | 14 ;; NOTE: See the accompanying texinfo manual for details on using this mode! |
15 | 15 |
531 (access-label . -3) | 531 (access-label . -3) |
532 (inclass . 6) | 532 (inclass . 6) |
533 (inline-open . 0) | 533 (inline-open . 0) |
534 )) | 534 )) |
535 ) | 535 ) |
536 ("linux" | |
537 (c-basic-offset . 8) | |
538 (c-comment-only-line-offset . 0) | |
539 (c-hanging-braces-alist . ((brace-list-open) | |
540 (substatement-open after) | |
541 (block-close . c-snug-do-while))) | |
542 (c-cleanup-list . (brace-else-brace)) | |
543 (c-offsets-alist . ((statement-block-intro . +) | |
544 (knr-argdecl-intro . 0) | |
545 (substatement-open . 0) | |
546 (label . 0) | |
547 (statement-cont . +) | |
548 )) | |
549 ) | |
536 ("java" | 550 ("java" |
537 (c-basic-offset . 2) | 551 (c-basic-offset . 2) |
538 (c-comment-only-line-offset . (0 . 0)) | 552 (c-comment-only-line-offset . (0 . 0)) |
539 (c-offsets-alist . ((statement-block-intro . +) | 553 (c-offsets-alist . ((statement-block-intro . +) |
540 (knr-argdecl-intro . 5) | 554 (knr-argdecl-intro . 5) |
621 ["Backward Conditional" c-backward-conditional t] | 635 ["Backward Conditional" c-backward-conditional t] |
622 ["Forward Conditional" c-forward-conditional t] | 636 ["Forward Conditional" c-forward-conditional t] |
623 ["Backward Statement" c-beginning-of-statement t] | 637 ["Backward Statement" c-beginning-of-statement t] |
624 ["Forward Statement" c-end-of-statement t] | 638 ["Forward Statement" c-end-of-statement t] |
625 ) | 639 ) |
626 "XEmacs 19 menu for C/C++/ObjC modes.") | 640 "XEmacs 19 menu for C/C++/ObjC/Java modes.") |
627 | 641 |
628 ;; Sadly we need this for a macro in Emacs 19. | 642 ;; Sadly we need this for a macro in Emacs 19. |
629 (eval-when-compile | 643 (eval-when-compile |
630 ;; Imenu isn't used in XEmacs, so just ignore load errors. | 644 ;; Imenu isn't used in XEmacs, so just ignore load errors. |
631 (condition-case () | 645 (condition-case () |
849 (define-key map [menu-bar c backward-stmt] | 863 (define-key map [menu-bar c backward-stmt] |
850 '("Backward Statement" . c-beginning-of-statement)) | 864 '("Backward Statement" . c-beginning-of-statement)) |
851 (define-key map [menu-bar c forward-stmt] | 865 (define-key map [menu-bar c forward-stmt] |
852 '("Forward Statement" . c-end-of-statement)) | 866 '("Forward Statement" . c-end-of-statement)) |
853 | 867 |
854 ;; RMS: mouse-3 should not select this menu. mouse-3's global | 868 ;; RMS says: mouse-3 should not select this menu. mouse-3's |
855 ;; definition is useful in C mode and we should not interfere | 869 ;; global definition is useful in C mode and we should not |
856 ;; with that. The menu is mainly for beginners, and for them, | 870 ;; interfere with that. The menu is mainly for beginners, and |
857 ;; the menubar requires less memory than a special click. | 871 ;; for them, the menubar requires less memory than a special |
872 ;; click. | |
858 t) | 873 t) |
859 (error nil))) | 874 (error nil))) |
860 | 875 |
861 (defvar c-mode-map () | 876 (defvar c-mode-map () |
862 "Keymap used in c-mode buffers.") | 877 "Keymap used in c-mode buffers.") |
908 ;; conflicts with OOBR | 923 ;; conflicts with OOBR |
909 ;;(define-key c-mode-map "\C-c\C-v" 'c-version) | 924 ;;(define-key c-mode-map "\C-c\C-v" 'c-version) |
910 ;; | 925 ;; |
911 ;; Emacs 19 defines menus in the mode map. This call will return | 926 ;; Emacs 19 defines menus in the mode map. This call will return |
912 ;; t on Emacs 19, otherwise no-op and return nil. | 927 ;; t on Emacs 19, otherwise no-op and return nil. |
913 (if (and (not (c-mode-fsf-menu "C" c-mode-map)) | 928 (if (and (not (c-mode-fsf-menu "CC-Mode" c-mode-map)) |
914 ;; in XEmacs 19, we want the menu to popup when the 3rd | 929 ;; in XEmacs 19, we want the menu to popup when the 3rd |
915 ;; button is hit. In Lucid Emacs 19.10 and beyond this is | 930 ;; button is hit. In Lucid Emacs 19.10 and beyond this is |
916 ;; done automatically if we put the menu on mode-popup-menu | 931 ;; done automatically if we put the menu on mode-popup-menu |
917 ;; variable, see c-common-init. Emacs 19 uses C-Mouse-3 for | 932 ;; variable, see c-common-init. Emacs 19 uses C-Mouse-3 for |
918 ;; this, and it works with no special effort. | 933 ;; this, and it works with no special effort. |
945 (define-key c++-mode-map "/" 'c-electric-slash) | 960 (define-key c++-mode-map "/" 'c-electric-slash) |
946 (define-key c++-mode-map "<" 'c-electric-lt-gt) | 961 (define-key c++-mode-map "<" 'c-electric-lt-gt) |
947 (define-key c++-mode-map ">" 'c-electric-lt-gt) | 962 (define-key c++-mode-map ">" 'c-electric-lt-gt) |
948 ;; Emacs 19 defines menus in the mode map. This call will return | 963 ;; Emacs 19 defines menus in the mode map. This call will return |
949 ;; t on Emacs 19, otherwise no-op and return nil. | 964 ;; t on Emacs 19, otherwise no-op and return nil. |
950 (c-mode-fsf-menu "C++" c++-mode-map)) | 965 ; (c-mode-fsf-menu "C++" c++-mode-map) |
966 ) | |
951 | 967 |
952 (defvar objc-mode-map () | 968 (defvar objc-mode-map () |
953 "Keymap used in objc-mode buffers.") | 969 "Keymap used in objc-mode buffers.") |
954 (if objc-mode-map | 970 (if objc-mode-map |
955 () | 971 () |
969 (setq objc-mode-map (nconc (make-sparse-keymap) c-mode-map))) | 985 (setq objc-mode-map (nconc (make-sparse-keymap) c-mode-map))) |
970 ;; add bindings which are only useful for Objective-C | 986 ;; add bindings which are only useful for Objective-C |
971 (define-key objc-mode-map "/" 'c-electric-slash) | 987 (define-key objc-mode-map "/" 'c-electric-slash) |
972 ;; Emacs 19 defines menus in the mode map. This call will return | 988 ;; Emacs 19 defines menus in the mode map. This call will return |
973 ;; t on Emacs 19, otherwise no-op and return nil. | 989 ;; t on Emacs 19, otherwise no-op and return nil. |
974 (c-mode-fsf-menu "ObjC" objc-mode-map)) | 990 ; (c-mode-fsf-menu "ObjC" objc-mode-map) |
991 ) | |
975 | 992 |
976 (defvar java-mode-map () | 993 (defvar java-mode-map () |
977 "Keymap used in java-mode buffers.") | 994 "Keymap used in java-mode buffers.") |
978 (if java-mode-map | 995 (if java-mode-map |
979 () | 996 () |
994 (setq java-mode-map (nconc (make-sparse-keymap) c-mode-map))) | 1011 (setq java-mode-map (nconc (make-sparse-keymap) c-mode-map))) |
995 ;; add bindings which are only useful for Java | 1012 ;; add bindings which are only useful for Java |
996 (define-key java-mode-map "/" 'c-electric-slash) | 1013 (define-key java-mode-map "/" 'c-electric-slash) |
997 ;; Emacs 19 defines menus in the mode map. This call will return t | 1014 ;; Emacs 19 defines menus in the mode map. This call will return t |
998 ;; on Emacs 19, otherwise no-op and return nil. | 1015 ;; on Emacs 19, otherwise no-op and return nil. |
999 (c-mode-fsf-menu "Java" java-mode-map)) | 1016 ; (c-mode-fsf-menu "Java" java-mode-map) |
1017 ) | |
1000 | 1018 |
1001 (defun c-populate-syntax-table (table) | 1019 (defun c-populate-syntax-table (table) |
1002 ;; Populate the syntax TABLE | 1020 ;; Populate the syntax TABLE |
1003 ;; DO NOT TRY TO SET _ (UNDERSCORE) TO WORD CLASS! | 1021 ;; DO NOT TRY TO SET _ (UNDERSCORE) TO WORD CLASS! |
1004 (modify-syntax-entry ?_ "_" table) | 1022 (modify-syntax-entry ?_ "_" table) |
1137 ;; style variables are made buffer local at tail end of this file. | 1155 ;; style variables are made buffer local at tail end of this file. |
1138 | 1156 |
1139 ;; cmacexp is lame because it uses no preprocessor symbols. | 1157 ;; cmacexp is lame because it uses no preprocessor symbols. |
1140 ;; It isn't very extensible either -- hardcodes /lib/cpp. | 1158 ;; It isn't very extensible either -- hardcodes /lib/cpp. |
1141 ;; [I add it here only because c-mode has it -- BAW] | 1159 ;; [I add it here only because c-mode has it -- BAW] |
1142 ;;(autoload 'c-macro-expand "cmacexp" | 1160 ;(autoload 'c-macro-expand "cmacexp" |
1143 ;; "Display the result of expanding all C macros occurring in the region. | 1161 ; "Display the result of expanding all C macros occurring in the region. |
1144 ;;The expansion is entirely correct because it uses the C preprocessor." | 1162 ;The expansion is entirely correct because it uses the C preprocessor." |
1145 ;; t) | 1163 ; t) |
1146 | 1164 |
1147 | 1165 |
1148 ;; constant regular expressions for looking at various constructs | 1166 ;; constant regular expressions for looking at various constructs |
1149 (defconst c-C++-class-key "\\(class\\|struct\\|union\\)" | 1167 (defconst c-C++-class-key "\\(class\\|struct\\|union\\)" |
1150 "Regexp describing a C++ class declaration, including templates.") | 1168 "Regexp describing a C++ class declaration, including templates.") |
2357 (if s | 2375 (if s |
2358 (setcdr s (copy-alist descrip)) ; replace | 2376 (setcdr s (copy-alist descrip)) ; replace |
2359 (setq c-style-alist (cons (cons style descrip) c-style-alist)))) | 2377 (setq c-style-alist (cons (cons style descrip) c-style-alist)))) |
2360 (and set-p (c-set-style style))) | 2378 (and set-p (c-set-style style))) |
2361 | 2379 |
2380 | |
2362 (defun c-fill-paragraph (&optional arg) | 2381 (defun c-fill-paragraph (&optional arg) |
2363 "Like \\[fill-paragraph] but handles C and C++ style comments. | 2382 "Like \\[fill-paragraph] but handles C and C++ style comments. |
2364 If any of the current line is a comment or within a comment, | 2383 If any of the current line is a comment or within a comment, |
2365 fill the comment or the paragraph of it that point is in, | 2384 fill the comment or the paragraph of it that point is in, |
2366 preserving the comment indentation or line-starting decorations. | 2385 preserving the comment indentation or line-starting decorations. |
2863 (c-keep-region-active)) | 2882 (c-keep-region-active)) |
2864 | 2883 |
2865 | 2884 |
2866 ;; commands to indent lines, regions, defuns, and expressions | 2885 ;; commands to indent lines, regions, defuns, and expressions |
2867 (defun c-indent-command (&optional whole-exp) | 2886 (defun c-indent-command (&optional whole-exp) |
2868 "Indent current line as C++ code, or in some cases insert a tab character. | 2887 "Indent current line as C code, and/or insert some whitespace. |
2869 | 2888 |
2870 If `c-tab-always-indent' is t, always just indent the current line. | 2889 If `c-tab-always-indent' is t, always just indent the current line. |
2871 If nil, indent the current line only if point is at the left margin or | 2890 If nil, indent the current line only if point is at the left margin or |
2872 in the line's indentation; otherwise insert a tab. If other than nil | 2891 in the line's indentation; otherwise insert some whitespace[*]. If |
2873 or t, then tab is inserted only within literals (comments and strings) | 2892 other than nil or t, then some whitespace[*] is inserted only within |
2874 and inside preprocessor directives, but line is always reindented. | 2893 literals (comments and strings) and inside preprocessor directives, |
2894 but the line is always reindented. | |
2875 | 2895 |
2876 A numeric argument, regardless of its value, means indent rigidly all | 2896 A numeric argument, regardless of its value, means indent rigidly all |
2877 the lines of the expression starting after point so that this line | 2897 the lines of the expression starting after point so that this line |
2878 becomes properly indented. The relative indentation among the lines | 2898 becomes properly indented. The relative indentation among the lines |
2879 of the expression are preserved." | 2899 of the expression are preserved. |
2900 | |
2901 [*] The amount and kind of whitespace inserted is controlled by the | |
2902 variable `c-insert-tab-function', which is called to do the actual | |
2903 insertion of whitespace. Normally the function in this variable | |
2904 just inserts a tab character, or the equivalent number of spaces, | |
2905 depending on the variable `indent-tabs-mode'." | |
2906 | |
2880 (interactive "P") | 2907 (interactive "P") |
2881 (let ((bod (c-point 'bod))) | 2908 (let ((bod (c-point 'bod))) |
2882 (if whole-exp | 2909 (if whole-exp |
2883 ;; If arg, always indent this line as C | 2910 ;; If arg, always indent this line as C |
2884 ;; and shift remaining lines of expression the same amount. | 2911 ;; and shift remaining lines of expression the same amount. |
4909 (defun c-backslash-region (from to delete-flag) | 4936 (defun c-backslash-region (from to delete-flag) |
4910 "Insert, align, or delete end-of-line backslashes on the lines in the region. | 4937 "Insert, align, or delete end-of-line backslashes on the lines in the region. |
4911 With no argument, inserts backslashes and aligns existing backslashes. | 4938 With no argument, inserts backslashes and aligns existing backslashes. |
4912 With an argument, deletes the backslashes. | 4939 With an argument, deletes the backslashes. |
4913 | 4940 |
4914 This function does not modify the last line of the region if the region ends | 4941 This function does not modify blank lines at the start of the region. |
4915 right at the start of the following line; it does not modify blank lines | 4942 If the region ends at the start of a line, it always deletes the |
4916 at the start of the region. So you can put the region around an entire macro | 4943 backslash (if any) at the end of the previous line. |
4917 definition and conveniently use this command." | 4944 |
4945 You can put the region around an entire macro definition and use this | |
4946 command to conveniently insert and align the necessary backslashes." | |
4918 (interactive "r\nP") | 4947 (interactive "r\nP") |
4919 (save-excursion | 4948 (save-excursion |
4920 (goto-char from) | 4949 (goto-char from) |
4921 (let ((column c-backslash-column) | 4950 (let ((column c-backslash-column) |
4922 (endmark (make-marker))) | 4951 (endmark (make-marker))) |
4938 ;; Don't modify blank lines at start of region. | 4967 ;; Don't modify blank lines at start of region. |
4939 (goto-char from) | 4968 (goto-char from) |
4940 (while (and (< (point) endmark) (eolp)) | 4969 (while (and (< (point) endmark) (eolp)) |
4941 (forward-line 1)) | 4970 (forward-line 1)) |
4942 ;; Add or remove backslashes on all the lines. | 4971 ;; Add or remove backslashes on all the lines. |
4943 (while (and (< (point) endmark) | 4972 (while (< (point) endmark) |
4944 ;; Don't backslashify the last line | 4973 (if (and (not delete-flag) |
4945 ;; if the region ends right at the start of the next line. | 4974 ;; Un-backslashify the last line |
4946 (save-excursion | 4975 ;; if the region ends right at the start of the next line. |
4947 (forward-line 1) | 4976 (save-excursion |
4948 (< (point) endmark))) | 4977 (forward-line 1) |
4949 (if (not delete-flag) | 4978 (< (point) endmark))) |
4950 (c-append-backslash column) | 4979 (c-append-backslash column) |
4951 (c-delete-backslash)) | 4980 (c-delete-backslash)) |
4952 (forward-line 1)) | 4981 (forward-line 1)) |
4953 (move-marker endmark nil)))) | 4982 (move-marker endmark nil))) |
4983 (c-keep-region-active)) | |
4954 | 4984 |
4955 (defun c-append-backslash (column) | 4985 (defun c-append-backslash (column) |
4956 (end-of-line) | 4986 (end-of-line) |
4957 ;; Note that "\\\\" is needed to get one backslash. | 4987 ;; Note that "\\\\" is needed to get one backslash. |
4958 (if (= (preceding-char) ?\\) | 4988 (if (= (preceding-char) ?\\) |
4972 (progn (skip-chars-backward " \t") (point))))))) | 5002 (progn (skip-chars-backward " \t") (point))))))) |
4973 | 5003 |
4974 | 5004 |
4975 ;; defuns for submitting bug reports | 5005 ;; defuns for submitting bug reports |
4976 | 5006 |
4977 (defconst c-version "4.315" | 5007 (defconst c-version "4.322" |
4978 "cc-mode version number.") | 5008 "cc-mode version number.") |
4979 (defconst c-mode-help-address | 5009 (defconst c-mode-help-address |
4980 "bug-gnu-emacs@prep.ai.mit.edu, cc-mode-help@python.org" | 5010 "bug-gnu-emacs@prep.ai.mit.edu, cc-mode-help@python.org" |
4981 "Address for cc-mode bug reports.") | 5011 "Address for cc-mode bug reports.") |
4982 | 5012 |
5108 '(c-backslash-column | 5138 '(c-backslash-column |
5109 c-basic-offset | 5139 c-basic-offset |
5110 c-block-comments-indent-p | 5140 c-block-comments-indent-p |
5111 c-cleanup-list | 5141 c-cleanup-list |
5112 c-comment-only-line-offset | 5142 c-comment-only-line-offset |
5113 c-echo-syntactic-information-p | |
5114 c-electric-pound-behavior | 5143 c-electric-pound-behavior |
5115 c-hanging-braces-alist | 5144 c-hanging-braces-alist |
5116 c-hanging-colons-alist | 5145 c-hanging-colons-alist |
5117 c-hanging-comment-ender-p | 5146 c-hanging-comment-ender-p |
5118 c-offsets-alist | 5147 c-offsets-alist |
5119 c-strict-syntax-p | |
5120 c-tab-always-indent | |
5121 c-inhibit-startup-warnings-p | |
5122 ))) | 5148 ))) |
5123 ;; the default style is now GNU. This can be overridden in | 5149 ;; the default style is now GNU. This can be overridden in |
5124 ;; c-mode-common-hook or {c,c++,objc,java}-mode-hook. | 5150 ;; c-mode-common-hook or {c,c++,objc,java}-mode-hook. |
5125 (c-set-style c-site-default-style))) | 5151 (c-set-style c-site-default-style))) |
5126 | 5152 |
5145 (fset 'electric-c-semi 'c-electric-semi&comma) | 5171 (fset 'electric-c-semi 'c-electric-semi&comma) |
5146 (fset 'electric-c-sharp-sign 'c-electric-pound) | 5172 (fset 'electric-c-sharp-sign 'c-electric-pound) |
5147 ;; there is no cc-mode equivalent for electric-c-terminator | 5173 ;; there is no cc-mode equivalent for electric-c-terminator |
5148 (fset 'mark-c-function 'c-mark-function) | 5174 (fset 'mark-c-function 'c-mark-function) |
5149 (fset 'indent-c-exp 'c-indent-exp) | 5175 (fset 'indent-c-exp 'c-indent-exp) |
5150 (fset 'set-c-style 'c-set-style) | 5176 ;;;###autoload (fset 'set-c-style 'c-set-style) |
5151 ;; Lucid Emacs 19.9 + font-lock + cc-mode - c++-mode lossage | 5177 ;; Lucid Emacs 19.9 + font-lock + cc-mode - c++-mode lossage |
5152 (fset 'c++-beginning-of-defun 'beginning-of-defun) | 5178 (fset 'c++-beginning-of-defun 'beginning-of-defun) |
5153 (fset 'c++-end-of-defun 'end-of-defun) | 5179 (fset 'c++-end-of-defun 'end-of-defun) |
5154 | 5180 |
5155 ;; set up bc warnings for obsolete variables, but for now lets not | 5181 ;; set up bc warnings for obsolete variables, but for now lets not |