1 ;;; cc-compat.el --- cc-mode compatibility with c-mode.el confusion
3 ;; Copyright (C) 1985, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 ;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
5 ;; Free Software Foundation, Inc.
7 ;; Authors: 1998- Martin Stjernholm
8 ;; 1994-1999 Barry A. Warsaw
9 ;; Maintainer: bug-cc-mode@gnu.org
10 ;; Created: August 1994, split from cc-mode.el
11 ;; Version: See cc-mode.el
12 ;; Keywords: c languages oop
14 ;; This file is part of GNU Emacs.
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation; either version 3, or (at your option)
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with this program; see the file COPYING. If not, write to
28 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 ;; Boston, MA 02110-1301, USA.
33 ;; Boring old c-mode.el (BOCM) is confusion and brain melt. cc-mode.el
34 ;; is clarity of thought and purity of chi. If you are still unwilling
35 ;; to accept enlightenment, this might help, or it may prolong your
38 ;; To use, add the following to your c-mode-hook:
40 ;; (require 'cc-compat)
41 ;; (c-set-style "BOCM")
43 ;; This file is completely unsupported! Although it has been patched
44 ;; superficially to keep pace with the rest of CC Mode, it hasn't been
45 ;; tested for a long time.
51 (if (and (boundp 'byte-compile-dest-file
)
52 (stringp byte-compile-dest-file
))
53 (cons (file-name-directory byte-compile-dest-file
) load-path
)
55 (load "cc-bytecomp" nil t
)))
59 (cc-require 'cc-styles
)
60 (cc-require 'cc-engine
)
63 ;; In case c-mode.el isn't loaded
64 (defvar c-indent-level
2
65 "*Indentation of C statements with respect to containing block.")
66 ;;;###autoload(put 'c-indent-level 'safe-local-variable 'integerp)
68 (defvar c-brace-imaginary-offset
0
69 "*Imagined indentation of a C open brace that actually follows a statement.")
70 (defvar c-brace-offset
0
71 "*Extra indentation for braces, compared with other text in same context.")
72 (defvar c-argdecl-indent
5
73 "*Indentation level of declarations of C function arguments.")
74 (defvar c-label-offset -
2
75 "*Offset of C label lines and case statements relative to usual indentation.")
76 (defvar c-continued-statement-offset
2
77 "*Extra indent for lines not starting new statements.")
78 (defvar c-continued-brace-offset
0
79 "*Extra indent for substatements that start with open-braces.
80 This is in addition to c-continued-statement-offset.")
84 ;; these offsets are taken by brute force testing c-mode.el, since
85 ;; there's no logic to what it does.
86 (let* ((offsets '(c-offsets-alist .
87 ((defun-block-intro . cc-block-intro-offset
)
88 (statement-block-intro . cc-block-intro-offset
)
91 (inline-open . c-brace-offset
)
92 (block-open . c-brace-offset
)
93 (block-close . cc-block-close-offset
)
94 (brace-list-open . c-brace-offset
)
95 (substatement-open . cc-substatement-open-offset
)
96 (substatement . c-continued-statement-offset
)
97 (knr-argdecl-intro . c-argdecl-indent
)
98 (case-label . c-label-offset
)
99 (access-label . c-label-offset
)
100 (label . c-label-offset
)
102 (c-add-style "BOCM" offsets
))
105 (defun cc-block-intro-offset (langelem)
106 ;; taken directly from calculate-c-indent confusion
108 (c-backward-syntactic-ws)
109 (if (eq (char-before) ?
{)
111 (goto-char (cdr langelem
)))
112 (let* ((curcol (save-excursion
113 (goto-char (cdr langelem
))
116 ;; If no previous statement, indent it relative to line
117 ;; brace is on. For open brace in column zero, don't let
118 ;; statement start there too. If c-indent-level is zero,
119 ;; use c-brace-offset + c-continued-statement-offset
120 ;; instead. For open-braces not the first thing in a line,
121 ;; add in c-brace-imaginary-offset.
122 (+ (if (and (bolp) (zerop c-indent-level
))
123 (+ c-brace-offset c-continued-statement-offset
)
125 ;; Move back over whitespace before the openbrace. If
126 ;; openbrace is not first nonwhite thing on the line,
127 ;; add the c-brace-imaginary-offset.
128 (progn (skip-chars-backward " \t")
129 (if (bolp) 0 c-brace-imaginary-offset
))
130 ;; If the openbrace is preceded by a parenthesized exp,
131 ;; move to the beginning of that; possibly a different
134 (if (eq (char-before) ?\
))
136 ;; Get initial indentation of the line we are on.
137 (current-indentation)))))
138 (- bocm-lossage curcol
))))
141 (defun cc-block-close-offset (langelem)
143 (let* ((here (point))
146 (goto-char (cdr langelem
))
149 (goto-char (cdr langelem
))
150 (if (eq (char-after) ?
{)
156 (c-forward-syntactic-ws))
158 (- bocm-lossage curcol
159 (if bracep
0 c-indent-level
)))))
162 (defun cc-substatement-open-offset (langelem)
163 (+ c-continued-statement-offset c-continued-brace-offset
))
166 (cc-provide 'cc-compat
)
168 ;;; arch-tag: 564dab2f-e6ad-499c-a4a3-fedec3ecc192
169 ;;; cc-compat.el ends here