Mercurial > emacs
annotate lisp/progmodes/c-mode.el @ 11255:e79aca68f09c
Comment changes.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 07 Apr 1995 07:34:13 +0000 |
parents | 4d2a2fe1d8d7 |
children | 70e05c1afba7 |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
472
diff
changeset
|
1 ;;; c-mode.el --- C code editing commands for Emacs |
11234 | 2 ;; Copyright (C) 1985, 86, 87, 92, 94, 95 Free Software Foundation, Inc. |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
837
diff
changeset
|
3 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
759
diff
changeset
|
4 ;; Maintainer: FSF |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
759
diff
changeset
|
5 ;; Keywords: c |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
759
diff
changeset
|
6 |
453 | 7 ;; This file is part of GNU Emacs. |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
759
diff
changeset
|
11 ;; the Free Software Foundation; either version 2, or (at your option) |
453 | 12 ;; any later version. |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2084
diff
changeset
|
23 ;;; Commentary: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2084
diff
changeset
|
24 |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2084
diff
changeset
|
25 ;; A smart editing mode for C code. It knows a lot about C syntax and tries |
11234 | 26 ;; to position the cursor according to C layout conventions. You can |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2084
diff
changeset
|
27 ;; change the details of the layout style with option variables. Load it |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2084
diff
changeset
|
28 ;; and do M-x describe-mode for details. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2084
diff
changeset
|
29 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
759
diff
changeset
|
30 ;;; Code: |
453 | 31 |
32 (defvar c-mode-abbrev-table nil | |
33 "Abbrev table in use in C mode.") | |
34 (define-abbrev-table 'c-mode-abbrev-table ()) | |
35 | |
5417
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
36 (defvar c-mode-map (make-sparse-keymap) |
453 | 37 "Keymap used in C mode.") |
5417
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
38 |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
39 (define-key c-mode-map "{" 'electric-c-brace) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
40 (define-key c-mode-map "}" 'electric-c-brace) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
41 (define-key c-mode-map ";" 'electric-c-semi) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
42 (define-key c-mode-map "#" 'electric-c-sharp-sign) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
43 (define-key c-mode-map ":" 'electric-c-terminator) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
44 (define-key c-mode-map "\e\C-h" 'mark-c-function) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
45 (define-key c-mode-map "\e\C-q" 'indent-c-exp) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
46 (define-key c-mode-map "\ea" 'c-beginning-of-statement) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
47 (define-key c-mode-map "\ee" 'c-end-of-statement) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
48 (define-key c-mode-map "\C-c\C-n" 'c-forward-conditional) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
49 (define-key c-mode-map "\C-c\C-p" 'c-backward-conditional) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
50 (define-key c-mode-map "\C-c\C-u" 'c-up-conditional) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
51 (define-key c-mode-map "\177" 'backward-delete-char-untabify) |
5423
8213b45445a6
Fix typo in previous change.
Richard M. Stallman <rms@gnu.org>
parents:
5422
diff
changeset
|
52 (define-key c-mode-map "\t" 'c-indent-command) |
5417
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
53 |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
54 (define-key c-mode-map [menu-bar] (make-sparse-keymap)) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
55 |
11068
d274f02fc4f1
(c-mode-map): Use "C-mode", not "C mode".
Richard M. Stallman <rms@gnu.org>
parents:
11028
diff
changeset
|
56 ;; "C-mode" is not strictly the right punctuation--it should be "C |
d274f02fc4f1
(c-mode-map): Use "C-mode", not "C mode".
Richard M. Stallman <rms@gnu.org>
parents:
11028
diff
changeset
|
57 ;; mode"--but that would look like two menu items. "C-mode" is the |
d274f02fc4f1
(c-mode-map): Use "C-mode", not "C mode".
Richard M. Stallman <rms@gnu.org>
parents:
11028
diff
changeset
|
58 ;; best alternative I can think of. |
5417
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
59 (define-key c-mode-map [menu-bar c] |
11068
d274f02fc4f1
(c-mode-map): Use "C-mode", not "C mode".
Richard M. Stallman <rms@gnu.org>
parents:
11028
diff
changeset
|
60 (cons "C-mode" (make-sparse-keymap "C-mode"))) |
5417
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
61 |
5422 | 62 (define-key c-mode-map [menu-bar c comment-region] |
63 '("Comment Out Region" . comment-region)) | |
64 (define-key c-mode-map [menu-bar c c-macro-expand] | |
65 '("Macro Expand Region" . c-macro-expand)) | |
66 (define-key c-mode-map [menu-bar c c-backslash-region] | |
67 '("Backslashify" . c-backslash-region)) | |
5417
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
68 (define-key c-mode-map [menu-bar c indent-exp] |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
69 '("Indent Expression" . indent-c-exp)) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
70 (define-key c-mode-map [menu-bar c indent-line] |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
71 '("Indent Line" . c-indent-command)) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
72 (define-key c-mode-map [menu-bar c fill] |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
73 '("Fill Comment Paragraph" . c-fill-paragraph)) |
8742
a82055863414
(c-mode-map): Add "Highlight Conditionals" menu item.
Richard M. Stallman <rms@gnu.org>
parents:
8467
diff
changeset
|
74 (define-key c-mode-map [menu-bar c cpp-highlight-buffer] |
a82055863414
(c-mode-map): Add "Highlight Conditionals" menu item.
Richard M. Stallman <rms@gnu.org>
parents:
8467
diff
changeset
|
75 '("Highlight Conditionals" . cpp-highlight-buffer)) |
5417
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
76 (define-key c-mode-map [menu-bar c up] |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
77 '("Up Conditional" . c-up-conditional)) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
78 (define-key c-mode-map [menu-bar c backward] |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
79 '("Backward Conditional" . c-backward-conditional)) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
80 (define-key c-mode-map [menu-bar c forward] |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
81 '("Forward Conditional" . c-forward-conditional)) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
82 (define-key c-mode-map [menu-bar c backward-stmt] |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
83 '("Backward Statement" . c-beginning-of-statement)) |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
84 (define-key c-mode-map [menu-bar c forward-stmt] |
4d74f3f4ed03
(c-mode-map): Add menu bar menu.
Richard M. Stallman <rms@gnu.org>
parents:
5305
diff
changeset
|
85 '("Forward Statement" . c-end-of-statement)) |
453 | 86 |
87 (autoload 'c-macro-expand "cmacexp" | |
88 "Display the result of expanding all C macros occurring in the region. | |
89 The expansion is entirely correct because it uses the C preprocessor." | |
90 t) | |
91 | |
92 (defvar c-mode-syntax-table nil | |
93 "Syntax table in use in C-mode buffers.") | |
94 | |
95 (if c-mode-syntax-table | |
96 () | |
97 (setq c-mode-syntax-table (make-syntax-table)) | |
98 (modify-syntax-entry ?\\ "\\" c-mode-syntax-table) | |
99 (modify-syntax-entry ?/ ". 14" c-mode-syntax-table) | |
100 (modify-syntax-entry ?* ". 23" c-mode-syntax-table) | |
101 (modify-syntax-entry ?+ "." c-mode-syntax-table) | |
102 (modify-syntax-entry ?- "." c-mode-syntax-table) | |
103 (modify-syntax-entry ?= "." c-mode-syntax-table) | |
104 (modify-syntax-entry ?% "." c-mode-syntax-table) | |
105 (modify-syntax-entry ?< "." c-mode-syntax-table) | |
106 (modify-syntax-entry ?> "." c-mode-syntax-table) | |
107 (modify-syntax-entry ?& "." c-mode-syntax-table) | |
108 (modify-syntax-entry ?| "." c-mode-syntax-table) | |
109 (modify-syntax-entry ?\' "\"" c-mode-syntax-table)) | |
110 | |
111 (defconst c-indent-level 2 | |
112 "*Indentation of C statements with respect to containing block.") | |
113 (defconst c-brace-imaginary-offset 0 | |
114 "*Imagined indentation of a C open brace that actually follows a statement.") | |
115 (defconst c-brace-offset 0 | |
116 "*Extra indentation for braces, compared with other text in same context.") | |
117 (defconst c-argdecl-indent 5 | |
118 "*Indentation level of declarations of C function arguments.") | |
119 (defconst c-label-offset -2 | |
120 "*Offset of C label lines and case statements relative to usual indentation.") | |
121 (defconst c-continued-statement-offset 2 | |
122 "*Extra indent for lines not starting new statements.") | |
123 (defconst c-continued-brace-offset 0 | |
124 "*Extra indent for substatements that start with open-braces. | |
11028
123bb3f2d018
(c-style-alist): For BSD, set c-continued-brace-offset
Richard M. Stallman <rms@gnu.org>
parents:
10986
diff
changeset
|
125 This is in addition to `c-continued-statement-offset'.") |
453 | 126 (defconst c-style-alist |
127 '(("GNU" | |
128 (c-indent-level . 2) | |
129 (c-argdecl-indent . 5) | |
130 (c-brace-offset . 0) | |
11110
5f696061a082
(c-style-alist): Set c-continued-brace-offset and
Karl Heuer <kwzh@gnu.org>
parents:
11068
diff
changeset
|
131 (c-continued-brace-offset . 0) |
453 | 132 (c-label-offset . -2) |
133 (c-continued-statement-offset . 2)) | |
134 ("K&R" | |
135 (c-indent-level . 5) | |
136 (c-argdecl-indent . 0) | |
11110
5f696061a082
(c-style-alist): Set c-continued-brace-offset and
Karl Heuer <kwzh@gnu.org>
parents:
11068
diff
changeset
|
137 (c-brace-offset . 0) |
5f696061a082
(c-style-alist): Set c-continued-brace-offset and
Karl Heuer <kwzh@gnu.org>
parents:
11068
diff
changeset
|
138 (c-continued-brace-offset . -5) |
453 | 139 (c-label-offset . -5) |
140 (c-continued-statement-offset . 5)) | |
141 ("BSD" | |
142 (c-indent-level . 4) | |
143 (c-argdecl-indent . 4) | |
11110
5f696061a082
(c-style-alist): Set c-continued-brace-offset and
Karl Heuer <kwzh@gnu.org>
parents:
11068
diff
changeset
|
144 (c-brace-offset . 0) |
11028
123bb3f2d018
(c-style-alist): For BSD, set c-continued-brace-offset
Richard M. Stallman <rms@gnu.org>
parents:
10986
diff
changeset
|
145 (c-continued-brace-offset . -4) |
453 | 146 (c-label-offset . -4) |
147 (c-continued-statement-offset . 4)) | |
1661
26d8a65a6e32
* c-mode.el (c-style-alist): Add quotes around C++ style name.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1205
diff
changeset
|
148 ("C++" |
11110
5f696061a082
(c-style-alist): Set c-continued-brace-offset and
Karl Heuer <kwzh@gnu.org>
parents:
11068
diff
changeset
|
149 (c-indent-level . 4) |
5f696061a082
(c-style-alist): Set c-continued-brace-offset and
Karl Heuer <kwzh@gnu.org>
parents:
11068
diff
changeset
|
150 (c-argdecl-indent . 0) |
5f696061a082
(c-style-alist): Set c-continued-brace-offset and
Karl Heuer <kwzh@gnu.org>
parents:
11068
diff
changeset
|
151 (c-brace-offset . 0) |
5f696061a082
(c-style-alist): Set c-continued-brace-offset and
Karl Heuer <kwzh@gnu.org>
parents:
11068
diff
changeset
|
152 (c-continued-brace-offset . -4) |
472 | 153 (c-label-offset . -4) |
11110
5f696061a082
(c-style-alist): Set c-continued-brace-offset and
Karl Heuer <kwzh@gnu.org>
parents:
11068
diff
changeset
|
154 (c-continued-statement-offset . 4) |
5f696061a082
(c-style-alist): Set c-continued-brace-offset and
Karl Heuer <kwzh@gnu.org>
parents:
11068
diff
changeset
|
155 (c-auto-newline . t)) |
453 | 156 ("Whitesmith" |
157 (c-indent-level . 4) | |
158 (c-argdecl-indent . 4) | |
159 (c-brace-offset . 0) | |
11110
5f696061a082
(c-style-alist): Set c-continued-brace-offset and
Karl Heuer <kwzh@gnu.org>
parents:
11068
diff
changeset
|
160 (c-continued-brace-offset . 0) |
453 | 161 (c-label-offset . -4) |
162 (c-continued-statement-offset . 4)))) | |
163 | |
164 (defconst c-auto-newline nil | |
165 "*Non-nil means automatically newline before and after braces, | |
166 and after colons and semicolons, inserted in C code. | |
167 If you do not want a leading newline before braces then use: | |
1159 | 168 (define-key c-mode-map \"{\" 'electric-c-semi)") |
453 | 169 |
170 (defconst c-tab-always-indent t | |
171 "*Non-nil means TAB in C mode should always reindent the current line, | |
172 regardless of where in the line point is when the TAB command is used.") | |
1804
fe2bebf150c7
* c-mode.el (c-switch-label-regexp): New constant.
Jim Blandy <jimb@redhat.com>
parents:
1701
diff
changeset
|
173 |
fe2bebf150c7
* c-mode.el (c-switch-label-regexp): New constant.
Jim Blandy <jimb@redhat.com>
parents:
1701
diff
changeset
|
174 ;;; Regular expression used internally to recognize labels in switch |
fe2bebf150c7
* c-mode.el (c-switch-label-regexp): New constant.
Jim Blandy <jimb@redhat.com>
parents:
1701
diff
changeset
|
175 ;;; statements. |
10733
d08b63758c1a
(c-switch-label-regexp): Insist on colon after `default'.
Richard M. Stallman <rms@gnu.org>
parents:
10630
diff
changeset
|
176 (defconst c-switch-label-regexp "case[ \t'/(]\\|default[ \t]*:") |
1804
fe2bebf150c7
* c-mode.el (c-switch-label-regexp): New constant.
Jim Blandy <jimb@redhat.com>
parents:
1701
diff
changeset
|
177 |
453 | 178 |
179 (defun c-mode () | |
180 "Major mode for editing C code. | |
181 Expression and list commands understand all C brackets. | |
182 Tab indents for C code. | |
183 Comments are delimited with /* ... */. | |
184 Paragraphs are separated by blank lines only. | |
185 Delete converts tabs to spaces as it moves back. | |
186 \\{c-mode-map} | |
187 Variables controlling indentation style: | |
188 c-tab-always-indent | |
189 Non-nil means TAB in C mode should always reindent the current line, | |
190 regardless of where in the line point is when the TAB command is used. | |
191 c-auto-newline | |
192 Non-nil means automatically newline before and after braces, | |
193 and after colons and semicolons, inserted in C code. | |
194 c-indent-level | |
195 Indentation of C statements within surrounding block. | |
196 The surrounding block's indentation is the indentation | |
197 of the line on which the open-brace appears. | |
198 c-continued-statement-offset | |
199 Extra indentation given to a substatement, such as the | |
200 then-clause of an if or body of a while. | |
201 c-continued-brace-offset | |
202 Extra indentation given to a brace that starts a substatement. | |
203 This is in addition to c-continued-statement-offset. | |
204 c-brace-offset | |
205 Extra indentation for line if it starts with an open brace. | |
206 c-brace-imaginary-offset | |
207 An open brace following other text is treated as if it were | |
208 this far to the right of the start of its line. | |
209 c-argdecl-indent | |
210 Indentation level of declarations of C function arguments. | |
211 c-label-offset | |
212 Extra indentation for line that is a label, or case or default. | |
213 | |
214 Settings for K&R and BSD indentation styles are | |
215 c-indent-level 5 8 | |
216 c-continued-statement-offset 5 8 | |
217 c-brace-offset -5 -8 | |
218 c-argdecl-indent 0 8 | |
219 c-label-offset -5 -8 | |
220 | |
221 Turning on C mode calls the value of the variable c-mode-hook with no args, | |
222 if that value is non-nil." | |
223 (interactive) | |
224 (kill-all-local-variables) | |
225 (use-local-map c-mode-map) | |
226 (setq major-mode 'c-mode) | |
227 (setq mode-name "C") | |
228 (setq local-abbrev-table c-mode-abbrev-table) | |
229 (set-syntax-table c-mode-syntax-table) | |
230 (make-local-variable 'paragraph-start) | |
10870
b869871813cc
(c-mode, c-fill-paragraph): Remove ^ from paragraph-start & paragraph-separate.
Boris Goldowsky <boris@gnu.org>
parents:
10733
diff
changeset
|
231 (setq paragraph-start (concat "$\\|" page-delimiter)) |
453 | 232 (make-local-variable 'paragraph-separate) |
233 (setq paragraph-separate paragraph-start) | |
234 (make-local-variable 'paragraph-ignore-fill-prefix) | |
235 (setq paragraph-ignore-fill-prefix t) | |
10630
3e851e5cab1f
(c-mode-map): No binding for c-fill-paragraph
Richard M. Stallman <rms@gnu.org>
parents:
10544
diff
changeset
|
236 (make-local-variable 'fill-paragraph-function) |
3e851e5cab1f
(c-mode-map): No binding for c-fill-paragraph
Richard M. Stallman <rms@gnu.org>
parents:
10544
diff
changeset
|
237 (setq fill-paragraph-function 'c-fill-paragraph) |
453 | 238 (make-local-variable 'indent-line-function) |
239 (setq indent-line-function 'c-indent-line) | |
240 (make-local-variable 'indent-region-function) | |
241 (setq indent-region-function 'c-indent-region) | |
242 (make-local-variable 'require-final-newline) | |
243 (setq require-final-newline t) | |
6074
33f42f5f7448
(c-mode): Set outline-regexp and outline-level.
Richard M. Stallman <rms@gnu.org>
parents:
5806
diff
changeset
|
244 (make-local-variable 'outline-regexp) |
33f42f5f7448
(c-mode): Set outline-regexp and outline-level.
Richard M. Stallman <rms@gnu.org>
parents:
5806
diff
changeset
|
245 (setq outline-regexp "[^#\n\^M]") |
33f42f5f7448
(c-mode): Set outline-regexp and outline-level.
Richard M. Stallman <rms@gnu.org>
parents:
5806
diff
changeset
|
246 (make-local-variable 'outline-level) |
33f42f5f7448
(c-mode): Set outline-regexp and outline-level.
Richard M. Stallman <rms@gnu.org>
parents:
5806
diff
changeset
|
247 (setq outline-level 'c-outline-level) |
453 | 248 (make-local-variable 'comment-start) |
249 (setq comment-start "/* ") | |
250 (make-local-variable 'comment-end) | |
251 (setq comment-end " */") | |
252 (make-local-variable 'comment-column) | |
253 (setq comment-column 32) | |
254 (make-local-variable 'comment-start-skip) | |
255 (setq comment-start-skip "/\\*+ *") | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2084
diff
changeset
|
256 (make-local-variable 'comment-indent-function) |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2084
diff
changeset
|
257 (setq comment-indent-function 'c-comment-indent) |
10986
7e797580a46d
(c-mode): Make comment-multi-line t locally.
Richard M. Stallman <rms@gnu.org>
parents:
10870
diff
changeset
|
258 (make-local-variable 'comment-multi-line) |
7e797580a46d
(c-mode): Make comment-multi-line t locally.
Richard M. Stallman <rms@gnu.org>
parents:
10870
diff
changeset
|
259 (setq comment-multi-line t) |
453 | 260 (make-local-variable 'parse-sexp-ignore-comments) |
261 (setq parse-sexp-ignore-comments t) | |
262 (run-hooks 'c-mode-hook)) | |
6074
33f42f5f7448
(c-mode): Set outline-regexp and outline-level.
Richard M. Stallman <rms@gnu.org>
parents:
5806
diff
changeset
|
263 |
33f42f5f7448
(c-mode): Set outline-regexp and outline-level.
Richard M. Stallman <rms@gnu.org>
parents:
5806
diff
changeset
|
264 (defun c-outline-level () |
33f42f5f7448
(c-mode): Set outline-regexp and outline-level.
Richard M. Stallman <rms@gnu.org>
parents:
5806
diff
changeset
|
265 (save-excursion |
33f42f5f7448
(c-mode): Set outline-regexp and outline-level.
Richard M. Stallman <rms@gnu.org>
parents:
5806
diff
changeset
|
266 (skip-chars-forward "\t ") |
33f42f5f7448
(c-mode): Set outline-regexp and outline-level.
Richard M. Stallman <rms@gnu.org>
parents:
5806
diff
changeset
|
267 (current-column))) |
453 | 268 |
269 ;; This is used by indent-for-comment | |
270 ;; to decide how much to indent a comment in C code | |
271 ;; based on its context. | |
272 (defun c-comment-indent () | |
273 (if (looking-at "^/\\*") | |
274 0 ;Existing comment at bol stays there. | |
275 (let ((opoint (point))) | |
276 (save-excursion | |
277 (beginning-of-line) | |
278 (cond ((looking-at "[ \t]*}[ \t]*\\($\\|/\\*\\)") | |
279 ;; A comment following a solitary close-brace | |
280 ;; should have only one space. | |
281 (search-forward "}") | |
282 (1+ (current-column))) | |
283 ((or (looking-at "^#[ \t]*endif[ \t]*") | |
284 (looking-at "^#[ \t]*else[ \t]*")) | |
285 7) ;2 spaces after #endif | |
286 ((progn | |
287 (goto-char opoint) | |
288 (skip-chars-backward " \t") | |
289 (and (= comment-column 0) (bolp))) | |
290 ;; If comment-column is 0, and nothing but space | |
291 ;; before the comment, align it at 0 rather than 1. | |
292 0) | |
293 (t | |
294 (max (1+ (current-column)) ;Else indent at comment column | |
295 comment-column))))))) ; except leave at least one space. | |
296 | |
297 (defun c-fill-paragraph (&optional arg) | |
298 "Like \\[fill-paragraph] but handle C comments. | |
1081
4e7d09b779eb
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1064
diff
changeset
|
299 If any of the current line is a comment or within a comment, |
4e7d09b779eb
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1064
diff
changeset
|
300 fill the comment or the paragraph of it that point is in, |
4e7d09b779eb
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1064
diff
changeset
|
301 preserving the comment indentation or line-starting decorations." |
453 | 302 (interactive "P") |
1086
273918bf0a95
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1081
diff
changeset
|
303 (let* (comment-start-place |
273918bf0a95
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1081
diff
changeset
|
304 (first-line |
273918bf0a95
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1081
diff
changeset
|
305 ;; Check for obvious entry to comment. |
273918bf0a95
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1081
diff
changeset
|
306 (save-excursion |
273918bf0a95
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1081
diff
changeset
|
307 (beginning-of-line) |
1701
e0463f021e2f
* c-mode.el (c-fill-paragraph): Calculating the proper fill-prefix
Jim Blandy <jimb@redhat.com>
parents:
1662
diff
changeset
|
308 (skip-chars-forward " \t\n") |
1086
273918bf0a95
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1081
diff
changeset
|
309 (and (looking-at comment-start-skip) |
273918bf0a95
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1081
diff
changeset
|
310 (setq comment-start-place (point)))))) |
5689
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
311 (if (and (eq major-mode 'c++-mode) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
312 (save-excursion |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
313 (beginning-of-line) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
314 (looking-at ".*//"))) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
315 (let (fill-prefix |
453 | 316 (paragraph-start |
317 ;; Lines containing just a comment start or just an end | |
318 ;; should not be filled into paragraphs they are next to. | |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1804
diff
changeset
|
319 (concat |
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1804
diff
changeset
|
320 paragraph-start |
10870
b869871813cc
(c-mode, c-fill-paragraph): Remove ^ from paragraph-start & paragraph-separate.
Boris Goldowsky <boris@gnu.org>
parents:
10733
diff
changeset
|
321 "\\|[ \t]*/\\*[ \t]*$\\|[ \t]*\\*/[ \t]*$\\|[ \t/*]*$")) |
453 | 322 (paragraph-separate |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1804
diff
changeset
|
323 (concat |
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1804
diff
changeset
|
324 paragraph-separate |
10870
b869871813cc
(c-mode, c-fill-paragraph): Remove ^ from paragraph-start & paragraph-separate.
Boris Goldowsky <boris@gnu.org>
parents:
10733
diff
changeset
|
325 "\\|[ \t]*/\\*[ \t]*$\\|[ \t]*\\*/[ \t]*$\\|[ \t/*]*$"))) |
5689
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
326 (save-excursion |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
327 (beginning-of-line) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
328 ;; Move up to first line of this comment. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
329 (while (and (not (bobp)) (looking-at "[ \t]*//")) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
330 (forward-line -1)) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
331 (if (not (looking-at ".*//")) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
332 (forward-line 1)) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
333 ;; Find the comment start in this line. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
334 (re-search-forward "[ \t]*//[ \t]*") |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
335 ;; Set the fill-prefix to be what all lines except the first |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
336 ;; should start with. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
337 (let ((endcol (current-column))) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
338 (skip-chars-backward " \t") |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
339 (setq fill-prefix |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
340 (concat (make-string (- (current-column) 2) ?\ ) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
341 "//" |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
342 (make-string (- endcol (current-column)) ?\ )))) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
343 (save-restriction |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
344 ;; Narrow down to just the lines of this comment. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
345 (narrow-to-region (point) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
346 (save-excursion |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
347 (forward-line 1) |
5761
7bea55d86ff6
(c-fill-paragraph): Delete extraneous close paren.
Karl Heuer <kwzh@gnu.org>
parents:
5689
diff
changeset
|
348 (while (looking-at "[ \t]*//") |
5689
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
349 (forward-line 1)) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
350 (point))) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
351 (insert fill-prefix) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
352 (fill-paragraph arg) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
353 (delete-region (point-min) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
354 (+ (point-min) (length fill-prefix)))))) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
355 (if (or first-line |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
356 ;; t if we enter a comment between start of function and this line. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
357 (eq (calculate-c-indent) t) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
358 ;; t if this line contains a comment starter. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
359 (setq first-line |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
360 (save-excursion |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
361 (beginning-of-line) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
362 (prog1 |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
363 (re-search-forward comment-start-skip |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
364 (save-excursion (end-of-line) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
365 (point)) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
366 t) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
367 (setq comment-start-place (point)))))) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
368 ;; Inside a comment: fill one comment paragraph. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
369 (let ((fill-prefix |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
370 ;; The prefix for each line of this paragraph |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
371 ;; is the appropriate part of the start of this line, |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
372 ;; up to the column at which text should be indented. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
373 (save-excursion |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
374 (beginning-of-line) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
375 (if (looking-at "[ \t]*/\\*.*\\*/") |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
376 (progn (re-search-forward comment-start-skip) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
377 (make-string (current-column) ?\ )) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
378 (if first-line (forward-line 1)) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
379 |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
380 (let ((line-width (progn (end-of-line) (current-column)))) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
381 (beginning-of-line) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
382 (prog1 |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
383 (buffer-substring |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
384 (point) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
385 |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
386 ;; How shall we decide where the end of the |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
387 ;; fill-prefix is? |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
388 ;; calculate-c-indent-within-comment bases its value |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
389 ;; on the indentation of previous lines; if they're |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
390 ;; indented specially, it could return a column |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
391 ;; that's well into the current line's text. So |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
392 ;; we'll take at most that many space, tab, or * |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
393 ;; characters, and use that as our fill prefix. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
394 (let ((max-prefix-end |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
395 (progn |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
396 (move-to-column |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
397 (calculate-c-indent-within-comment t) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
398 t) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
399 (point)))) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
400 (beginning-of-line) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
401 (skip-chars-forward " \t*" max-prefix-end) |
7678
3eb816e254e6
(c-fill-paragraph): Don't include part of comment
Richard M. Stallman <rms@gnu.org>
parents:
6579
diff
changeset
|
402 ;; Don't include part of comment terminator |
3eb816e254e6
(c-fill-paragraph): Don't include part of comment
Richard M. Stallman <rms@gnu.org>
parents:
6579
diff
changeset
|
403 ;; in the fill-prefix. |
3eb816e254e6
(c-fill-paragraph): Don't include part of comment
Richard M. Stallman <rms@gnu.org>
parents:
6579
diff
changeset
|
404 (and (eq (following-char) ?/) |
3eb816e254e6
(c-fill-paragraph): Don't include part of comment
Richard M. Stallman <rms@gnu.org>
parents:
6579
diff
changeset
|
405 (eq (preceding-char) ?*) |
3eb816e254e6
(c-fill-paragraph): Don't include part of comment
Richard M. Stallman <rms@gnu.org>
parents:
6579
diff
changeset
|
406 (backward-char 1)) |
5689
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
407 (point))) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
408 |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
409 ;; If the comment is only one line followed by a blank |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
410 ;; line, calling move-to-column above may have added |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
411 ;; some spaces and tabs to the end of the line; the |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
412 ;; fill-paragraph function will then delete it and the |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
413 ;; newline following it, so we'll lose a blank line |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
414 ;; when we shouldn't. So delete anything |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
415 ;; move-to-column added to the end of the line. We |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
416 ;; record the line width instead of the position of the |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
417 ;; old line end because move-to-column might break a |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
418 ;; tab into spaces, and the new characters introduced |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
419 ;; there shouldn't be deleted. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
420 |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
421 ;; If you can see a better way to do this, please make |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
422 ;; the change. This seems very messy to me. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
423 (delete-region (progn (move-to-column line-width) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
424 (point)) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
425 (progn (end-of-line) (point)))))))) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
426 |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
427 (paragraph-start |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
428 ;; Lines containing just a comment start or just an end |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
429 ;; should not be filled into paragraphs they are next to. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
430 (concat |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
431 paragraph-start |
10870
b869871813cc
(c-mode, c-fill-paragraph): Remove ^ from paragraph-start & paragraph-separate.
Boris Goldowsky <boris@gnu.org>
parents:
10733
diff
changeset
|
432 "\\|[ \t]*/\\*[ \t]*$\\|[ \t]*\\*/[ \t]*$\\|[ \t/*]*$")) |
5689
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
433 (paragraph-separate |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
434 (concat |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
435 paragraph-separate |
10870
b869871813cc
(c-mode, c-fill-paragraph): Remove ^ from paragraph-start & paragraph-separate.
Boris Goldowsky <boris@gnu.org>
parents:
10733
diff
changeset
|
436 "\\|[ \t]*/\\*[ \t]*$\\|[ \t]*\\*/[ \t]*$\\|[ \t/*]*$")) |
5689
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
437 (chars-to-delete 0)) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
438 (save-restriction |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
439 ;; Don't fill the comment together with the code following it. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
440 ;; So temporarily exclude everything before the comment start, |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
441 ;; and everything after the line where the comment ends. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
442 ;; If comment-start-place is non-nil, the comment starter is there. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
443 ;; Otherwise, point is inside the comment. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
444 (narrow-to-region (save-excursion |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
445 (if comment-start-place |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
446 (goto-char comment-start-place) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
447 (search-backward "/*")) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
448 ;; Protect text before the comment start |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
449 ;; by excluding it. Add spaces to bring back |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
450 ;; proper indentation of that point. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
451 (let ((column (current-column))) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
452 (prog1 (point) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
453 (setq chars-to-delete column) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
454 (insert-char ?\ column)))) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
455 (save-excursion |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
456 (if comment-start-place |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
457 (goto-char (+ comment-start-place 2))) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
458 (search-forward "*/" nil 'move) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
459 (forward-line 1) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
460 (point))) |
10544
eeeae6ef626e
(c-forward-conditional):
Richard M. Stallman <rms@gnu.org>
parents:
10490
diff
changeset
|
461 (goto-char (point-max)) |
eeeae6ef626e
(c-forward-conditional):
Richard M. Stallman <rms@gnu.org>
parents:
10490
diff
changeset
|
462 (forward-line -1) |
eeeae6ef626e
(c-forward-conditional):
Richard M. Stallman <rms@gnu.org>
parents:
10490
diff
changeset
|
463 ;; And comment terminator was on a separate line before, |
eeeae6ef626e
(c-forward-conditional):
Richard M. Stallman <rms@gnu.org>
parents:
10490
diff
changeset
|
464 ;; keep it that way. |
eeeae6ef626e
(c-forward-conditional):
Richard M. Stallman <rms@gnu.org>
parents:
10490
diff
changeset
|
465 ;; This also avoids another problem: |
eeeae6ef626e
(c-forward-conditional):
Richard M. Stallman <rms@gnu.org>
parents:
10490
diff
changeset
|
466 ;; if the fill-prefix ends in a *, it could eat up |
eeeae6ef626e
(c-forward-conditional):
Richard M. Stallman <rms@gnu.org>
parents:
10490
diff
changeset
|
467 ;; the * of the comment terminator. |
eeeae6ef626e
(c-forward-conditional):
Richard M. Stallman <rms@gnu.org>
parents:
10490
diff
changeset
|
468 (if (looking-at "[ \t]*\\*/") |
eeeae6ef626e
(c-forward-conditional):
Richard M. Stallman <rms@gnu.org>
parents:
10490
diff
changeset
|
469 (narrow-to-region (point-min) (point))) |
5689
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
470 (fill-paragraph arg) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
471 (save-excursion |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
472 ;; Delete the chars we inserted to avoid clobbering |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
473 ;; the stuff before the comment start. |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
474 (goto-char (point-min)) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
475 (if (> chars-to-delete 0) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
476 (delete-region (point) (+ (point) chars-to-delete))) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
477 ;; Find the comment ender (should be on last line of buffer, |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
478 ;; given the narrowing) and don't leave it on its own line. |
6190
23e31de31f47
(c-fill-paragraph): Preserve final sentence boundary.
Karl Heuer <kwzh@gnu.org>
parents:
6074
diff
changeset
|
479 ;; Do this with a fill command, so as to preserve sentence |
23e31de31f47
(c-fill-paragraph): Preserve final sentence boundary.
Karl Heuer <kwzh@gnu.org>
parents:
6074
diff
changeset
|
480 ;; boundaries. |
5689
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
481 (goto-char (point-max)) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
482 (forward-line -1) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
483 (search-forward "*/" nil 'move) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
484 (beginning-of-line) |
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
485 (if (looking-at "[ \t]*\\*/") |
6190
23e31de31f47
(c-fill-paragraph): Preserve final sentence boundary.
Karl Heuer <kwzh@gnu.org>
parents:
6074
diff
changeset
|
486 (let ((fill-column (+ fill-column 9999))) |
23e31de31f47
(c-fill-paragraph): Preserve final sentence boundary.
Karl Heuer <kwzh@gnu.org>
parents:
6074
diff
changeset
|
487 (forward-line -1) |
23e31de31f47
(c-fill-paragraph): Preserve final sentence boundary.
Karl Heuer <kwzh@gnu.org>
parents:
6074
diff
changeset
|
488 (fill-region-as-paragraph (point) (point-max))))))) |
5689
4a3125e60737
(c-fill-paragraph): Handle C++ mode.
Richard M. Stallman <rms@gnu.org>
parents:
5540
diff
changeset
|
489 ;; Outside of comments: do ordinary filling. |
10630
3e851e5cab1f
(c-mode-map): No binding for c-fill-paragraph
Richard M. Stallman <rms@gnu.org>
parents:
10544
diff
changeset
|
490 (fill-paragraph arg))) |
3e851e5cab1f
(c-mode-map): No binding for c-fill-paragraph
Richard M. Stallman <rms@gnu.org>
parents:
10544
diff
changeset
|
491 t)) |
453 | 492 |
493 (defun electric-c-brace (arg) | |
494 "Insert character and correct line's indentation." | |
495 (interactive "P") | |
496 (let (insertpos) | |
497 (if (and (not arg) | |
498 (eolp) | |
499 (or (save-excursion | |
500 (skip-chars-backward " \t") | |
501 (bolp)) | |
502 (if c-auto-newline (progn (c-indent-line) (newline) t) nil))) | |
503 (progn | |
504 (insert last-command-char) | |
505 (c-indent-line) | |
506 (if c-auto-newline | |
507 (progn | |
508 (newline) | |
509 ;; (newline) may have done auto-fill | |
510 (setq insertpos (- (point) 2)) | |
511 (c-indent-line))) | |
512 (save-excursion | |
513 (if insertpos (goto-char (1+ insertpos))) | |
514 (delete-char -1)))) | |
515 (if insertpos | |
516 (save-excursion | |
517 (goto-char insertpos) | |
518 (self-insert-command (prefix-numeric-value arg))) | |
519 (self-insert-command (prefix-numeric-value arg))))) | |
520 | |
521 (defun electric-c-sharp-sign (arg) | |
522 "Insert character and correct line's indentation." | |
523 (interactive "P") | |
524 (if (save-excursion | |
525 (skip-chars-backward " \t") | |
526 (bolp)) | |
527 (let ((c-auto-newline nil)) | |
528 (electric-c-terminator arg)) | |
529 (self-insert-command (prefix-numeric-value arg)))) | |
530 | |
531 (defun electric-c-semi (arg) | |
532 "Insert character and correct line's indentation." | |
533 (interactive "P") | |
534 (if c-auto-newline | |
535 (electric-c-terminator arg) | |
536 (self-insert-command (prefix-numeric-value arg)))) | |
537 | |
538 (defun electric-c-terminator (arg) | |
539 "Insert character and correct line's indentation." | |
540 (interactive "P") | |
541 (let (insertpos (end (point))) | |
542 (if (and (not arg) (eolp) | |
543 (not (save-excursion | |
544 (beginning-of-line) | |
545 (skip-chars-forward " \t") | |
546 (or (= (following-char) ?#) | |
547 ;; Colon is special only after a label, or case .... | |
548 ;; So quickly rule out most other uses of colon | |
549 ;; and do no indentation for them. | |
550 (and (eq last-command-char ?:) | |
1804
fe2bebf150c7
* c-mode.el (c-switch-label-regexp): New constant.
Jim Blandy <jimb@redhat.com>
parents:
1701
diff
changeset
|
551 (not (looking-at c-switch-label-regexp)) |
453 | 552 (save-excursion |
553 (skip-chars-forward "a-zA-Z0-9_$") | |
554 (skip-chars-forward " \t") | |
555 (< (point) end))) | |
556 (progn | |
557 (beginning-of-defun) | |
558 (let ((pps (parse-partial-sexp (point) end))) | |
559 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))))) | |
560 (progn | |
561 (insert last-command-char) | |
562 (c-indent-line) | |
563 (and c-auto-newline | |
564 (not (c-inside-parens-p)) | |
565 (progn | |
566 (newline) | |
567 ;; (newline) may have done auto-fill | |
568 (setq insertpos (- (point) 2)) | |
569 (c-indent-line))) | |
570 (save-excursion | |
571 (if insertpos (goto-char (1+ insertpos))) | |
572 (delete-char -1)))) | |
573 (if insertpos | |
574 (save-excursion | |
575 (goto-char insertpos) | |
576 (self-insert-command (prefix-numeric-value arg))) | |
577 (self-insert-command (prefix-numeric-value arg))))) | |
578 | |
579 (defun c-inside-parens-p () | |
580 (condition-case () | |
581 (save-excursion | |
582 (save-restriction | |
583 (narrow-to-region (point) | |
584 (progn (beginning-of-defun) (point))) | |
585 (goto-char (point-max)) | |
586 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\())) | |
587 (error nil))) | |
588 | |
589 (defun c-indent-command (&optional whole-exp) | |
590 "Indent current line as C code, or in some cases insert a tab character. | |
591 If `c-tab-always-indent' is non-nil (the default), always indent current line. | |
592 Otherwise, indent the current line only if point is at the left margin or | |
593 in the line's indentation; otherwise insert a tab. | |
594 | |
595 A numeric argument, regardless of its value, means indent rigidly all the | |
596 lines of the expression starting after point so that this line becomes | |
597 properly indented. The relative indentation among the lines of the | |
598 expression are preserved." | |
599 (interactive "P") | |
600 (if whole-exp | |
601 ;; If arg, always indent this line as C | |
602 ;; and shift remaining lines of expression the same amount. | |
603 (let ((shift-amt (c-indent-line)) | |
604 beg end) | |
605 (save-excursion | |
606 (if c-tab-always-indent | |
607 (beginning-of-line)) | |
608 ;; Find beginning of following line. | |
609 (save-excursion | |
610 (forward-line 1) (setq beg (point))) | |
611 ;; Find first beginning-of-sexp for sexp extending past this line. | |
612 (while (< (point) beg) | |
613 (forward-sexp 1) | |
614 (setq end (point)) | |
615 (skip-chars-forward " \t\n"))) | |
616 (if (> end beg) | |
617 (indent-code-rigidly beg end shift-amt "#"))) | |
618 (if (and (not c-tab-always-indent) | |
619 (save-excursion | |
620 (skip-chars-backward " \t") | |
621 (not (bolp)))) | |
622 (insert-tab) | |
623 (c-indent-line)))) | |
624 | |
625 (defun c-indent-line () | |
626 "Indent current line as C code. | |
627 Return the amount the indentation changed by." | |
628 (let ((indent (calculate-c-indent nil)) | |
629 beg shift-amt | |
630 (case-fold-search nil) | |
631 (pos (- (point-max) (point)))) | |
632 (beginning-of-line) | |
633 (setq beg (point)) | |
634 (cond ((eq indent nil) | |
635 (setq indent (current-indentation))) | |
636 ((eq indent t) | |
637 (setq indent (calculate-c-indent-within-comment))) | |
638 ((looking-at "[ \t]*#") | |
639 (setq indent 0)) | |
640 (t | |
641 (skip-chars-forward " \t") | |
642 (if (listp indent) (setq indent (car indent))) | |
1804
fe2bebf150c7
* c-mode.el (c-switch-label-regexp): New constant.
Jim Blandy <jimb@redhat.com>
parents:
1701
diff
changeset
|
643 (cond ((or (looking-at c-switch-label-regexp) |
453 | 644 (and (looking-at "[A-Za-z]") |
645 (save-excursion | |
646 (forward-sexp 1) | |
647 (looking-at ":")))) | |
648 (setq indent (max 1 (+ indent c-label-offset)))) | |
649 ((and (looking-at "else\\b") | |
650 (not (looking-at "else\\s_"))) | |
651 (setq indent (save-excursion | |
652 (c-backward-to-start-of-if) | |
653 (current-indentation)))) | |
10182
b80150d748d1
(indent-c-exp): Don't be fooled by else_ or while_.
Richard M. Stallman <rms@gnu.org>
parents:
10075
diff
changeset
|
654 ((and (looking-at "}[ \t]*else\\b") |
b80150d748d1
(indent-c-exp): Don't be fooled by else_ or while_.
Richard M. Stallman <rms@gnu.org>
parents:
10075
diff
changeset
|
655 (not (looking-at "}[ \t]*else\\s_"))) |
453 | 656 (setq indent (save-excursion |
657 (forward-char) | |
658 (backward-sexp) | |
3716
c8af07496d54
(c-indent-line): Call c-backward-to-start-of-if
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
659 (c-backward-to-start-of-if) |
453 | 660 (current-indentation)))) |
661 ((and (looking-at "while\\b") | |
10182
b80150d748d1
(indent-c-exp): Don't be fooled by else_ or while_.
Richard M. Stallman <rms@gnu.org>
parents:
10075
diff
changeset
|
662 (not (looking-at "while\\s_")) |
453 | 663 (save-excursion |
664 (c-backward-to-start-of-do))) | |
665 ;; This is a `while' that ends a do-while. | |
666 (setq indent (save-excursion | |
667 (c-backward-to-start-of-do) | |
668 (current-indentation)))) | |
669 ((= (following-char) ?}) | |
670 (setq indent (- indent c-indent-level))) | |
671 ((= (following-char) ?{) | |
672 (setq indent (+ indent c-brace-offset)))))) | |
673 (skip-chars-forward " \t") | |
674 (setq shift-amt (- indent (current-column))) | |
675 (if (zerop shift-amt) | |
676 (if (> (- (point-max) pos) (point)) | |
677 (goto-char (- (point-max) pos))) | |
678 (delete-region beg (point)) | |
679 (indent-to indent) | |
680 ;; If initial point was within line's indentation, | |
681 ;; position after the indentation. Else stay at same point in text. | |
682 (if (> (- (point-max) pos) (point)) | |
683 (goto-char (- (point-max) pos)))) | |
684 shift-amt)) | |
685 | |
686 (defun calculate-c-indent (&optional parse-start) | |
687 "Return appropriate indentation for current line as C code. | |
688 In usual case returns an integer: the column to indent to. | |
689 Returns nil if line starts inside a string, t if in a comment." | |
690 (save-excursion | |
691 (beginning-of-line) | |
692 (let ((indent-point (point)) | |
693 (case-fold-search nil) | |
694 state | |
695 containing-sexp) | |
696 (if parse-start | |
697 (goto-char parse-start) | |
698 (beginning-of-defun)) | |
699 (while (< (point) indent-point) | |
700 (setq parse-start (point)) | |
701 (setq state (parse-partial-sexp (point) indent-point 0)) | |
702 (setq containing-sexp (car (cdr state)))) | |
703 (cond ((or (nth 3 state) (nth 4 state)) | |
704 ;; return nil or t if should not change this line | |
705 (nth 4 state)) | |
706 ((null containing-sexp) | |
707 ;; Line is at top level. May be data or function definition, | |
708 ;; or may be function argument declaration. | |
709 ;; Indent like the previous top level line | |
710 ;; unless that ends in a closeparen without semicolon, | |
711 ;; in which case this line is the first argument decl. | |
712 (goto-char indent-point) | |
713 (skip-chars-forward " \t") | |
714 (if (= (following-char) ?{) | |
715 0 ; Unless it starts a function body | |
716 (c-backward-to-noncomment (or parse-start (point-min))) | |
717 ;; Look at previous line that's at column 0 | |
718 ;; to determine whether we are in top-level decls | |
719 ;; or function's arg decls. Set basic-indent accordingly. | |
720 (let ((basic-indent | |
721 (save-excursion | |
722 (re-search-backward "^[^ \^L\t\n#]" nil 'move) | |
759
58b7fc91b74a
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
662
diff
changeset
|
723 (let (comment lim) |
1064
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
724 ;; Recognize the DEFUN macro in Emacs. |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
725 (if (save-excursion |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
726 ;; Move down to the (putative) argnames line. |
1184 | 727 (while (and (not (eobp)) |
728 (not (looking-at " *[({}#/]"))) | |
1064
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
729 (forward-line 1)) |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
730 ;; Go back to the DEFUN, if it is one. |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
731 (condition-case nil |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
732 (backward-sexp 1) |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
733 (error)) |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
734 (beginning-of-line) |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
735 (looking-at "DEFUN\\b")) |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
736 c-argdecl-indent |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
737 (if (and (looking-at "\\sw\\|\\s_") |
1205
56d315ca10ee
(calculate-c-indent): When testing for function-start line,
Richard M. Stallman <rms@gnu.org>
parents:
1184
diff
changeset
|
738 ;; This is careful to stop at the first |
56d315ca10ee
(calculate-c-indent): When testing for function-start line,
Richard M. Stallman <rms@gnu.org>
parents:
1184
diff
changeset
|
739 ;; paren if we have |
56d315ca10ee
(calculate-c-indent): When testing for function-start line,
Richard M. Stallman <rms@gnu.org>
parents:
1184
diff
changeset
|
740 ;; int foo Proto ((int, int)); |
56d315ca10ee
(calculate-c-indent): When testing for function-start line,
Richard M. Stallman <rms@gnu.org>
parents:
1184
diff
changeset
|
741 (looking-at "[^\"\n=(]*(") |
1064
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
742 (progn |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
743 (goto-char (1- (match-end 0))) |
10075
bf0eb7f0717b
(calculate-c-indent): Handle a top-level decl with multiple paren groups.
Richard M. Stallman <rms@gnu.org>
parents:
9468
diff
changeset
|
744 ;; Skip any number of paren-groups. |
bf0eb7f0717b
(calculate-c-indent): Handle a top-level decl with multiple paren groups.
Richard M. Stallman <rms@gnu.org>
parents:
9468
diff
changeset
|
745 ;; Consider typedef int (*fcn) (int); |
bf0eb7f0717b
(calculate-c-indent): Handle a top-level decl with multiple paren groups.
Richard M. Stallman <rms@gnu.org>
parents:
9468
diff
changeset
|
746 (while (= (following-char) ?\() |
bf0eb7f0717b
(calculate-c-indent): Handle a top-level decl with multiple paren groups.
Richard M. Stallman <rms@gnu.org>
parents:
9468
diff
changeset
|
747 (setq lim (point)) |
bf0eb7f0717b
(calculate-c-indent): Handle a top-level decl with multiple paren groups.
Richard M. Stallman <rms@gnu.org>
parents:
9468
diff
changeset
|
748 (condition-case nil |
bf0eb7f0717b
(calculate-c-indent): Handle a top-level decl with multiple paren groups.
Richard M. Stallman <rms@gnu.org>
parents:
9468
diff
changeset
|
749 (forward-sexp 1) |
bf0eb7f0717b
(calculate-c-indent): Handle a top-level decl with multiple paren groups.
Richard M. Stallman <rms@gnu.org>
parents:
9468
diff
changeset
|
750 (error)) |
bf0eb7f0717b
(calculate-c-indent): Handle a top-level decl with multiple paren groups.
Richard M. Stallman <rms@gnu.org>
parents:
9468
diff
changeset
|
751 (skip-chars-forward " \t\f")) |
bf0eb7f0717b
(calculate-c-indent): Handle a top-level decl with multiple paren groups.
Richard M. Stallman <rms@gnu.org>
parents:
9468
diff
changeset
|
752 ;; Have we reached something |
bf0eb7f0717b
(calculate-c-indent): Handle a top-level decl with multiple paren groups.
Richard M. Stallman <rms@gnu.org>
parents:
9468
diff
changeset
|
753 ;; that shows this isn't a function |
bf0eb7f0717b
(calculate-c-indent): Handle a top-level decl with multiple paren groups.
Richard M. Stallman <rms@gnu.org>
parents:
9468
diff
changeset
|
754 ;; definition? |
1064
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
755 (and (< (point) indent-point) |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
756 (not (memq (following-char) |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
757 '(?\, ?\;))))) |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
758 ;; Make sure the "function decl" we found |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
759 ;; is not inside a comment. |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
760 (progn |
4333
c356a81e1a46
(calculate-c-indent): When checking whether function decl
Richard M. Stallman <rms@gnu.org>
parents:
4286
diff
changeset
|
761 ;; Move back to the `(' starting arglist |
c356a81e1a46
(calculate-c-indent): When checking whether function decl
Richard M. Stallman <rms@gnu.org>
parents:
4286
diff
changeset
|
762 (goto-char lim) |
1064
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
763 (beginning-of-line) |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
764 (while (and (not comment) |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
765 (search-forward "/*" lim t)) |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
766 (setq comment |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
767 (not (search-forward "*/" lim t)))) |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
768 (not comment))) |
e699ce19609f
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
1054
diff
changeset
|
769 c-argdecl-indent 0)))))) |
453 | 770 basic-indent))) |
771 | |
772 ;; ;; Now add a little if this is a continuation line. | |
773 ;; (+ basic-indent (if (or (bobp) | |
774 ;; (memq (preceding-char) '(?\) ?\; ?\})) | |
775 ;; ;; Line with zero indentation | |
776 ;; ;; is probably the return-type | |
777 ;; ;; of a function definition, | |
778 ;; ;; so following line is function name. | |
779 ;; (= (current-indentation) 0)) | |
780 ;; 0 c-continued-statement-offset)) | |
781 | |
782 ((/= (char-after containing-sexp) ?{) | |
783 ;; line is expression, not statement: | |
784 ;; indent to just after the surrounding open. | |
785 (goto-char (1+ containing-sexp)) | |
786 (current-column)) | |
787 (t | |
788 ;; Statement level. Is it a continuation or a new statement? | |
789 ;; Find previous non-comment character. | |
790 (goto-char indent-point) | |
791 (c-backward-to-noncomment containing-sexp) | |
792 ;; Back up over label lines, since they don't | |
793 ;; affect whether our line is a continuation. | |
794 (while (or (eq (preceding-char) ?\,) | |
795 (and (eq (preceding-char) ?:) | |
796 (or (eq (char-after (- (point) 2)) ?\') | |
797 (memq (char-syntax (char-after (- (point) 2))) | |
798 '(?w ?_))))) | |
799 (if (eq (preceding-char) ?\,) | |
800 (progn (forward-char -1) | |
801 (c-backward-to-start-of-continued-exp containing-sexp))) | |
802 (beginning-of-line) | |
803 (c-backward-to-noncomment containing-sexp)) | |
804 ;; Check for a preprocessor statement or its continuation lines. | |
6579
51a7a67cd4c2
(calculate-c-indent): Don't loop forever at bobp.
Karl Heuer <kwzh@gnu.org>
parents:
6190
diff
changeset
|
805 ;; Move back to end of previous non-preprocessor line, |
51a7a67cd4c2
(calculate-c-indent): Don't loop forever at bobp.
Karl Heuer <kwzh@gnu.org>
parents:
6190
diff
changeset
|
806 ;; or possibly beginning of buffer. |
453 | 807 (let ((found (point)) stop) |
808 (while (not stop) | |
6579
51a7a67cd4c2
(calculate-c-indent): Don't loop forever at bobp.
Karl Heuer <kwzh@gnu.org>
parents:
6190
diff
changeset
|
809 (beginning-of-line) |
51a7a67cd4c2
(calculate-c-indent): Don't loop forever at bobp.
Karl Heuer <kwzh@gnu.org>
parents:
6190
diff
changeset
|
810 (cond ((bobp) |
51a7a67cd4c2
(calculate-c-indent): Don't loop forever at bobp.
Karl Heuer <kwzh@gnu.org>
parents:
6190
diff
changeset
|
811 (setq found (point) |
51a7a67cd4c2
(calculate-c-indent): Don't loop forever at bobp.
Karl Heuer <kwzh@gnu.org>
parents:
6190
diff
changeset
|
812 stop t)) |
51a7a67cd4c2
(calculate-c-indent): Don't loop forever at bobp.
Karl Heuer <kwzh@gnu.org>
parents:
6190
diff
changeset
|
813 ((save-excursion (forward-char -1) |
453 | 814 (= (preceding-char) ?\\)) |
6579
51a7a67cd4c2
(calculate-c-indent): Don't loop forever at bobp.
Karl Heuer <kwzh@gnu.org>
parents:
6190
diff
changeset
|
815 (forward-char -1)) |
453 | 816 ;; This line is not preceded by a backslash. |
817 ;; So either it starts a preprocessor command | |
818 ;; or any following continuation lines | |
819 ;; should not be skipped. | |
6579
51a7a67cd4c2
(calculate-c-indent): Don't loop forever at bobp.
Karl Heuer <kwzh@gnu.org>
parents:
6190
diff
changeset
|
820 ((= (following-char) ?#) |
51a7a67cd4c2
(calculate-c-indent): Don't loop forever at bobp.
Karl Heuer <kwzh@gnu.org>
parents:
6190
diff
changeset
|
821 (forward-char -1) |
453 | 822 (setq found (point))) |
823 (t (setq stop t)))) | |
824 (goto-char found)) | |
825 ;; Now we get the answer. | |
6579
51a7a67cd4c2
(calculate-c-indent): Don't loop forever at bobp.
Karl Heuer <kwzh@gnu.org>
parents:
6190
diff
changeset
|
826 (if (and (not (memq (preceding-char) '(0 ?\, ?\; ?\} ?\{))) |
453 | 827 ;; But don't treat a line with a close-brace |
828 ;; as a continuation. It is probably the | |
829 ;; end of an enum type declaration. | |
830 (save-excursion | |
831 (goto-char indent-point) | |
832 (skip-chars-forward " \t") | |
833 (not (= (following-char) ?})))) | |
834 ;; This line is continuation of preceding line's statement; | |
835 ;; indent c-continued-statement-offset more than the | |
836 ;; previous line of the statement. | |
837 (progn | |
838 (c-backward-to-start-of-continued-exp containing-sexp) | |
839 (+ c-continued-statement-offset (current-column) | |
840 (if (save-excursion (goto-char indent-point) | |
841 (skip-chars-forward " \t") | |
842 (eq (following-char) ?{)) | |
843 c-continued-brace-offset 0))) | |
844 ;; This line starts a new statement. | |
845 ;; Position following last unclosed open. | |
846 (goto-char containing-sexp) | |
847 ;; Is line first statement after an open-brace? | |
848 (or | |
849 ;; If no, find that first statement and indent like it. | |
850 (save-excursion | |
851 (forward-char 1) | |
852 (let ((colon-line-end 0)) | |
853 (while (progn (skip-chars-forward " \t\n") | |
854 (looking-at "#\\|/\\*\\|case[ \t\n'/(].*:\\|[a-zA-Z0-9_$]*:")) | |
855 ;; Skip over comments and labels following openbrace. | |
856 (cond ((= (following-char) ?\#) | |
857 (forward-line 1)) | |
858 ((= (following-char) ?\/) | |
859 (forward-char 2) | |
860 (search-forward "*/" nil 'move)) | |
861 ;; case or label: | |
862 (t | |
863 (save-excursion (end-of-line) | |
864 (setq colon-line-end (point))) | |
865 (search-forward ":")))) | |
866 ;; The first following code counts | |
867 ;; if it is before the line we want to indent. | |
868 (and (< (point) indent-point) | |
1054
f6f13367d93c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
909
diff
changeset
|
869 (- |
f6f13367d93c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
909
diff
changeset
|
870 (if (> colon-line-end (point)) |
f6f13367d93c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
909
diff
changeset
|
871 (- (current-indentation) c-label-offset) |
f6f13367d93c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
909
diff
changeset
|
872 (current-column)) |
f6f13367d93c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
909
diff
changeset
|
873 ;; If prev stmt starts with open-brace, that |
f6f13367d93c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
909
diff
changeset
|
874 ;; open brace was offset by c-brace-offset. |
f6f13367d93c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
909
diff
changeset
|
875 ;; Compensate to get the column where |
f6f13367d93c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
909
diff
changeset
|
876 ;; an ordinary statement would start. |
f6f13367d93c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
909
diff
changeset
|
877 (if (= (following-char) ?\{) c-brace-offset 0))))) |
453 | 878 ;; If no previous statement, |
879 ;; indent it relative to line brace is on. | |
880 ;; For open brace in column zero, don't let statement | |
881 ;; start there too. If c-indent-level is zero, | |
882 ;; use c-brace-offset + c-continued-statement-offset instead. | |
883 ;; For open-braces not the first thing in a line, | |
884 ;; add in c-brace-imaginary-offset. | |
885 (+ (if (and (bolp) (zerop c-indent-level)) | |
886 (+ c-brace-offset c-continued-statement-offset) | |
887 c-indent-level) | |
888 ;; Move back over whitespace before the openbrace. | |
889 ;; If openbrace is not first nonwhite thing on the line, | |
890 ;; add the c-brace-imaginary-offset. | |
891 (progn (skip-chars-backward " \t") | |
892 (if (bolp) 0 c-brace-imaginary-offset)) | |
893 ;; If the openbrace is preceded by a parenthesized exp, | |
894 ;; move to the beginning of that; | |
895 ;; possibly a different line | |
896 (progn | |
897 (if (eq (preceding-char) ?\)) | |
898 (forward-sexp -1)) | |
899 ;; Get initial indentation of the line we are on. | |
900 (current-indentation)))))))))) | |
901 | |
902 (defun calculate-c-indent-within-comment (&optional after-star) | |
903 "Return the indentation amount for line inside a block comment. | |
904 Optional arg AFTER-STAR means, if lines in the comment have a leading star, | |
905 return the indentation of the text that would follow this star." | |
906 (let (end star-start) | |
907 (save-excursion | |
908 (beginning-of-line) | |
909 (skip-chars-forward " \t") | |
910 (setq star-start (= (following-char) ?\*)) | |
911 (skip-chars-backward " \t\n") | |
912 (setq end (point)) | |
913 (beginning-of-line) | |
914 (skip-chars-forward " \t") | |
915 (if after-star | |
916 (and (looking-at "\\*") | |
917 (re-search-forward "\\*[ \t]*"))) | |
918 (and (re-search-forward "/\\*[ \t]*" end t) | |
919 star-start | |
920 (not after-star) | |
921 (goto-char (1+ (match-beginning 0)))) | |
922 (if (and (looking-at "[ \t]*$") (= (preceding-char) ?\*)) | |
923 (1+ (current-column)) | |
924 (current-column))))) | |
925 | |
926 | |
927 (defun c-backward-to-noncomment (lim) | |
928 (let (opoint stop) | |
929 (while (not stop) | |
930 (skip-chars-backward " \t\n\f" lim) | |
931 (setq opoint (point)) | |
932 (if (and (>= (point) (+ 2 lim)) | |
933 (save-excursion | |
934 (forward-char -2) | |
935 (looking-at "\\*/"))) | |
936 (search-backward "/*" lim 'move) | |
937 (setq stop (or (<= (point) lim) | |
938 (save-excursion | |
939 (beginning-of-line) | |
940 (skip-chars-forward " \t") | |
941 (not (looking-at "#"))))) | |
942 (or stop (beginning-of-line)))))) | |
943 | |
944 (defun c-backward-to-start-of-continued-exp (lim) | |
945 (if (memq (preceding-char) '(?\) ?\")) | |
946 (forward-sexp -1)) | |
947 (beginning-of-line) | |
948 (if (<= (point) lim) | |
949 (goto-char (1+ lim))) | |
950 (skip-chars-forward " \t")) | |
951 | |
952 (defun c-backward-to-start-of-if (&optional limit) | |
953 "Move to the start of the last \"unbalanced\" `if'." | |
954 (or limit (setq limit (save-excursion (beginning-of-defun) (point)))) | |
955 (let ((if-level 1) | |
956 (case-fold-search nil)) | |
957 (while (and (not (bobp)) (not (zerop if-level))) | |
958 (backward-sexp 1) | |
10182
b80150d748d1
(indent-c-exp): Don't be fooled by else_ or while_.
Richard M. Stallman <rms@gnu.org>
parents:
10075
diff
changeset
|
959 (cond ((and (looking-at "else\\b") |
b80150d748d1
(indent-c-exp): Don't be fooled by else_ or while_.
Richard M. Stallman <rms@gnu.org>
parents:
10075
diff
changeset
|
960 (not (looking-at "else\\s_"))) |
453 | 961 (setq if-level (1+ if-level))) |
10182
b80150d748d1
(indent-c-exp): Don't be fooled by else_ or while_.
Richard M. Stallman <rms@gnu.org>
parents:
10075
diff
changeset
|
962 ((and (looking-at "if\\b") |
b80150d748d1
(indent-c-exp): Don't be fooled by else_ or while_.
Richard M. Stallman <rms@gnu.org>
parents:
10075
diff
changeset
|
963 (not (looking-at "if\\s_"))) |
453 | 964 (setq if-level (1- if-level))) |
965 ((< (point) limit) | |
966 (setq if-level 0) | |
967 (goto-char limit)))))) | |
968 | |
969 (defun c-backward-to-start-of-do (&optional limit) | |
970 "If point follows a `do' statement, move to beginning of it and return t. | |
971 Otherwise return nil and don't move point." | |
972 (or limit (setq limit (save-excursion (beginning-of-defun) (point)))) | |
973 (let ((first t) | |
974 (startpos (point)) | |
975 (done nil)) | |
976 (while (not done) | |
977 (let ((next-start (point))) | |
978 (condition-case nil | |
979 ;; Move back one token or one brace or paren group. | |
980 (backward-sexp 1) | |
981 ;; If we find an open-brace, we lose. | |
982 (error (setq done 'fail))) | |
983 (if done | |
984 nil | |
985 ;; If we reached a `do', we win. | |
986 (if (looking-at "do\\b") | |
987 (setq done 'succeed) | |
988 ;; Otherwise, if we skipped a semicolon, we lose. | |
989 ;; (Exception: we can skip one semicolon before getting | |
990 ;; to a the last token of the statement, unless that token | |
991 ;; is a close brace.) | |
992 (if (save-excursion | |
993 (forward-sexp 1) | |
994 (or (and (not first) (= (preceding-char) ?})) | |
995 (search-forward ";" next-start t | |
996 (if (and first | |
997 (/= (preceding-char) ?})) | |
998 2 1)))) | |
999 (setq done 'fail) | |
1000 (setq first nil) | |
1001 ;; If we go too far back in the buffer, we lose. | |
1002 (if (< (point) limit) | |
1003 (setq done 'fail))))))) | |
1004 (if (eq done 'succeed) | |
1005 t | |
1006 (goto-char startpos) | |
1007 nil))) | |
1008 | |
1009 (defun c-beginning-of-statement (count) | |
1010 "Go to the beginning of the innermost C statement. | |
1011 With prefix arg, go back N - 1 statements. If already at the beginning of a | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3256
diff
changeset
|
1012 statement then go to the beginning of the preceding one. |
2084
9561d2584cbb
(c-beginning-of-statement): If next to a comment, use sentence motion.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
1013 If within a string or comment, or next to a comment (only whitespace between), |
9561d2584cbb
(c-beginning-of-statement): If next to a comment, use sentence motion.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
1014 move by sentences instead of statements." |
453 | 1015 (interactive "p") |
871
34b6b37092c7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
861
diff
changeset
|
1016 (let ((here (point)) state) |
34b6b37092c7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
861
diff
changeset
|
1017 (save-excursion |
34b6b37092c7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
861
diff
changeset
|
1018 (beginning-of-defun) |
34b6b37092c7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
861
diff
changeset
|
1019 (setq state (parse-partial-sexp (point) here nil nil))) |
2084
9561d2584cbb
(c-beginning-of-statement): If next to a comment, use sentence motion.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
1020 (if (or (nth 3 state) (nth 4 state) |
9561d2584cbb
(c-beginning-of-statement): If next to a comment, use sentence motion.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
1021 (looking-at (concat "[ \t]*" comment-start-skip)) |
9561d2584cbb
(c-beginning-of-statement): If next to a comment, use sentence motion.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
1022 (save-excursion (skip-chars-backward " \t") |
9561d2584cbb
(c-beginning-of-statement): If next to a comment, use sentence motion.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
1023 (goto-char (- (point) 2)) |
9561d2584cbb
(c-beginning-of-statement): If next to a comment, use sentence motion.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
1024 (looking-at "\\*/"))) |
871
34b6b37092c7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
861
diff
changeset
|
1025 (forward-sentence (- count)) |
34b6b37092c7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
861
diff
changeset
|
1026 (while (> count 0) |
34b6b37092c7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
861
diff
changeset
|
1027 (c-beginning-of-statement-1) |
34b6b37092c7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
861
diff
changeset
|
1028 (setq count (1- count))) |
34b6b37092c7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
861
diff
changeset
|
1029 (while (< count 0) |
34b6b37092c7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
861
diff
changeset
|
1030 (c-end-of-statement-1) |
34b6b37092c7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
861
diff
changeset
|
1031 (setq count (1+ count)))))) |
453 | 1032 |
1033 (defun c-end-of-statement (count) | |
1034 "Go to the end of the innermost C statement. | |
871
34b6b37092c7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
861
diff
changeset
|
1035 With prefix arg, go forward N - 1 statements. |
34b6b37092c7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
861
diff
changeset
|
1036 Move forward to end of the next statement if already at end. |
34b6b37092c7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
861
diff
changeset
|
1037 If within a string or comment, move by sentences instead of statements." |
453 | 1038 (interactive "p") |
1039 (c-beginning-of-statement (- count))) | |
1040 | |
1041 (defun c-beginning-of-statement-1 () | |
1042 (let ((last-begin (point)) | |
1043 (first t)) | |
1044 (condition-case () | |
1045 (progn | |
1046 (while (and (not (bobp)) | |
1047 (progn | |
1048 (backward-sexp 1) | |
1049 (or first | |
1050 (not (re-search-forward "[;{}]" last-begin t))))) | |
1051 (setq last-begin (point) first nil)) | |
1052 (goto-char last-begin)) | |
1053 (error (if first (backward-up-list 1) (goto-char last-begin)))))) | |
1054 | |
1055 (defun c-end-of-statement-1 () | |
1056 (condition-case () | |
1057 (progn | |
1058 (while (and (not (eobp)) | |
1059 (let ((beg (point))) | |
1060 (forward-sexp 1) | |
1061 (let ((end (point))) | |
1062 (save-excursion | |
1063 (goto-char beg) | |
1064 (not (re-search-forward "[;{}]" end t))))))) | |
1065 (re-search-backward "[;}]") | |
1066 (forward-char 1)) | |
1067 (error | |
1068 (let ((beg (point))) | |
1069 (backward-up-list -1) | |
1070 (let ((end (point))) | |
1071 (goto-char beg) | |
1072 (search-forward ";" end 'move)))))) | |
1073 | |
1074 (defun mark-c-function () | |
1075 "Put mark at end of C function, point at beginning." | |
1076 (interactive) | |
1077 (push-mark (point)) | |
1078 (end-of-defun) | |
2829
688e57a7ade8
(mark-c-function): Activate the mark.
Richard M. Stallman <rms@gnu.org>
parents:
2307
diff
changeset
|
1079 (push-mark (point) nil t) |
453 | 1080 (beginning-of-defun) |
1081 (backward-paragraph)) | |
1082 | |
4419
e7348af6762b
(indent-c-exp): Don't document ENDPOS.
Richard M. Stallman <rms@gnu.org>
parents:
4388
diff
changeset
|
1083 ;; Idea of ENDPOS is, indent each line, stopping when |
e7348af6762b
(indent-c-exp): Don't document ENDPOS.
Richard M. Stallman <rms@gnu.org>
parents:
4388
diff
changeset
|
1084 ;; ENDPOS is encountered. But it's too much of a pain to make that work. |
453 | 1085 (defun indent-c-exp (&optional endpos) |
4419
e7348af6762b
(indent-c-exp): Don't document ENDPOS.
Richard M. Stallman <rms@gnu.org>
parents:
4388
diff
changeset
|
1086 "Indent each line of the C grouping following point." |
453 | 1087 (interactive) |
1088 (let* ((indent-stack (list nil)) | |
1089 (opoint (point)) ;; May be altered below. | |
1090 (contain-stack | |
1091 (list (if endpos | |
1092 (let (funbeg) | |
1093 ;; Find previous fcn-start. | |
1094 (save-excursion (forward-char 1) | |
1095 (beginning-of-defun) | |
1096 (setq funbeg (point))) | |
4201
8b53e0fa08b4
(indent-c-exp): If ENDPOS, always set OPOINT
Richard M. Stallman <rms@gnu.org>
parents:
3906
diff
changeset
|
1097 (setq opoint funbeg) |
453 | 1098 ;; Try to find containing open, |
1099 ;; but don't scan past that fcn-start. | |
1100 (save-restriction | |
1101 (narrow-to-region funbeg (point)) | |
1102 (condition-case nil | |
1103 (save-excursion | |
4201
8b53e0fa08b4
(indent-c-exp): If ENDPOS, always set OPOINT
Richard M. Stallman <rms@gnu.org>
parents:
3906
diff
changeset
|
1104 (backward-up-list 1) |
8b53e0fa08b4
(indent-c-exp): If ENDPOS, always set OPOINT
Richard M. Stallman <rms@gnu.org>
parents:
3906
diff
changeset
|
1105 (point)) |
453 | 1106 ;; We gave up: must be between fcns. |
1107 ;; Set opoint to beg of prev fcn | |
1108 ;; since otherwise calculate-c-indent | |
1109 ;; will get wrong answers. | |
1110 (error (setq opoint funbeg) | |
1111 (point))))) | |
1112 (point)))) | |
1113 (case-fold-search nil) | |
1114 restart outer-loop-done inner-loop-done state ostate | |
1115 this-indent last-sexp | |
1116 at-else at-brace at-while | |
4286
d719788a0aaa
(indent-c-exp): When previous line ends in comma,
Richard M. Stallman <rms@gnu.org>
parents:
4202
diff
changeset
|
1117 last-depth this-point |
453 | 1118 (next-depth 0)) |
1119 ;; If the braces don't match, get an error right away. | |
1120 (save-excursion | |
1121 (forward-sexp 1)) | |
1122 ;; Realign the comment on the first line, even though we don't reindent it. | |
1123 (save-excursion | |
1124 (let ((beg (point))) | |
1125 (and (re-search-forward | |
1126 comment-start-skip | |
1127 (save-excursion (end-of-line) (point)) t) | |
4201
8b53e0fa08b4
(indent-c-exp): If ENDPOS, always set OPOINT
Richard M. Stallman <rms@gnu.org>
parents:
3906
diff
changeset
|
1128 ;; Make sure this isn't a comment alone on a line |
8b53e0fa08b4
(indent-c-exp): If ENDPOS, always set OPOINT
Richard M. Stallman <rms@gnu.org>
parents:
3906
diff
changeset
|
1129 ;; (which should be indented like code instead). |
8b53e0fa08b4
(indent-c-exp): If ENDPOS, always set OPOINT
Richard M. Stallman <rms@gnu.org>
parents:
3906
diff
changeset
|
1130 (save-excursion |
8b53e0fa08b4
(indent-c-exp): If ENDPOS, always set OPOINT
Richard M. Stallman <rms@gnu.org>
parents:
3906
diff
changeset
|
1131 (goto-char (match-beginning 0)) |
8b53e0fa08b4
(indent-c-exp): If ENDPOS, always set OPOINT
Richard M. Stallman <rms@gnu.org>
parents:
3906
diff
changeset
|
1132 (skip-chars-backward " \t") |
8b53e0fa08b4
(indent-c-exp): If ENDPOS, always set OPOINT
Richard M. Stallman <rms@gnu.org>
parents:
3906
diff
changeset
|
1133 (not (bolp))) |
453 | 1134 ;; Make sure the comment starter we found |
1135 ;; is not actually in a string or quoted. | |
1136 (let ((new-state | |
1137 (parse-partial-sexp beg (point) | |
1138 nil nil state))) | |
1139 (and (not (nth 3 new-state)) (not (nth 5 new-state)))) | |
1140 (progn (indent-for-comment) (beginning-of-line))))) | |
1141 (save-excursion | |
1142 (setq outer-loop-done nil) | |
1143 (while (and (not (eobp)) | |
1144 (if endpos (< (point) endpos) | |
1145 (not outer-loop-done))) | |
1146 (setq last-depth next-depth) | |
1147 ;; Compute how depth changes over this line | |
1148 ;; plus enough other lines to get to one that | |
1149 ;; does not end inside a comment or string. | |
1150 ;; Meanwhile, do appropriate indentation on comment lines. | |
1151 (setq inner-loop-done nil) | |
1152 (while (and (not inner-loop-done) | |
1153 (not (and (eobp) (setq outer-loop-done t)))) | |
1154 (setq ostate state) | |
1155 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point)) | |
1156 nil nil state)) | |
1157 (setq next-depth (car state)) | |
1158 (if (and (car (cdr (cdr state))) | |
1159 (>= (car (cdr (cdr state))) 0)) | |
1160 (setq last-sexp (car (cdr (cdr state))))) | |
4286
d719788a0aaa
(indent-c-exp): When previous line ends in comma,
Richard M. Stallman <rms@gnu.org>
parents:
4202
diff
changeset
|
1161 ;; If this line started within a comment, indent it as such. |
d719788a0aaa
(indent-c-exp): When previous line ends in comma,
Richard M. Stallman <rms@gnu.org>
parents:
4202
diff
changeset
|
1162 (if (or (nth 4 ostate) (nth 7 ostate)) |
453 | 1163 (c-indent-line)) |
4286
d719788a0aaa
(indent-c-exp): When previous line ends in comma,
Richard M. Stallman <rms@gnu.org>
parents:
4202
diff
changeset
|
1164 ;; If it ends outside of comments or strings, exit the inner loop. |
d719788a0aaa
(indent-c-exp): When previous line ends in comma,
Richard M. Stallman <rms@gnu.org>
parents:
4202
diff
changeset
|
1165 ;; Otherwise move on to next line. |
d719788a0aaa
(indent-c-exp): When previous line ends in comma,
Richard M. Stallman <rms@gnu.org>
parents:
4202
diff
changeset
|
1166 (if (or (nth 3 state) (nth 4 state) (nth 7 state)) |
453 | 1167 (forward-line 1) |
1168 (setq inner-loop-done t))) | |
1169 (and endpos | |
1170 (while (< next-depth 0) | |
1171 (setq indent-stack (append indent-stack (list nil))) | |
1172 (setq contain-stack (append contain-stack (list nil))) | |
1173 (setq next-depth (1+ next-depth)) | |
1174 (setq last-depth (1+ last-depth)) | |
1175 (setcar (nthcdr 6 state) (1+ (nth 6 state))))) | |
1176 (setq outer-loop-done (and (not endpos) (<= next-depth 0))) | |
1177 (if outer-loop-done | |
1178 nil | |
1179 ;; If this line had ..))) (((.. in it, pop out of the levels | |
1180 ;; that ended anywhere in this line, even if the final depth | |
1181 ;; doesn't indicate that they ended. | |
1182 (while (> last-depth (nth 6 state)) | |
1183 (setq indent-stack (cdr indent-stack) | |
1184 contain-stack (cdr contain-stack) | |
1185 last-depth (1- last-depth))) | |
1186 (if (/= last-depth next-depth) | |
1187 (setq last-sexp nil)) | |
1188 ;; Add levels for any parens that were started in this line. | |
1189 (while (< last-depth next-depth) | |
1190 (setq indent-stack (cons nil indent-stack) | |
1191 contain-stack (cons nil contain-stack) | |
1192 last-depth (1+ last-depth))) | |
1193 (if (null (car contain-stack)) | |
1194 (setcar contain-stack (or (car (cdr state)) | |
1195 (save-excursion (forward-sexp -1) | |
1196 (point))))) | |
1197 (forward-line 1) | |
1198 (skip-chars-forward " \t") | |
4201
8b53e0fa08b4
(indent-c-exp): If ENDPOS, always set OPOINT
Richard M. Stallman <rms@gnu.org>
parents:
3906
diff
changeset
|
1199 ;; Don't really reindent if the line is just whitespace, |
8b53e0fa08b4
(indent-c-exp): If ENDPOS, always set OPOINT
Richard M. Stallman <rms@gnu.org>
parents:
3906
diff
changeset
|
1200 ;; or if it is past the endpos. |
8b53e0fa08b4
(indent-c-exp): If ENDPOS, always set OPOINT
Richard M. Stallman <rms@gnu.org>
parents:
3906
diff
changeset
|
1201 ;; (The exit test in the outer while |
8b53e0fa08b4
(indent-c-exp): If ENDPOS, always set OPOINT
Richard M. Stallman <rms@gnu.org>
parents:
3906
diff
changeset
|
1202 ;; does not exit until we have passed the first line |
8b53e0fa08b4
(indent-c-exp): If ENDPOS, always set OPOINT
Richard M. Stallman <rms@gnu.org>
parents:
3906
diff
changeset
|
1203 ;; past the region.) |
8b53e0fa08b4
(indent-c-exp): If ENDPOS, always set OPOINT
Richard M. Stallman <rms@gnu.org>
parents:
3906
diff
changeset
|
1204 (if (or (eolp) (and endpos (>= (point) endpos))) |
453 | 1205 nil |
10410
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1206 ;; Is this line in a new nesting level? |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1207 ;; In other words, is this the first line that |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1208 ;; starts in the new level? |
453 | 1209 (if (and (car indent-stack) |
1210 (>= (car indent-stack) 0)) | |
10410
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1211 nil |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1212 ;; Yes. |
453 | 1213 ;; Compute the standard indent for this level. |
10410
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1214 (let (val) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1215 (if (= (char-after (car contain-stack)) ?{) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1216 (save-excursion |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1217 (goto-char (car contain-stack)) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1218 (setq val (+ c-indent-level (current-column)))) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1219 (setq val (calculate-c-indent |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1220 (if (car indent-stack) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1221 (- (car indent-stack)) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1222 opoint)))) |
4202
4d0dd361b49a
(indent-c-exp): Call calculate-c-indent-within-comment when appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
4201
diff
changeset
|
1223 ;; t means we are in a block comment and should |
4d0dd361b49a
(indent-c-exp): Call calculate-c-indent-within-comment when appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
4201
diff
changeset
|
1224 ;; calculate accordingly. |
4d0dd361b49a
(indent-c-exp): Call calculate-c-indent-within-comment when appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
4201
diff
changeset
|
1225 (if (eq val t) |
4d0dd361b49a
(indent-c-exp): Call calculate-c-indent-within-comment when appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
4201
diff
changeset
|
1226 (setq val (calculate-c-indent-within-comment))) |
10410
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1227 (setcar indent-stack val))) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1228 ;; Adjust indent of this individual line |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1229 ;; based on its predecessor. |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1230 ;; Handle continuation lines, if, else, while, and so on. |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1231 (if (/= (char-after (car contain-stack)) ?{) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1232 (setq this-indent (car indent-stack)) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1233 ;; Line is at statement level. |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1234 ;; Is it a new statement? Is it an else? |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1235 ;; Find last non-comment character before this line |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1236 (save-excursion |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1237 (setq this-point (point)) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1238 (setq at-else (and (looking-at "else\\b") |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1239 (not (looking-at "else\\s_")))) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1240 (setq at-brace (= (following-char) ?{)) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1241 (setq at-while (and (looking-at "while\\b") |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1242 (not (looking-at "while\\s_")))) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1243 (if (= (following-char) ?}) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1244 (setq this-indent (car indent-stack)) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1245 (c-backward-to-noncomment opoint) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1246 (if (not (memq (preceding-char) '(0 ?\, ?\; ?} ?: ?{))) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1247 ;; Preceding line did not end in comma or semi; |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1248 ;; indent this line c-continued-statement-offset |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1249 ;; more than previous. |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1250 (progn |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1251 (c-backward-to-start-of-continued-exp (car contain-stack)) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1252 (setq this-indent |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1253 (+ c-continued-statement-offset (current-column) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1254 (if at-brace c-continued-brace-offset 0)))) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1255 ;; Preceding line ended in comma or semi; |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1256 ;; use the standard indent for this level. |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1257 (cond (at-else (progn (c-backward-to-start-of-if opoint) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1258 (setq this-indent |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1259 (current-indentation)))) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1260 ((and at-while (c-backward-to-start-of-do opoint)) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1261 (setq this-indent (current-indentation))) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1262 ((eq (preceding-char) ?\,) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1263 (goto-char this-point) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1264 (setq this-indent (calculate-c-indent))) |
562c360a3f6c
(indent-c-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents:
10182
diff
changeset
|
1265 (t (setq this-indent (car indent-stack)))))))) |
453 | 1266 ;; Adjust line indentation according to its contents |
1804
fe2bebf150c7
* c-mode.el (c-switch-label-regexp): New constant.
Jim Blandy <jimb@redhat.com>
parents:
1701
diff
changeset
|
1267 (if (or (looking-at c-switch-label-regexp) |
453 | 1268 (and (looking-at "[A-Za-z]") |
1269 (save-excursion | |
1270 (forward-sexp 1) | |
1271 (looking-at ":")))) | |
1272 (setq this-indent (max 1 (+ this-indent c-label-offset)))) | |
1273 (if (= (following-char) ?}) | |
1274 (setq this-indent (- this-indent c-indent-level))) | |
1275 (if (= (following-char) ?{) | |
4979 | 1276 ;; Don't move an open-brace in column 0. |
1277 ;; This is good when constructs such as | |
1278 ;; `extern "C" {' surround a function definition | |
1279 ;; that should be indented as usual. | |
1280 ;; It is also good for nested functions. | |
1281 ;; It is bad when an open-brace is indented at column 0 | |
1282 ;; and you want to fix that, but we can't win 'em all. | |
4388
c020f9a57cfe
(indent-c-exp): Don't move an { from column 0.
Richard M. Stallman <rms@gnu.org>
parents:
4333
diff
changeset
|
1283 (if (zerop (current-column)) |
c020f9a57cfe
(indent-c-exp): Don't move an { from column 0.
Richard M. Stallman <rms@gnu.org>
parents:
4333
diff
changeset
|
1284 (setq this-indent 0) |
c020f9a57cfe
(indent-c-exp): Don't move an { from column 0.
Richard M. Stallman <rms@gnu.org>
parents:
4333
diff
changeset
|
1285 (setq this-indent (+ this-indent c-brace-offset)))) |
453 | 1286 ;; Don't leave indentation in empty lines. |
1287 (if (eolp) (setq this-indent 0)) | |
1288 ;; Put chosen indentation into effect. | |
1289 (or (= (current-column) this-indent) | |
1290 (= (following-char) ?\#) | |
1291 (progn | |
1292 (delete-region (point) (progn (beginning-of-line) (point))) | |
1293 (indent-to this-indent))) | |
1294 ;; Indent any comment following the text. | |
1295 (or (looking-at comment-start-skip) | |
8467
b2cfcc126dac
(indent-c-exp): Preserve point when handling comments.
Richard M. Stallman <rms@gnu.org>
parents:
7678
diff
changeset
|
1296 (save-excursion |
b2cfcc126dac
(indent-c-exp): Preserve point when handling comments.
Richard M. Stallman <rms@gnu.org>
parents:
7678
diff
changeset
|
1297 (let ((beg (point))) |
b2cfcc126dac
(indent-c-exp): Preserve point when handling comments.
Richard M. Stallman <rms@gnu.org>
parents:
7678
diff
changeset
|
1298 (and (re-search-forward |
b2cfcc126dac
(indent-c-exp): Preserve point when handling comments.
Richard M. Stallman <rms@gnu.org>
parents:
7678
diff
changeset
|
1299 comment-start-skip |
b2cfcc126dac
(indent-c-exp): Preserve point when handling comments.
Richard M. Stallman <rms@gnu.org>
parents:
7678
diff
changeset
|
1300 (save-excursion (end-of-line) (point)) t) |
b2cfcc126dac
(indent-c-exp): Preserve point when handling comments.
Richard M. Stallman <rms@gnu.org>
parents:
7678
diff
changeset
|
1301 ;; Make sure the comment starter we found |
b2cfcc126dac
(indent-c-exp): Preserve point when handling comments.
Richard M. Stallman <rms@gnu.org>
parents:
7678
diff
changeset
|
1302 ;; is not actually in a string or quoted. |
b2cfcc126dac
(indent-c-exp): Preserve point when handling comments.
Richard M. Stallman <rms@gnu.org>
parents:
7678
diff
changeset
|
1303 (let ((new-state |
b2cfcc126dac
(indent-c-exp): Preserve point when handling comments.
Richard M. Stallman <rms@gnu.org>
parents:
7678
diff
changeset
|
1304 (parse-partial-sexp beg (point) |
b2cfcc126dac
(indent-c-exp): Preserve point when handling comments.
Richard M. Stallman <rms@gnu.org>
parents:
7678
diff
changeset
|
1305 nil nil state))) |
b2cfcc126dac
(indent-c-exp): Preserve point when handling comments.
Richard M. Stallman <rms@gnu.org>
parents:
7678
diff
changeset
|
1306 (and (not (nth 3 new-state)) (not (nth 5 new-state)))) |
b2cfcc126dac
(indent-c-exp): Preserve point when handling comments.
Richard M. Stallman <rms@gnu.org>
parents:
7678
diff
changeset
|
1307 (indent-for-comment))))))))))) |
453 | 1308 |
1309 ;; Look at all comment-start strings in the current line after point. | |
1310 ;; Return t if one of them starts a real comment. | |
1311 ;; This is not used yet, because indent-for-comment | |
1312 ;; isn't smart enough to handle the cases this can find. | |
1313 (defun indent-c-find-real-comment () | |
1314 (let (win) | |
1315 (while (and (not win) | |
1316 (re-search-forward comment-start-skip | |
1317 (save-excursion (end-of-line) (point)) | |
1318 t)) | |
1319 ;; Make sure the comment start is not quoted. | |
1320 (let ((state-1 | |
1321 (parse-partial-sexp | |
1322 (save-excursion (beginning-of-line) (point)) | |
1323 (point) nil nil state))) | |
1324 (setq win (and (null (nth 3 state-1)) (null (nth 5 state-1)))))) | |
1325 win)) | |
1326 | |
1327 ;; Indent every line whose first char is between START and END inclusive. | |
1328 (defun c-indent-region (start end) | |
1329 (save-excursion | |
1330 (goto-char start) | |
5137
d11c5909a2d0
(c-indent-region): As first thing, advance to a nonblank line.
Richard M. Stallman <rms@gnu.org>
parents:
5124
diff
changeset
|
1331 ;; Advance to first nonblank line. |
d11c5909a2d0
(c-indent-region): As first thing, advance to a nonblank line.
Richard M. Stallman <rms@gnu.org>
parents:
5124
diff
changeset
|
1332 (skip-chars-forward " \t\n") |
d11c5909a2d0
(c-indent-region): As first thing, advance to a nonblank line.
Richard M. Stallman <rms@gnu.org>
parents:
5124
diff
changeset
|
1333 (beginning-of-line) |
4419
e7348af6762b
(indent-c-exp): Don't document ENDPOS.
Richard M. Stallman <rms@gnu.org>
parents:
4388
diff
changeset
|
1334 (let ((endmark (copy-marker end)) |
e7348af6762b
(indent-c-exp): Don't document ENDPOS.
Richard M. Stallman <rms@gnu.org>
parents:
4388
diff
changeset
|
1335 (c-tab-always-indent t)) |
5540
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1336 (while (and (bolp) (not (eobp)) (< (point) endmark)) |
4419
e7348af6762b
(indent-c-exp): Don't document ENDPOS.
Richard M. Stallman <rms@gnu.org>
parents:
4388
diff
changeset
|
1337 ;; Indent one line as with TAB. |
e7348af6762b
(indent-c-exp): Don't document ENDPOS.
Richard M. Stallman <rms@gnu.org>
parents:
4388
diff
changeset
|
1338 (let ((shift-amt (c-indent-line)) |
4976
a81642d50a8e
(c-indent-region): When looking for a sexp that ends
Richard M. Stallman <rms@gnu.org>
parents:
4419
diff
changeset
|
1339 nextline sexpbeg sexpend) |
5540
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1340 (if (save-excursion (beginning-of-line) (looking-at "[ \t]*#")) |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1341 (forward-line 1) |
4419
e7348af6762b
(indent-c-exp): Don't document ENDPOS.
Richard M. Stallman <rms@gnu.org>
parents:
4388
diff
changeset
|
1342 (save-excursion |
5540
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1343 ;; Find beginning of following line. |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1344 (save-excursion |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1345 (forward-line 1) (setq nextline (point))) |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1346 ;; Find first beginning-of-sexp for sexp extending past this line. |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1347 (beginning-of-line) |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1348 (while (< (point) nextline) |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1349 (condition-case nil |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1350 (progn |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1351 (forward-sexp 1) |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1352 (setq sexpend (point-marker))) |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1353 (error (setq sexpend nil) |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1354 (goto-char nextline))) |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1355 (skip-chars-forward " \t\n")) |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1356 (if sexpend |
4419
e7348af6762b
(indent-c-exp): Don't document ENDPOS.
Richard M. Stallman <rms@gnu.org>
parents:
4388
diff
changeset
|
1357 (progn |
5540
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1358 ;; Make sure the sexp we found really starts on the |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1359 ;; current line and extends past it. |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1360 (goto-char sexpend) |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1361 (backward-sexp 1) |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1362 (setq sexpbeg (point))))) |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1363 ;; If that sexp ends within the region, |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1364 ;; indent it all at once, fast. |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1365 (if (and sexpend (> sexpend nextline) (<= sexpend endmark) |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1366 (< sexpbeg nextline)) |
5124
1aba6a79cb3d
(c-indent-region): Don't goto-char sexpend if it's nil.
Richard M. Stallman <rms@gnu.org>
parents:
4979
diff
changeset
|
1367 (progn |
5540
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1368 (indent-c-exp) |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1369 (goto-char sexpend))) |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1370 ;; Move to following line and try again. |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1371 (and sexpend (set-marker sexpend nil)) |
d147979e10f4
(c-indent-region): Keep looping till reach endmark.
Richard M. Stallman <rms@gnu.org>
parents:
5535
diff
changeset
|
1372 (forward-line 1)))) |
453 | 1373 (set-marker endmark nil)))) |
1374 | |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1375 (defun set-c-style (style &optional global) |
453 | 1376 "Set C-mode variables to use one of several different indentation styles. |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1377 The arguments are a string representing the desired style |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1378 and a flag which, if non-nil, means to set the style globally. |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1379 \(Interactively, the flag comes from the prefix argument.) |
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
1380 Available styles are GNU, K&R, BSD and Whitesmith." |
10490
14c7b7749f45
(set-c-style): Ignore case in completion.
Karl Heuer <kwzh@gnu.org>
parents:
10410
diff
changeset
|
1381 (interactive (list (let ((completion-ignore-case t)) |
14c7b7749f45
(set-c-style): Ignore case in completion.
Karl Heuer <kwzh@gnu.org>
parents:
10410
diff
changeset
|
1382 (completing-read "Use which C indentation style? " |
14c7b7749f45
(set-c-style): Ignore case in completion.
Karl Heuer <kwzh@gnu.org>
parents:
10410
diff
changeset
|
1383 c-style-alist nil t)) |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1384 current-prefix-arg)) |
453 | 1385 (let ((vars (cdr (assoc style c-style-alist)))) |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1386 (or vars |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1387 (error "Invalid C indentation style `%s'" style)) |
453 | 1388 (while vars |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1389 (or global |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1390 (make-local-variable (car (car vars)))) |
453 | 1391 (set (car (car vars)) (cdr (car vars))) |
1392 (setq vars (cdr vars))))) | |
837
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1393 |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1394 ;;; This page handles insertion and removal of backslashes for C macros. |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1395 |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1396 (defvar c-backslash-column 48 |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1397 "*Minimum column for end-of-line backslashes of macro definitions.") |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1398 |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1399 (defun c-backslash-region (from to delete-flag) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1400 "Insert, align, or delete end-of-line backslashes on the lines in the region. |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1401 With no argument, inserts backslashes and aligns existing backslashes. |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1402 With an argument, deletes the backslashes. |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1403 |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1404 This function does not modify the last line of the region if the region ends |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1405 right at the start of the following line; it does not modify blank lines |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1406 at the start of the region. So you can put the region around an entire macro |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1407 definition and conveniently use this command." |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1408 (interactive "r\nP") |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1409 (save-excursion |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1410 (goto-char from) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1411 (let ((column c-backslash-column) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1412 (endmark (make-marker))) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1413 (move-marker endmark to) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1414 ;; Compute the smallest column number past the ends of all the lines. |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1415 (if (not delete-flag) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1416 (while (< (point) to) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1417 (end-of-line) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1418 (if (= (preceding-char) ?\\) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1419 (progn (forward-char -1) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1420 (skip-chars-backward " \t"))) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1421 (setq column (max column (1+ (current-column)))) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1422 (forward-line 1))) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1423 ;; Adjust upward to a tab column, if that doesn't push past the margin. |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1424 (if (> (% column tab-width) 0) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1425 (let ((adjusted (* (/ (+ column tab-width -1) tab-width) tab-width))) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1426 (if (< adjusted (window-width)) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1427 (setq column adjusted)))) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1428 ;; Don't modify blank lines at start of region. |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1429 (goto-char from) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1430 (while (and (< (point) endmark) (eolp)) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1431 (forward-line 1)) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1432 ;; Add or remove backslashes on all the lines. |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1433 (while (and (< (point) endmark) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1434 ;; Don't backslashify the last line |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1435 ;; if the region ends right at the start of the next line. |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1436 (save-excursion |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1437 (forward-line 1) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1438 (< (point) endmark))) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1439 (if (not delete-flag) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1440 (c-append-backslash column) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1441 (c-delete-backslash)) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1442 (forward-line 1)) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1443 (move-marker endmark nil)))) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1444 |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1445 (defun c-append-backslash (column) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1446 (end-of-line) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1447 ;; Note that "\\\\" is needed to get one backslash. |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1448 (if (= (preceding-char) ?\\) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1449 (progn (forward-char -1) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1450 (delete-horizontal-space) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1451 (indent-to column)) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1452 (indent-to column) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1453 (insert "\\"))) |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1454 |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1455 (defun c-delete-backslash () |
a8aef92e0025
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
807
diff
changeset
|
1456 (end-of-line) |
5305
1a32c9c9cfbb
(c-delete-backslash): Do nothing if empty line.
Richard M. Stallman <rms@gnu.org>
parents:
5137
diff
changeset
|
1457 (or (bolp) |
1a32c9c9cfbb
(c-delete-backslash): Do nothing if empty line.
Richard M. Stallman <rms@gnu.org>
parents:
5137
diff
changeset
|
1458 (progn |
1a32c9c9cfbb
(c-delete-backslash): Do nothing if empty line.
Richard M. Stallman <rms@gnu.org>
parents:
5137
diff
changeset
|
1459 (forward-char -1) |
1a32c9c9cfbb
(c-delete-backslash): Do nothing if empty line.
Richard M. Stallman <rms@gnu.org>
parents:
5137
diff
changeset
|
1460 (if (looking-at "\\\\") |
1a32c9c9cfbb
(c-delete-backslash): Do nothing if empty line.
Richard M. Stallman <rms@gnu.org>
parents:
5137
diff
changeset
|
1461 (delete-region (1+ (point)) |
1a32c9c9cfbb
(c-delete-backslash): Do nothing if empty line.
Richard M. Stallman <rms@gnu.org>
parents:
5137
diff
changeset
|
1462 (progn (skip-chars-backward " \t") (point))))))) |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1463 |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1464 (defun c-up-conditional (count) |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1465 "Move back to the containing preprocessor conditional, leaving mark behind. |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1466 A prefix argument acts as a repeat count. With a negative argument, |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1467 move forward to the end of the containing preprocessor conditional. |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1468 When going backwards, `#elif' is treated like `#else' followed by `#if'. |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1469 When going forwards, `#elif' is ignored." |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1470 (interactive "p") |
3906
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1471 (c-forward-conditional (- count) t)) |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1472 |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1473 (defun c-backward-conditional (count &optional up-flag) |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1474 "Move back across a preprocessor conditional, leaving mark behind. |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1475 A prefix argument acts as a repeat count. With a negative argument, |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1476 move forward across a preprocessor conditional." |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1477 (interactive "p") |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1478 (c-forward-conditional (- count) up-flag)) |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1479 |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1480 (defun c-forward-conditional (count &optional up-flag) |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1481 "Move forward across a preprocessor conditional, leaving mark behind. |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1482 A prefix argument acts as a repeat count. With a negative argument, |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1483 move backward across a preprocessor conditional." |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1484 (interactive "p") |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1485 (let* ((forward (> count 0)) |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1486 (increment (if forward -1 1)) |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1487 (search-function (if forward 're-search-forward 're-search-backward)) |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1488 (opoint (point)) |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1489 (new)) |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1490 (save-excursion |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1491 (while (/= count 0) |
3906
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1492 (let ((depth (if up-flag 0 -1)) found) |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1493 (save-excursion |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1494 ;; Find the "next" significant line in the proper direction. |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1495 (while (and (not found) |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1496 ;; Rather than searching for a # sign that comes |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1497 ;; at the beginning of a line aside from whitespace, |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1498 ;; search first for a string starting with # sign. |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1499 ;; Then verify what precedes it. |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1500 ;; This is faster on account of the fastmap feature of |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1501 ;; the regexp matcher. |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1502 (funcall search-function |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1503 "#[ \t]*\\(if\\|elif\\|endif\\)" |
3256
14eb227cad41
(c-up-conditional): Handle commented-out #-cmds properly.
Richard M. Stallman <rms@gnu.org>
parents:
2829
diff
changeset
|
1504 nil t)) |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1505 (beginning-of-line) |
3256
14eb227cad41
(c-up-conditional): Handle commented-out #-cmds properly.
Richard M. Stallman <rms@gnu.org>
parents:
2829
diff
changeset
|
1506 ;; Now verify it is really a preproc line. |
14eb227cad41
(c-up-conditional): Handle commented-out #-cmds properly.
Richard M. Stallman <rms@gnu.org>
parents:
2829
diff
changeset
|
1507 (if (looking-at "^[ \t]*#[ \t]*\\(if\\|elif\\|endif\\)") |
3906
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1508 (let ((prev depth)) |
3256
14eb227cad41
(c-up-conditional): Handle commented-out #-cmds properly.
Richard M. Stallman <rms@gnu.org>
parents:
2829
diff
changeset
|
1509 ;; Update depth according to what we found. |
14eb227cad41
(c-up-conditional): Handle commented-out #-cmds properly.
Richard M. Stallman <rms@gnu.org>
parents:
2829
diff
changeset
|
1510 (beginning-of-line) |
14eb227cad41
(c-up-conditional): Handle commented-out #-cmds properly.
Richard M. Stallman <rms@gnu.org>
parents:
2829
diff
changeset
|
1511 (cond ((looking-at "[ \t]*#[ \t]*endif") |
14eb227cad41
(c-up-conditional): Handle commented-out #-cmds properly.
Richard M. Stallman <rms@gnu.org>
parents:
2829
diff
changeset
|
1512 (setq depth (+ depth increment))) |
14eb227cad41
(c-up-conditional): Handle commented-out #-cmds properly.
Richard M. Stallman <rms@gnu.org>
parents:
2829
diff
changeset
|
1513 ((looking-at "[ \t]*#[ \t]*elif") |
14eb227cad41
(c-up-conditional): Handle commented-out #-cmds properly.
Richard M. Stallman <rms@gnu.org>
parents:
2829
diff
changeset
|
1514 (if (and forward (= depth 0)) |
14eb227cad41
(c-up-conditional): Handle commented-out #-cmds properly.
Richard M. Stallman <rms@gnu.org>
parents:
2829
diff
changeset
|
1515 (setq found (point)))) |
14eb227cad41
(c-up-conditional): Handle commented-out #-cmds properly.
Richard M. Stallman <rms@gnu.org>
parents:
2829
diff
changeset
|
1516 (t (setq depth (- depth increment)))) |
3906
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1517 ;; If we are trying to move across, and we find |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1518 ;; an end before we find a beginning, get an error. |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1519 (if (and (< prev 0) (< depth prev)) |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1520 (error (if forward |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1521 "No following conditional at this level" |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1522 "No previous conditional at this level"))) |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1523 ;; When searching forward, start from next line |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1524 ;; so that we don't find the same line again. |
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1525 (if forward (forward-line 1)) |
3256
14eb227cad41
(c-up-conditional): Handle commented-out #-cmds properly.
Richard M. Stallman <rms@gnu.org>
parents:
2829
diff
changeset
|
1526 ;; If this line exits a level of conditional, exit inner loop. |
14eb227cad41
(c-up-conditional): Handle commented-out #-cmds properly.
Richard M. Stallman <rms@gnu.org>
parents:
2829
diff
changeset
|
1527 (if (< depth 0) |
10544
eeeae6ef626e
(c-forward-conditional):
Richard M. Stallman <rms@gnu.org>
parents:
10490
diff
changeset
|
1528 (setq found (point)))) |
eeeae6ef626e
(c-forward-conditional):
Richard M. Stallman <rms@gnu.org>
parents:
10490
diff
changeset
|
1529 ;; If the line is not really a conditional, skip past it. |
eeeae6ef626e
(c-forward-conditional):
Richard M. Stallman <rms@gnu.org>
parents:
10490
diff
changeset
|
1530 (if forward (end-of-line))))) |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1531 (or found |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1532 (error "No containing preprocessor conditional")) |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1533 (goto-char (setq new found))) |
3906
a03d6cac1cd1
(c-forward-conditional): New function.
Richard M. Stallman <rms@gnu.org>
parents:
3716
diff
changeset
|
1534 (setq count (+ count increment)))) |
909
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1535 (push-mark) |
4c6cdb66c74c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
871
diff
changeset
|
1536 (goto-char new))) |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
472
diff
changeset
|
1537 |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
472
diff
changeset
|
1538 ;;; c-mode.el ends here |