annotate lisp/modes/cc-compat.el @ 124:9b50b4588a93 r20-1b15

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