Mercurial > emacs
annotate lisp/progmodes/cc-compat.el @ 49109:39d762048cdd
(unforward-rmail-message): Simplified. No functional change.
author | Francesco Potortì <pot@gnu.org> |
---|---|
date | Wed, 08 Jan 2003 09:11:23 +0000 |
parents | 7a3ac6c387fe |
children | 0d8b17d428b5 |
rev | line source |
---|---|
18720 | 1 ;;; cc-compat.el --- cc-mode compatibility with c-mode.el confusion |
2 | |
36920 | 3 ;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc. |
18720 | 4 |
30405 | 5 ;; Authors: 2000- Martin Stjernholm |
6 ;; 1998-1999 Barry A. Warsaw and Martin Stjernholm | |
7 ;; 1994-1997 Barry A. Warsaw | |
8 ;; Maintainer: bug-cc-mode@gnu.org | |
18720 | 9 ;; Created: August 1994, split from cc-mode.el |
20141 | 10 ;; Version: See cc-mode.el |
18720 | 11 ;; Keywords: c languages oop |
12 | |
13 ;; This file is part of GNU Emacs. | |
14 | |
15 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
16 ;; it under the terms of the GNU General Public License as published by | |
17 ;; the Free Software Foundation; either version 2, or (at your option) | |
18 ;; any later version. | |
19 | |
20 ;; GNU Emacs is distributed in the hope that it will be useful, | |
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 ;; GNU General Public License for more details. | |
24 | |
25 ;; You should have received a copy of the GNU General Public License | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
36920
diff
changeset
|
26 ;; along with GNU Emacs; see the file COPYING. If not, write to |
36920 | 27 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18720 | 28 ;; Boston, MA 02111-1307, USA. |
29 | |
30 ;;; Commentary: | |
31 ;; | |
32 ;; Boring old c-mode.el (BOCM) is confusion and brain melt. cc-mode.el | |
33 ;; is clarity of thought and purity of chi. If you are still unwilling | |
34 ;; to accept enlightenment, this might help, or it may prolong your | |
35 ;; agony. | |
36 ;; | |
37 ;; To use, add the following to your c-mode-hook: | |
38 ;; | |
39 ;; (require 'cc-compat) | |
40 ;; (c-set-style "BOCM") | |
36920 | 41 ;; |
42 ;; This file is completely unsupported! Although it has been patched | |
43 ;; superficially to keep pace with the rest of CC Mode, it hasn't been | |
44 ;; tested for a long time. | |
18720 | 45 |
46 ;;; Code: | |
47 | |
48 (eval-when-compile | |
26817 | 49 (let ((load-path |
36920 | 50 (if (and (boundp 'byte-compile-dest-file) |
51 (stringp byte-compile-dest-file)) | |
52 (cons (file-name-directory byte-compile-dest-file) load-path) | |
26817 | 53 load-path))) |
36920 | 54 (require 'cc-bytecomp))) |
55 | |
56 (cc-require 'cc-defs) | |
57 (cc-require 'cc-vars) | |
58 (cc-require 'cc-styles) | |
59 (cc-require 'cc-engine) | |
18720 | 60 |
61 | |
62 ;; In case c-mode.el isn't loaded | |
63 (defvar c-indent-level 2 | |
64 "*Indentation of C statements with respect to containing block.") | |
65 (defvar c-brace-imaginary-offset 0 | |
66 "*Imagined indentation of a C open brace that actually follows a statement.") | |
67 (defvar c-brace-offset 0 | |
68 "*Extra indentation for braces, compared with other text in same context.") | |
69 (defvar c-argdecl-indent 5 | |
70 "*Indentation level of declarations of C function arguments.") | |
71 (defvar c-label-offset -2 | |
72 "*Offset of C label lines and case statements relative to usual indentation.") | |
73 (defvar c-continued-statement-offset 2 | |
74 "*Extra indent for lines not starting new statements.") | |
75 (defvar c-continued-brace-offset 0 | |
76 "*Extra indent for substatements that start with open-braces. | |
77 This is in addition to c-continued-statement-offset.") | |
78 | |
79 | |
80 | |
81 ;; these offsets are taken by brute force testing c-mode.el, since | |
82 ;; there's no logic to what it does. | |
83 (let* ((offsets '(c-offsets-alist . | |
84 ((defun-block-intro . cc-block-intro-offset) | |
85 (statement-block-intro . cc-block-intro-offset) | |
86 (defun-open . 0) | |
87 (class-open . 0) | |
88 (inline-open . c-brace-offset) | |
89 (block-open . c-brace-offset) | |
90 (block-close . cc-block-close-offset) | |
91 (brace-list-open . c-brace-offset) | |
92 (substatement-open . cc-substatement-open-offset) | |
93 (substatement . c-continued-statement-offset) | |
94 (knr-argdecl-intro . c-argdecl-indent) | |
95 (case-label . c-label-offset) | |
96 (access-label . c-label-offset) | |
97 (label . c-label-offset) | |
98 )))) | |
99 (c-add-style "BOCM" offsets)) | |
100 | |
101 | |
102 (defun cc-block-intro-offset (langelem) | |
103 ;; taken directly from calculate-c-indent confusion | |
104 (save-excursion | |
105 (c-backward-syntactic-ws) | |
106 (if (eq (char-before) ?{) | |
107 (forward-char -1) | |
108 (goto-char (cdr langelem))) | |
109 (let* ((curcol (save-excursion | |
110 (goto-char (cdr langelem)) | |
111 (current-column))) | |
112 (bocm-lossage | |
113 ;; If no previous statement, indent it relative to line | |
114 ;; brace is on. For open brace in column zero, don't let | |
115 ;; statement start there too. If c-indent-level is zero, | |
116 ;; use c-brace-offset + c-continued-statement-offset | |
117 ;; instead. For open-braces not the first thing in a line, | |
118 ;; add in c-brace-imaginary-offset. | |
119 (+ (if (and (bolp) (zerop c-indent-level)) | |
120 (+ c-brace-offset c-continued-statement-offset) | |
121 c-indent-level) | |
122 ;; Move back over whitespace before the openbrace. If | |
123 ;; openbrace is not first nonwhite thing on the line, | |
124 ;; add the c-brace-imaginary-offset. | |
125 (progn (skip-chars-backward " \t") | |
126 (if (bolp) 0 c-brace-imaginary-offset)) | |
127 ;; If the openbrace is preceded by a parenthesized exp, | |
128 ;; move to the beginning of that; possibly a different | |
129 ;; line | |
130 (progn | |
131 (if (eq (char-before) ?\)) | |
24282 | 132 (c-forward-sexp -1)) |
18720 | 133 ;; Get initial indentation of the line we are on. |
134 (current-indentation))))) | |
135 (- bocm-lossage curcol)))) | |
136 | |
137 | |
138 (defun cc-block-close-offset (langelem) | |
139 (save-excursion | |
140 (let* ((here (point)) | |
141 bracep | |
142 (curcol (progn | |
143 (goto-char (cdr langelem)) | |
144 (current-column))) | |
145 (bocm-lossage (progn | |
146 (goto-char (cdr langelem)) | |
147 (if (eq (char-after) ?{) | |
148 (setq bracep t) | |
149 (goto-char here) | |
150 (beginning-of-line) | |
151 (backward-up-list 1) | |
152 (forward-char 1) | |
153 (c-forward-syntactic-ws)) | |
154 (current-column)))) | |
155 (- bocm-lossage curcol | |
156 (if bracep 0 c-indent-level))))) | |
157 | |
158 | |
159 (defun cc-substatement-open-offset (langelem) | |
160 (+ c-continued-statement-offset c-continued-brace-offset)) | |
161 | |
162 | |
36920 | 163 (cc-provide 'cc-compat) |
18720 | 164 ;;; cc-compat.el ends here |