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