Mercurial > hg > xemacs-beta
comparison lisp/modes/c-style.el @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | b82b59fe008d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 ;; c-style.el --- sets c-style control variables. | |
2 ;; Copyright (C) 1992-1993 Free Software Foundation, Inc. | |
3 | |
4 ;; This file is part of XEmacs. | |
5 | |
6 ;; XEmacs is free software; you can redistribute it and/or modify it | |
7 ;; under the terms of the GNU General Public License as published by | |
8 ;; the Free Software Foundation; either version 2, or (at your option) | |
9 ;; any later version. | |
10 | |
11 ;; XEmacs is distributed in the hope that it will be useful, but | |
12 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ;; General Public License for more details. | |
15 | |
16 ;; You should have received a copy of the GNU General Public License | |
17 ;; along with XEmacs; see the file COPYING. If not, write to the Free | |
18 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 ;; | |
20 ;; LCD Archive Entry: | |
21 ;; c-style|Daniel LaLiberte|liberte@cs.uiuc.edu | |
22 ;; |sets c-style control variables | |
23 ;; |Thu Feb 27 13:42:57 CST 1992|Version: 2.1|~/as-is/c-src-doc.el.Z | |
24 ;; | |
25 ;;; Synched up with: Not in FSF. | |
26 | |
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
28 ;;; | |
29 ;;; There are several ways to call set-c-style described below. | |
30 ;;; None of these methods reindent your program - they only affect | |
31 ;;; new indentation. | |
32 ;;; | |
33 ;;; - Just call set-c-style in your c-mode-hook. | |
34 ;;; Without style argument, default-c-style will be used. | |
35 ;;; With style argument, this will set the style for every | |
36 ;;; c-mode buffer the same. | |
37 ;;; | |
38 ;;; - Call set-c-style from the Local Variables list. | |
39 ;;; e.g. "eval:(set-c-style 'C++)" | |
40 ;;; | |
41 ;;; - Call set-c-style interactively. It prompts for the style name | |
42 ;;; with completion using default-c-style. | |
43 ;;; | |
44 ;;; For convenience, put one of the following in your .emacs: | |
45 ;;; (autoload 'set-c-style "c-style" nil t) | |
46 ;;; or (load "c-style") | |
47 ;;; ===================================================== | |
48 | |
49 (defvar default-c-style 'GNU | |
50 "*The default value of c-style. Set this in your .emacs.") | |
51 | |
52 ;; The following predefined styles are all I know about. | |
53 ;; If you learn of another style that has a "big" following, please | |
54 ;; send me the parameters. | |
55 | |
56 (defvar c-style-alist | |
57 '((GNU | |
58 (c-indent-level 2) | |
59 (c-continued-statement-offset 2) | |
60 (c-brace-offset 0) | |
61 (c-argdecl-indent 5) | |
62 (c-label-offset -2)) | |
63 | |
64 (BSD | |
65 (c-indent-level 8) | |
66 (c-continued-statement-offset 8) | |
67 (c-brace-offset -8) | |
68 (c-argdecl-indent 8) | |
69 (c-label-offset -8)) | |
70 | |
71 (K&R | |
72 (c-indent-level 5) | |
73 (c-continued-statement-offset 5) | |
74 (c-brace-offset -5) | |
75 (c-argdecl-indent 0) | |
76 (c-label-offset -5)) | |
77 | |
78 (BS ; was C++ | |
79 (c-indent-level 4) | |
80 (c-continued-statement-offset 4) | |
81 (c-brace-offset -4) | |
82 (c-argdecl-indent 4) | |
83 (c-label-offset -4)) | |
84 | |
85 ;; From Lynn Slater | |
86 (LRS | |
87 (c-indent-level 4) | |
88 (c-continued-statement-offset 4) | |
89 (c-brace-offset 0) | |
90 (c-argdecl-indent 4) | |
91 (c-label-offset -2) | |
92 (c-auto-newline nil)) | |
93 | |
94 (Plauger | |
95 (c-indent-level 0) | |
96 (c-continued-statement-offset 8) | |
97 (c-continued-brace-offset -8) | |
98 (c-brace-offset 8) | |
99 (c-brace-imaginary-offset 0) | |
100 (c-argdecl-indent 0) | |
101 (c-label-offset -8) | |
102 (c-auto-newline t) | |
103 (c-tab-always-indent t)) | |
104 | |
105 ;; From Jozsef A Toth <jtoth+@pitt.edu> | |
106 ;; Is this really the Whitesmith style? | |
107 (Alman | |
108 (c-argdecl-indent 0) | |
109 (c-brace-imaginary-offset 2) ;;; ???? | |
110 (c-brace-offset 0) | |
111 (c-continued-statement-offset 2) | |
112 (c-indent-level 0) | |
113 (c-label-offset -2) | |
114 (c-auto-newline t) | |
115 (comment-column 40) | |
116 (tab-width 2) | |
117 (fill-column '79)) | |
118 | |
119 (Gould | |
120 (c-indent-level 4) | |
121 (c-continued-statement-offset 4) | |
122 (c-brace-offset -4) | |
123 (c-argdecl-indent 8) | |
124 (c-label-offset -2) | |
125 (c-brace-imaginary-offset 0)) | |
126 | |
127 ;; From Joan Eslinger <wombat@kilimanjaro.key.amdahl.com> | |
128 (WRS | |
129 (c-indent-level 0) | |
130 (c-continued-statement-offset 4) | |
131 (c-brace-offset 0) | |
132 (c-argdecl-indent 4) | |
133 (c-label-offset -2) | |
134 (c-brace-imaginary-offset 4) | |
135 (c-continued-brace-offset -4)) | |
136 )) | |
137 | |
138 (defvar c-style nil | |
139 "The buffer local c-mode indentation style.") | |
140 | |
141 ;; Add style name to mode line. Assumes minor-mode-alist is not buffer local. | |
142 ;; Thanks to Joan Eslinger. | |
143 | |
144 (defvar c-style-name nil | |
145 "The style name for a c-mode indentation style. | |
146 This is to be set by set-c-style, and used by the mode line.") | |
147 | |
148 (or (assq 'c-style-name minor-mode-alist) | |
149 (setq minor-mode-alist | |
150 (purecopy | |
151 (append minor-mode-alist | |
152 ;; use undocumented feature | |
153 '((c-style-name c-style-name)))))) | |
154 | |
155 (defun set-c-style (&optional style) | |
156 "Set up the c-mode style variables from STYLE if it is given, or | |
157 default-c-style otherwise. It makes the c indentation style variables | |
158 buffer local." | |
159 | |
160 (interactive) | |
161 | |
162 (let ((c-styles (mapcar 'car c-style-alist))) ; for completion | |
163 (if (interactive-p) | |
164 (setq style | |
165 (let ((style-string ; Get style name with completion. | |
166 (completing-read | |
167 (format "Set c-mode indentation style to (default %s): " | |
168 default-c-style) | |
169 (vconcat c-styles) | |
170 (function (lambda (arg) (memq arg c-styles))) | |
171 ))) | |
172 (if (string-equal "" style-string) | |
173 default-c-style | |
174 (intern style-string)) | |
175 ))) | |
176 | |
177 ;; If style is nil, use default-c-style. | |
178 (setq style (or style default-c-style)) | |
179 | |
180 (make-local-variable 'c-style) | |
181 (if (memq style c-styles) | |
182 (setq c-style style) | |
183 (error "Undefined c style: %s" style) | |
184 ) | |
185 (message "c-style: %s" c-style) | |
186 | |
187 ;; Set the c-style-name | |
188 (make-local-variable 'c-style-name) | |
189 (setq c-style-name (format " %s" c-style)) | |
190 | |
191 ;; Finally, set the indentation style variables making each one local. | |
192 (mapcar (function (lambda (c-style-pair) | |
193 (make-local-variable (car c-style-pair)) | |
194 (set (car c-style-pair) | |
195 (car (cdr c-style-pair))))) | |
196 (cdr (assq c-style c-style-alist))) | |
197 c-style | |
198 )) |