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