0
|
1 ;;; cc-compat.el --- cc-mode compatibility with c-mode.el confusion
|
|
2
|
|
3 ;; Copyright (C) 1985-1995 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: 1994-1995 Barry A. Warsaw
|
|
6 ;; Maintainer: cc-mode-help@merlin.cnri.reston.va.us
|
|
7 ;; Created: August 1994, split from cc-mode.el
|
|
8 ;; Version: 1.5
|
|
9 ;; Last Modified: 1995/06/11 20:15:44
|
|
10 ;; Keywords: c languages oop
|
|
11
|
|
12 ;; This file is part of GNU Emacs.
|
|
13
|
|
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
15 ;; it under the terms of the GNU General Public License as published by
|
|
16 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
17 ;; any later version.
|
|
18
|
|
19 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22 ;; GNU General Public License for more details.
|
|
23
|
|
24 ;; You should have received a copy of the GNU General Public License
|
|
25 ;; along with GNU Emacs; see the file COPYING. If not, write to
|
|
26 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
27
|
|
28 ;;; Synched up with: FSF 19.30.
|
|
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")
|
|
41
|
|
42 ;;; Code:
|
|
43
|
|
44
|
|
45 ;; In case c-mode.el isn't loaded
|
|
46 (defvar c-indent-level 2
|
|
47 "*Indentation of C statements with respect to containing block.")
|
|
48 (defvar c-brace-imaginary-offset 0
|
|
49 "*Imagined indentation of a C open brace that actually follows a statement.")
|
|
50 (defvar c-brace-offset 0
|
|
51 "*Extra indentation for braces, compared with other text in same context.")
|
|
52 (defvar c-argdecl-indent 5
|
|
53 "*Indentation level of declarations of C function arguments.")
|
|
54 (defvar c-label-offset -2
|
|
55 "*Offset of C label lines and case statements relative to usual indentation.")
|
|
56 (defvar c-continued-statement-offset 2
|
|
57 "*Extra indent for lines not starting new statements.")
|
|
58 (defvar c-continued-brace-offset 0
|
|
59 "*Extra indent for substatements that start with open-braces.
|
|
60 This is in addition to c-continued-statement-offset.")
|
|
61
|
|
62
|
|
63
|
|
64 ;; these offsets are taken by brute force testing c-mode.el, since
|
|
65 ;; there's no logic to what it does.
|
|
66 (let* ((offsets '(c-offsets-alist .
|
|
67 ((defun-block-intro . cc-block-intro-offset)
|
|
68 (statement-block-intro . cc-block-intro-offset)
|
|
69 (defun-open . 0)
|
|
70 (class-open . 0)
|
|
71 (inline-open . c-brace-offset)
|
|
72 (block-open . c-brace-offset)
|
|
73 (block-close . cc-block-close-offset)
|
|
74 (brace-list-open . c-brace-offset)
|
|
75 (substatement-open . cc-substatement-open-offset)
|
|
76 (substatement . c-continued-statement-offset)
|
|
77 (knr-argdecl-intro . c-argdecl-indent)
|
|
78 (case-label . c-label-offset)
|
|
79 (access-label . c-label-offset)
|
|
80 (label . c-label-offset)
|
|
81 ))))
|
|
82 (c-add-style "BOCM" offsets))
|
|
83
|
|
84
|
|
85 (defun cc-block-intro-offset (langelem)
|
|
86 ;; taken directly from calculate-c-indent confusion
|
|
87 (save-excursion
|
|
88 (c-backward-syntactic-ws)
|
|
89 (if (= (preceding-char) ?{)
|
|
90 (forward-char -1)
|
|
91 (goto-char (cdr langelem)))
|
|
92 (let* ((curcol (save-excursion
|
|
93 (goto-char (cdr langelem))
|
|
94 (current-column)))
|
|
95 (bocm-lossage
|
|
96 ;; If no previous statement, indent it relative to line
|
|
97 ;; brace is on. For open brace in column zero, don't let
|
|
98 ;; statement start there too. If c-indent-level is zero,
|
|
99 ;; use c-brace-offset + c-continued-statement-offset
|
|
100 ;; instead. For open-braces not the first thing in a line,
|
|
101 ;; add in c-brace-imaginary-offset.
|
|
102 (+ (if (and (bolp) (zerop c-indent-level))
|
|
103 (+ c-brace-offset c-continued-statement-offset)
|
|
104 c-indent-level)
|
|
105 ;; Move back over whitespace before the openbrace. If
|
|
106 ;; openbrace is not first nonwhite thing on the line,
|
|
107 ;; add the c-brace-imaginary-offset.
|
|
108 (progn (skip-chars-backward " \t")
|
|
109 (if (bolp) 0 c-brace-imaginary-offset))
|
|
110 ;; If the openbrace is preceded by a parenthesized exp,
|
|
111 ;; move to the beginning of that; possibly a different
|
|
112 ;; line
|
|
113 (progn
|
|
114 (if (eq (preceding-char) ?\))
|
|
115 (forward-sexp -1))
|
|
116 ;; Get initial indentation of the line we are on.
|
|
117 (current-indentation)))))
|
|
118 (- bocm-lossage curcol))))
|
|
119
|
|
120
|
|
121 (defun cc-block-close-offset (langelem)
|
|
122 (save-excursion
|
|
123 (let* ((here (point))
|
|
124 bracep
|
|
125 (curcol (progn
|
|
126 (goto-char (cdr langelem))
|
|
127 (current-column)))
|
|
128 (bocm-lossage (progn
|
|
129 (goto-char (cdr langelem))
|
|
130 (if (= (following-char) ?{)
|
|
131 (setq bracep t)
|
|
132 (goto-char here)
|
|
133 (beginning-of-line)
|
|
134 (backward-up-list 1)
|
|
135 (forward-char 1)
|
|
136 (c-forward-syntactic-ws))
|
|
137 (current-column))))
|
|
138 (- bocm-lossage curcol
|
|
139 (if bracep 0 c-indent-level)))))
|
|
140
|
|
141
|
|
142 (defun cc-substatement-open-offset (langelem)
|
|
143 (+ c-continued-statement-offset c-continued-brace-offset))
|
|
144
|
|
145
|
|
146 (provide 'cc-compat)
|
|
147 ;;; cc-compat.el ends here
|