1 ;;; c-mode.el --- C code editing commands for Emacs
2 ;; Copyright (C) 1985, 1986, 1987, 1992, 1994 Free Software Foundation, Inc.
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
25 ;; A smart editing mode for C code. It knows a lot about C syntax and tries
26 ;; to position the curser according to C layout conventions. You can
27 ;; change the details of the layout style with option variables. Load it
28 ;; and do M-x describe-mode for details.
32 (defvar c-mode-abbrev-table nil
33 "Abbrev table in use in C mode.")
34 (define-abbrev-table 'c-mode-abbrev-table ())
36 (defvar c-mode-map (make-sparse-keymap)
37 "Keymap used in C mode.")
39 (define-key c-mode-map "{" 'electric-c-brace)
40 (define-key c-mode-map "}" 'electric-c-brace)
41 (define-key c-mode-map ";" 'electric-c-semi)
42 (define-key c-mode-map "#" 'electric-c-sharp-sign)
43 (define-key c-mode-map ":" 'electric-c-terminator)
44 (define-key c-mode-map "\e\C-h" 'mark-c-function)
45 (define-key c-mode-map "\e\C-q" 'indent-c-exp)
46 (define-key c-mode-map "\ea" 'c-beginning-of-statement)
47 (define-key c-mode-map "\ee" 'c-end-of-statement)
48 (define-key c-mode-map "\eq" 'c-fill-paragraph)
49 (define-key c-mode-map "\C-c\C-n" 'c-forward-conditional)
50 (define-key c-mode-map "\C-c\C-p" 'c-backward-conditional)
51 (define-key c-mode-map "\C-c\C-u" 'c-up-conditional)
52 (define-key c-mode-map "\177" 'backward-delete-char-untabify)
53 (define-key c-mode-map "\t" 'c-indent-command)
55 (define-key c-mode-map [menu-bar] (make-sparse-keymap))
57 (define-key c-mode-map [menu-bar c]
58 (cons "C" (make-sparse-keymap "C")))
60 (define-key c-mode-map [menu-bar c comment-region]
61 '("Comment Out Region" . comment-region))
62 (define-key c-mode-map [menu-bar c c-macro-expand]
63 '("Macro Expand Region" . c-macro-expand))
64 (define-key c-mode-map [menu-bar c c-backslash-region]
65 '("Backslashify" . c-backslash-region))
66 (define-key c-mode-map [menu-bar c indent-exp]
67 '("Indent Expression" . indent-c-exp))
68 (define-key c-mode-map [menu-bar c indent-line]
69 '("Indent Line" . c-indent-command))
70 (define-key c-mode-map [menu-bar c fill]
71 '("Fill Comment Paragraph" . c-fill-paragraph))
72 (define-key c-mode-map [menu-bar c up]
73 '("Up Conditional" . c-up-conditional))
74 (define-key c-mode-map [menu-bar c backward]
75 '("Backward Conditional" . c-backward-conditional))
76 (define-key c-mode-map [menu-bar c forward]
77 '("Forward Conditional" . c-forward-conditional))
78 (define-key c-mode-map [menu-bar c backward-stmt]
79 '("Backward Statement" . c-beginning-of-statement))
80 (define-key c-mode-map [menu-bar c forward-stmt]
81 '("Forward Statement" . c-end-of-statement))
83 (autoload 'c-macro-expand "cmacexp"
84 "Display the result of expanding all C macros occurring in the region.
85 The expansion is entirely correct because it uses the C preprocessor."
88 (defvar c-mode-syntax-table nil
89 "Syntax table in use in C-mode buffers.")
91 (if c-mode-syntax-table
93 (setq c-mode-syntax-table (make-syntax-table))
94 (modify-syntax-entry ?\\ "\\" c-mode-syntax-table)
95 (modify-syntax-entry ?/ ". 14" c-mode-syntax-table)
96 (modify-syntax-entry ?* ". 23" c-mode-syntax-table)
97 (modify-syntax-entry ?+ "." c-mode-syntax-table)
98 (modify-syntax-entry ?- "." c-mode-syntax-table)
99 (modify-syntax-entry ?= "." c-mode-syntax-table)
100 (modify-syntax-entry ?% "." c-mode-syntax-table)
101 (modify-syntax-entry ?< "." c-mode-syntax-table)
102 (modify-syntax-entry ?> "." c-mode-syntax-table)
103 (modify-syntax-entry ?& "." c-mode-syntax-table)
104 (modify-syntax-entry ?| "." c-mode-syntax-table)
105 (modify-syntax-entry ?\' "\"" c-mode-syntax-table))
107 (defconst c-indent-level 2
108 "*Indentation of C statements with respect to containing block.")
109 (defconst c-brace-imaginary-offset 0
110 "*Imagined indentation of a C open brace that actually follows a statement.")
111 (defconst c-brace-offset 0
112 "*Extra indentation for braces, compared with other text in same context.")
113 (defconst c-argdecl-indent 5
114 "*Indentation level of declarations of C function arguments.")
115 (defconst c-label-offset -2
116 "*Offset of C label lines and case statements relative to usual indentation.")
117 (defconst c-continued-statement-offset 2
118 "*Extra indent for lines not starting new statements.")
119 (defconst c-continued-brace-offset 0
120 "*Extra indent for substatements that start with open-braces.
121 This is in addition to c-continued-statement-offset.")
122 (defconst c-style-alist
125 (c-argdecl-indent . 5)
127 (c-label-offset . -2)
128 (c-continued-statement-offset . 2))
131 (c-argdecl-indent . 0)
132 (c-brace-offset . -5)
133 (c-label-offset . -5)
134 (c-continued-statement-offset . 5))
137 (c-argdecl-indent . 4)
138 (c-brace-offset . -4)
139 (c-label-offset . -4)
140 (c-continued-statement-offset . 4))
143 (c-continued-statement-offset . 4)
144 (c-brace-offset . -4)
145 (c-argdecl-indent . 0)
146 (c-label-offset . -4)
147 (c-auto-newline . t))
150 (c-argdecl-indent . 4)
152 (c-label-offset . -4)
153 (c-continued-statement-offset . 4))))
155 (defconst c-auto-newline nil
156 "*Non-nil means automatically newline before and after braces,
157 and after colons and semicolons, inserted in C code.
158 If you do not want a leading newline before braces then use:
159 (define-key c-mode-map \"{\" 'electric-c-semi)")
161 (defconst c-tab-always-indent t
162 "*Non-nil means TAB in C mode should always reindent the current line,
163 regardless of where in the line point is when the TAB command is used.")
165 ;;; Regular expression used internally to recognize labels in switch
167 (defconst c-switch-label-regexp "case[ \t'/(]\\|default\\(\\S_\\|'\\)")
171 "Major mode for editing C code.
172 Expression and list commands understand all C brackets.
173 Tab indents for C code.
174 Comments are delimited with /* ... */.
175 Paragraphs are separated by blank lines only.
176 Delete converts tabs to spaces as it moves back.
178 Variables controlling indentation style:
180 Non-nil means TAB in C mode should always reindent the current line,
181 regardless of where in the line point is when the TAB command is used.
183 Non-nil means automatically newline before and after braces,
184 and after colons and semicolons, inserted in C code.
186 Indentation of C statements within surrounding block.
187 The surrounding block's indentation is the indentation
188 of the line on which the open-brace appears.
189 c-continued-statement-offset
190 Extra indentation given to a substatement, such as the
191 then-clause of an if or body of a while.
192 c-continued-brace-offset
193 Extra indentation given to a brace that starts a substatement.
194 This is in addition to c-continued-statement-offset.
196 Extra indentation for line if it starts with an open brace.
197 c-brace-imaginary-offset
198 An open brace following other text is treated as if it were
199 this far to the right of the start of its line.
201 Indentation level of declarations of C function arguments.
203 Extra indentation for line that is a label, or case or default.
205 Settings for K&R and BSD indentation styles are
207 c-continued-statement-offset 5 8
212 Turning on C mode calls the value of the variable c-mode-hook with no args,
213 if that value is non-nil."
215 (kill-all-local-variables)
216 (use-local-map c-mode-map)
217 (setq major-mode 'c-mode)
219 (setq local-abbrev-table c-mode-abbrev-table)
220 (set-syntax-table c-mode-syntax-table)
221 (make-local-variable 'paragraph-start)
222 (setq paragraph-start (concat "^$\\|" page-delimiter))
223 (make-local-variable 'paragraph-separate)
224 (setq paragraph-separate paragraph-start)
225 (make-local-variable 'paragraph-ignore-fill-prefix)
226 (setq paragraph-ignore-fill-prefix t)
227 (make-local-variable 'indent-line-function)
228 (setq indent-line-function 'c-indent-line)
229 (make-local-variable 'indent-region-function)
230 (setq indent-region-function 'c-indent-region)
231 (make-local-variable 'require-final-newline)
232 (setq require-final-newline t)
233 (make-local-variable 'outline-regexp)
234 (setq outline-regexp "[^#\n\^M]")
235 (make-local-variable 'outline-level)
236 (setq outline-level 'c-outline-level)
237 (make-local-variable 'comment-start)
238 (setq comment-start "/* ")
239 (make-local-variable 'comment-end)
240 (setq comment-end " */")
241 (make-local-variable 'comment-column)
242 (setq comment-column 32)
243 (make-local-variable 'comment-start-skip)
244 (setq comment-start-skip "/\\*+ *")
245 (make-local-variable 'comment-indent-function)
246 (setq comment-indent-function 'c-comment-indent)
247 (make-local-variable 'parse-sexp-ignore-comments)
248 (setq parse-sexp-ignore-comments t)
249 (run-hooks 'c-mode-hook))
251 (defun c-outline-level ()
253 (skip-chars-forward "\t ")
256 ;; This is used by indent-for-comment
257 ;; to decide how much to indent a comment in C code
258 ;; based on its context.
259 (defun c-comment-indent ()
260 (if (looking-at "^/\\*")
261 0 ;Existing comment at bol stays there.
262 (let ((opoint (point)))
265 (cond ((looking-at "[ \t]*}[ \t]*\\($\\|/\\*\\)")
266 ;; A comment following a solitary close-brace
267 ;; should have only one space.
269 (1+ (current-column)))
270 ((or (looking-at "^#[ \t]*endif[ \t]*")
271 (looking-at "^#[ \t]*else[ \t]*"))
272 7) ;2 spaces after #endif
275 (skip-chars-backward " \t")
276 (and (= comment-column 0) (bolp)))
277 ;; If comment-column is 0, and nothing but space
278 ;; before the comment, align it at 0 rather than 1.
281 (max (1+ (current-column)) ;Else indent at comment column
282 comment-column))))))) ; except leave at least one space.
284 (defun c-fill-paragraph (&optional arg)
285 "Like \\[fill-paragraph] but handle C comments.
286 If any of the current line is a comment or within a comment,
287 fill the comment or the paragraph of it that point is in,
288 preserving the comment indentation or line-starting decorations."
290 (let* (comment-start-place
292 ;; Check for obvious entry to comment.
295 (skip-chars-forward " \t\n")
296 (and (looking-at comment-start-skip)
297 (setq comment-start-place (point))))))
298 (if (and (eq major-mode 'c++-mode)
301 (looking-at ".*//")))
304 ;; Lines containing just a comment start or just an end
305 ;; should not be filled into paragraphs they are next to.
308 "\\|^[ \t]*/\\*[ \t]*$\\|^[ \t]*\\*/[ \t]*$\\|^[ \t/*]*$"))
312 "\\|^[ \t]*/\\*[ \t]*$\\|^[ \t]*\\*/[ \t]*$\\|^[ \t/*]*$")))
315 ;; Move up to first line of this comment.
316 (while (and (not (bobp)) (looking-at "[ \t]*//"))
318 (if (not (looking-at ".*//"))
320 ;; Find the comment start in this line.
321 (re-search-forward "[ \t]*//[ \t]*")
322 ;; Set the fill-prefix to be what all lines except the first
323 ;; should start with.
324 (let ((endcol (current-column)))
325 (skip-chars-backward " \t")
327 (concat (make-string (- (current-column) 2) ?\ )
329 (make-string (- endcol (current-column)) ?\ ))))
331 ;; Narrow down to just the lines of this comment.
332 (narrow-to-region (point)
335 (while (looking-at "[ \t]*//")
340 (delete-region (point-min)
341 (+ (point-min) (length fill-prefix))))))
343 ;; t if we enter a comment between start of function and this line.
344 (eq (calculate-c-indent) t)
345 ;; t if this line contains a comment starter.
350 (re-search-forward comment-start-skip
351 (save-excursion (end-of-line)
354 (setq comment-start-place (point))))))
355 ;; Inside a comment: fill one comment paragraph.
357 ;; The prefix for each line of this paragraph
358 ;; is the appropriate part of the start of this line,
359 ;; up to the column at which text should be indented.
362 (if (looking-at "[ \t]*/\\*.*\\*/")
363 (progn (re-search-forward comment-start-skip)
364 (make-string (current-column) ?\ ))
365 (if first-line (forward-line 1))
367 (let ((line-width (progn (end-of-line) (current-column))))
373 ;; How shall we decide where the end of the
375 ;; calculate-c-indent-within-comment bases its value
376 ;; on the indentation of previous lines; if they're
377 ;; indented specially, it could return a column
378 ;; that's well into the current line's text. So
379 ;; we'll take at most that many space, tab, or *
380 ;; characters, and use that as our fill prefix.
381 (let ((max-prefix-end
384 (calculate-c-indent-within-comment t)
388 (skip-chars-forward " \t*" max-prefix-end)
389 ;; Don't include part of comment terminator
390 ;; in the fill-prefix.
391 (and (eq (following-char) ?/)
392 (eq (preceding-char) ?*)
396 ;; If the comment is only one line followed by a blank
397 ;; line, calling move-to-column above may have added
398 ;; some spaces and tabs to the end of the line; the
399 ;; fill-paragraph function will then delete it and the
400 ;; newline following it, so we'll lose a blank line
401 ;; when we shouldn't. So delete anything
402 ;; move-to-column added to the end of the line. We
403 ;; record the line width instead of the position of the
404 ;; old line end because move-to-column might break a
405 ;; tab into spaces, and the new characters introduced
406 ;; there shouldn't be deleted.
408 ;; If you can see a better way to do this, please make
409 ;; the change. This seems very messy to me.
410 (delete-region (progn (move-to-column line-width)
412 (progn (end-of-line) (point))))))))
415 ;; Lines containing just a comment start or just an end
416 ;; should not be filled into paragraphs they are next to.
419 "\\|^[ \t]*/\\*[ \t]*$\\|^[ \t]*\\*/[ \t]*$\\|^[ \t/*]*$"))
423 "\\|^[ \t]*/\\*[ \t]*$\\|^[ \t]*\\*/[ \t]*$\\|^[ \t/*]*$"))
426 ;; Don't fill the comment together with the code following it.
427 ;; So temporarily exclude everything before the comment start,
428 ;; and everything after the line where the comment ends.
429 ;; If comment-start-place is non-nil, the comment starter is there.
430 ;; Otherwise, point is inside the comment.
431 (narrow-to-region (save-excursion
432 (if comment-start-place
433 (goto-char comment-start-place)
434 (search-backward "/*"))
435 ;; Protect text before the comment start
436 ;; by excluding it. Add spaces to bring back
437 ;; proper indentation of that point.
438 (let ((column (current-column)))
440 (setq chars-to-delete column)
441 (insert-char ?\ column))))
443 (if comment-start-place
444 (goto-char (+ comment-start-place 2)))
445 (search-forward "*/" nil 'move)
450 ;; Delete the chars we inserted to avoid clobbering
451 ;; the stuff before the comment start.
452 (goto-char (point-min))
453 (if (> chars-to-delete 0)
454 (delete-region (point) (+ (point) chars-to-delete)))
455 ;; Find the comment ender (should be on last line of buffer,
456 ;; given the narrowing) and don't leave it on its own line.
457 ;; Do this with a fill command, so as to preserve sentence
459 (goto-char (point-max))
461 (search-forward "*/" nil 'move)
463 (if (looking-at "[ \t]*\\*/")
464 (let ((fill-column (+ fill-column 9999)))
466 (fill-region-as-paragraph (point) (point-max)))))))
467 ;; Outside of comments: do ordinary filling.
468 (fill-paragraph arg)))))
470 (defun electric-c-brace (arg)
471 "Insert character and correct line's indentation."
477 (skip-chars-backward " \t")
479 (if c-auto-newline (progn (c-indent-line) (newline) t) nil)))
481 (insert last-command-char)
486 ;; (newline) may have done auto-fill
487 (setq insertpos (- (point) 2))
490 (if insertpos (goto-char (1+ insertpos)))
494 (goto-char insertpos)
495 (self-insert-command (prefix-numeric-value arg)))
496 (self-insert-command (prefix-numeric-value arg)))))
498 (defun electric-c-sharp-sign (arg)
499 "Insert character and correct line's indentation."
502 (skip-chars-backward " \t")
504 (let ((c-auto-newline nil))
505 (electric-c-terminator arg))
506 (self-insert-command (prefix-numeric-value arg))))
508 (defun electric-c-semi (arg)
509 "Insert character and correct line's indentation."
512 (electric-c-terminator arg)
513 (self-insert-command (prefix-numeric-value arg))))
515 (defun electric-c-terminator (arg)
516 "Insert character and correct line's indentation."
518 (let (insertpos (end (point)))
519 (if (and (not arg) (eolp)
522 (skip-chars-forward " \t")
523 (or (= (following-char) ?#)
524 ;; Colon is special only after a label, or case ....
525 ;; So quickly rule out most other uses of colon
526 ;; and do no indentation for them.
527 (and (eq last-command-char ?:)
528 (not (looking-at c-switch-label-regexp))
530 (skip-chars-forward "a-zA-Z0-9_$")
531 (skip-chars-forward " \t")
535 (let ((pps (parse-partial-sexp (point) end)))
536 (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
538 (insert last-command-char)
541 (not (c-inside-parens-p))
544 ;; (newline) may have done auto-fill
545 (setq insertpos (- (point) 2))
548 (if insertpos (goto-char (1+ insertpos)))
552 (goto-char insertpos)
553 (self-insert-command (prefix-numeric-value arg)))
554 (self-insert-command (prefix-numeric-value arg)))))
556 (defun c-inside-parens-p ()
560 (narrow-to-region (point)
561 (progn (beginning-of-defun) (point)))
562 (goto-char (point-max))
563 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\()))
566 (defun c-indent-command (&optional whole-exp)
567 "Indent current line as C code, or in some cases insert a tab character.
568 If `c-tab-always-indent' is non-nil (the default), always indent current line.
569 Otherwise, indent the current line only if point is at the left margin or
570 in the line's indentation; otherwise insert a tab.
572 A numeric argument, regardless of its value, means indent rigidly all the
573 lines of the expression starting after point so that this line becomes
574 properly indented. The relative indentation among the lines of the
575 expression are preserved."
578 ;; If arg, always indent this line as C
579 ;; and shift remaining lines of expression the same amount.
580 (let ((shift-amt (c-indent-line))
583 (if c-tab-always-indent
585 ;; Find beginning of following line.
587 (forward-line 1) (setq beg (point)))
588 ;; Find first beginning-of-sexp for sexp extending past this line.
589 (while (< (point) beg)
592 (skip-chars-forward " \t\n")))
594 (indent-code-rigidly beg end shift-amt "#")))
595 (if (and (not c-tab-always-indent)
597 (skip-chars-backward " \t")
602 (defun c-indent-line ()
603 "Indent current line as C code.
604 Return the amount the indentation changed by."
605 (let ((indent (calculate-c-indent nil))
607 (case-fold-search nil)
608 (pos (- (point-max) (point))))
611 (cond ((eq indent nil)
612 (setq indent (current-indentation)))
614 (setq indent (calculate-c-indent-within-comment)))
615 ((looking-at "[ \t]*#")
618 (skip-chars-forward " \t")
619 (if (listp indent) (setq indent (car indent)))
620 (cond ((or (looking-at c-switch-label-regexp)
621 (and (looking-at "[A-Za-z]")
625 (setq indent (max 1 (+ indent c-label-offset))))
626 ((and (looking-at "else\\b")
627 (not (looking-at "else\\s_")))
628 (setq indent (save-excursion
629 (c-backward-to-start-of-if)
630 (current-indentation))))
631 ((looking-at "}[ \t]*else")
632 (setq indent (save-excursion
635 (c-backward-to-start-of-if)
636 (current-indentation))))
637 ((and (looking-at "while\\b")
639 (c-backward-to-start-of-do)))
640 ;; This is a `while' that ends a do-while.
641 (setq indent (save-excursion
642 (c-backward-to-start-of-do)
643 (current-indentation))))
644 ((= (following-char) ?})
645 (setq indent (- indent c-indent-level)))
646 ((= (following-char) ?{)
647 (setq indent (+ indent c-brace-offset))))))
648 (skip-chars-forward " \t")
649 (setq shift-amt (- indent (current-column)))
650 (if (zerop shift-amt)
651 (if (> (- (point-max) pos) (point))
652 (goto-char (- (point-max) pos)))
653 (delete-region beg (point))
655 ;; If initial point was within line's indentation,
656 ;; position after the indentation. Else stay at same point in text.
657 (if (> (- (point-max) pos) (point))
658 (goto-char (- (point-max) pos))))
661 (defun calculate-c-indent (&optional parse-start)
662 "Return appropriate indentation for current line as C code.
663 In usual case returns an integer: the column to indent to.
664 Returns nil if line starts inside a string, t if in a comment."
667 (let ((indent-point (point))
668 (case-fold-search nil)
672 (goto-char parse-start)
673 (beginning-of-defun))
674 (while (< (point) indent-point)
675 (setq parse-start (point))
676 (setq state (parse-partial-sexp (point) indent-point 0))
677 (setq containing-sexp (car (cdr state))))
678 (cond ((or (nth 3 state) (nth 4 state))
679 ;; return nil or t if should not change this line
681 ((null containing-sexp)
682 ;; Line is at top level. May be data or function definition,
683 ;; or may be function argument declaration.
684 ;; Indent like the previous top level line
685 ;; unless that ends in a closeparen without semicolon,
686 ;; in which case this line is the first argument decl.
687 (goto-char indent-point)
688 (skip-chars-forward " \t")
689 (if (= (following-char) ?{)
690 0 ; Unless it starts a function body
691 (c-backward-to-noncomment (or parse-start (point-min)))
692 ;; Look at previous line that's at column 0
693 ;; to determine whether we are in top-level decls
694 ;; or function's arg decls. Set basic-indent accordingly.
697 (re-search-backward "^[^ \^L\t\n#]" nil 'move)
699 ;; Recognize the DEFUN macro in Emacs.
701 ;; Move down to the (putative) argnames line.
702 (while (and (not (eobp))
703 (not (looking-at " *[({}#/]")))
705 ;; Go back to the DEFUN, if it is one.
710 (looking-at "DEFUN\\b"))
712 (if (and (looking-at "\\sw\\|\\s_")
713 ;; This is careful to stop at the first
715 ;; int foo Proto ((int, int));
716 (looking-at "[^\"\n=(]*(")
718 (goto-char (1- (match-end 0)))
723 (skip-chars-forward " \t\f")
724 (and (< (point) indent-point)
725 (not (memq (following-char)
727 ;; Make sure the "function decl" we found
728 ;; is not inside a comment.
730 ;; Move back to the `(' starting arglist
733 (while (and (not comment)
734 (search-forward "/*" lim t))
736 (not (search-forward "*/" lim t))))
738 c-argdecl-indent 0))))))
741 ;; ;; Now add a little if this is a continuation line.
742 ;; (+ basic-indent (if (or (bobp)
743 ;; (memq (preceding-char) '(?\) ?\; ?\}))
744 ;; ;; Line with zero indentation
745 ;; ;; is probably the return-type
746 ;; ;; of a function definition,
747 ;; ;; so following line is function name.
748 ;; (= (current-indentation) 0))
749 ;; 0 c-continued-statement-offset))
751 ((/= (char-after containing-sexp) ?{)
752 ;; line is expression, not statement:
753 ;; indent to just after the surrounding open.
754 (goto-char (1+ containing-sexp))
757 ;; Statement level. Is it a continuation or a new statement?
758 ;; Find previous non-comment character.
759 (goto-char indent-point)
760 (c-backward-to-noncomment containing-sexp)
761 ;; Back up over label lines, since they don't
762 ;; affect whether our line is a continuation.
763 (while (or (eq (preceding-char) ?\,)
764 (and (eq (preceding-char) ?:)
765 (or (eq (char-after (- (point) 2)) ?\')
766 (memq (char-syntax (char-after (- (point) 2)))
768 (if (eq (preceding-char) ?\,)
769 (progn (forward-char -1)
770 (c-backward-to-start-of-continued-exp containing-sexp)))
772 (c-backward-to-noncomment containing-sexp))
773 ;; Check for a preprocessor statement or its continuation lines.
774 ;; Move back to end of previous non-preprocessor line,
775 ;; or possibly beginning of buffer.
776 (let ((found (point)) stop)
782 ((save-excursion (forward-char -1)
783 (= (preceding-char) ?\\))
785 ;; This line is not preceded by a backslash.
786 ;; So either it starts a preprocessor command
787 ;; or any following continuation lines
788 ;; should not be skipped.
789 ((= (following-char) ?#)
791 (setq found (point)))
794 ;; Now we get the answer.
795 (if (and (not (memq (preceding-char) '(0 ?\, ?\; ?\} ?\{)))
796 ;; But don't treat a line with a close-brace
797 ;; as a continuation. It is probably the
798 ;; end of an enum type declaration.
800 (goto-char indent-point)
801 (skip-chars-forward " \t")
802 (not (= (following-char) ?}))))
803 ;; This line is continuation of preceding line's statement;
804 ;; indent c-continued-statement-offset more than the
805 ;; previous line of the statement.
807 (c-backward-to-start-of-continued-exp containing-sexp)
808 (+ c-continued-statement-offset (current-column)
809 (if (save-excursion (goto-char indent-point)
810 (skip-chars-forward " \t")
811 (eq (following-char) ?{))
812 c-continued-brace-offset 0)))
813 ;; This line starts a new statement.
814 ;; Position following last unclosed open.
815 (goto-char containing-sexp)
816 ;; Is line first statement after an open-brace?
818 ;; If no, find that first statement and indent like it.
821 (let ((colon-line-end 0))
822 (while (progn (skip-chars-forward " \t\n")
823 (looking-at "#\\|/\\*\\|case[ \t\n'/(].*:\\|[a-zA-Z0-9_$]*:"))
824 ;; Skip over comments and labels following openbrace.
825 (cond ((= (following-char) ?\#)
827 ((= (following-char) ?\/)
829 (search-forward "*/" nil 'move))
832 (save-excursion (end-of-line)
833 (setq colon-line-end (point)))
834 (search-forward ":"))))
835 ;; The first following code counts
836 ;; if it is before the line we want to indent.
837 (and (< (point) indent-point)
839 (if (> colon-line-end (point))
840 (- (current-indentation) c-label-offset)
842 ;; If prev stmt starts with open-brace, that
843 ;; open brace was offset by c-brace-offset.
844 ;; Compensate to get the column where
845 ;; an ordinary statement would start.
846 (if (= (following-char) ?\{) c-brace-offset 0)))))
847 ;; If no previous statement,
848 ;; indent it relative to line brace is on.
849 ;; For open brace in column zero, don't let statement
850 ;; start there too. If c-indent-level is zero,
851 ;; use c-brace-offset + c-continued-statement-offset instead.
852 ;; For open-braces not the first thing in a line,
853 ;; add in c-brace-imaginary-offset.
854 (+ (if (and (bolp) (zerop c-indent-level))
855 (+ c-brace-offset c-continued-statement-offset)
857 ;; Move back over whitespace before the openbrace.
858 ;; If openbrace is not first nonwhite thing on the line,
859 ;; add the c-brace-imaginary-offset.
860 (progn (skip-chars-backward " \t")
861 (if (bolp) 0 c-brace-imaginary-offset))
862 ;; If the openbrace is preceded by a parenthesized exp,
863 ;; move to the beginning of that;
864 ;; possibly a different line
866 (if (eq (preceding-char) ?\))
868 ;; Get initial indentation of the line we are on.
869 (current-indentation))))))))))
871 (defun calculate-c-indent-within-comment (&optional after-star)
872 "Return the indentation amount for line inside a block comment.
873 Optional arg AFTER-STAR means, if lines in the comment have a leading star,
874 return the indentation of the text that would follow this star."
875 (let (end star-start)
878 (skip-chars-forward " \t")
879 (setq star-start (= (following-char) ?\*))
880 (skip-chars-backward " \t\n")
883 (skip-chars-forward " \t")
885 (and (looking-at "\\*")
886 (re-search-forward "\\*[ \t]*")))
887 (and (re-search-forward "/\\*[ \t]*" end t)
890 (goto-char (1+ (match-beginning 0))))
891 (if (and (looking-at "[ \t]*$") (= (preceding-char) ?\*))
892 (1+ (current-column))
896 (defun c-backward-to-noncomment (lim)
899 (skip-chars-backward " \t\n\f" lim)
900 (setq opoint (point))
901 (if (and (>= (point) (+ 2 lim))
904 (looking-at "\\*/")))
905 (search-backward "/*" lim 'move)
906 (setq stop (or (<= (point) lim)
909 (skip-chars-forward " \t")
910 (not (looking-at "#")))))
911 (or stop (beginning-of-line))))))
913 (defun c-backward-to-start-of-continued-exp (lim)
914 (if (memq (preceding-char) '(?\) ?\"))
918 (goto-char (1+ lim)))
919 (skip-chars-forward " \t"))
921 (defun c-backward-to-start-of-if (&optional limit)
922 "Move to the start of the last \"unbalanced\" `if'."
923 (or limit (setq limit (save-excursion (beginning-of-defun) (point))))
925 (case-fold-search nil))
926 (while (and (not (bobp)) (not (zerop if-level)))
928 (cond ((looking-at "else\\b")
929 (setq if-level (1+ if-level)))
930 ((looking-at "if\\b")
931 (setq if-level (1- if-level)))
934 (goto-char limit))))))
936 (defun c-backward-to-start-of-do (&optional limit)
937 "If point follows a `do' statement, move to beginning of it and return t.
938 Otherwise return nil and don't move point."
939 (or limit (setq limit (save-excursion (beginning-of-defun) (point))))
944 (let ((next-start (point)))
946 ;; Move back one token or one brace or paren group.
948 ;; If we find an open-brace, we lose.
949 (error (setq done 'fail)))
952 ;; If we reached a `do', we win.
953 (if (looking-at "do\\b")
955 ;; Otherwise, if we skipped a semicolon, we lose.
956 ;; (Exception: we can skip one semicolon before getting
957 ;; to a the last token of the statement, unless that token
958 ;; is a close brace.)
961 (or (and (not first) (= (preceding-char) ?}))
962 (search-forward ";" next-start t
964 (/= (preceding-char) ?}))
968 ;; If we go too far back in the buffer, we lose.
969 (if (< (point) limit)
970 (setq done 'fail)))))))
971 (if (eq done 'succeed)
976 (defun c-beginning-of-statement (count)
977 "Go to the beginning of the innermost C statement.
978 With prefix arg, go back N - 1 statements. If already at the beginning of a
979 statement then go to the beginning of the preceding one.
980 If within a string or comment, or next to a comment (only whitespace between),
981 move by sentences instead of statements."
983 (let ((here (point)) state)
986 (setq state (parse-partial-sexp (point) here nil nil)))
987 (if (or (nth 3 state) (nth 4 state)
988 (looking-at (concat "[ \t]*" comment-start-skip))
989 (save-excursion (skip-chars-backward " \t")
990 (goto-char (- (point) 2))
991 (looking-at "\\*/")))
992 (forward-sentence (- count))
994 (c-beginning-of-statement-1)
995 (setq count (1- count)))
997 (c-end-of-statement-1)
998 (setq count (1+ count))))))
1000 (defun c-end-of-statement (count)
1001 "Go to the end of the innermost C statement.
1002 With prefix arg, go forward N - 1 statements.
1003 Move forward to end of the next statement if already at end.
1004 If within a string or comment, move by sentences instead of statements."
1006 (c-beginning-of-statement (- count)))
1008 (defun c-beginning-of-statement-1 ()
1009 (let ((last-begin (point))
1013 (while (and (not (bobp))
1017 (not (re-search-forward "[;{}]" last-begin t)))))
1018 (setq last-begin (point) first nil))
1019 (goto-char last-begin))
1020 (error (if first (backward-up-list 1) (goto-char last-begin))))))
1022 (defun c-end-of-statement-1 ()
1025 (while (and (not (eobp))
1026 (let ((beg (point)))
1028 (let ((end (point)))
1031 (not (re-search-forward "[;{}]" end t)))))))
1032 (re-search-backward "[;}]")
1035 (let ((beg (point)))
1036 (backward-up-list -1)
1037 (let ((end (point)))
1039 (search-forward ";" end 'move))))))
1041 (defun mark-c-function ()
1042 "Put mark at end of C function, point at beginning."
1046 (push-mark (point) nil t)
1047 (beginning-of-defun)
1048 (backward-paragraph))
1050 ;; Idea of ENDPOS is, indent each line, stopping when
1051 ;; ENDPOS is encountered. But it's too much of a pain to make that work.
1052 (defun indent-c-exp (&optional endpos)
1053 "Indent each line of the C grouping following point."
1055 (let* ((indent-stack (list nil))
1056 (opoint (point)) ;; May be altered below.
1060 ;; Find previous fcn-start.
1061 (save-excursion (forward-char 1)
1062 (beginning-of-defun)
1063 (setq funbeg (point)))
1064 (setq opoint funbeg)
1065 ;; Try to find containing open,
1066 ;; but don't scan past that fcn-start.
1068 (narrow-to-region funbeg (point))
1071 (backward-up-list 1)
1073 ;; We gave up: must be between fcns.
1074 ;; Set opoint to beg of prev fcn
1075 ;; since otherwise calculate-c-indent
1076 ;; will get wrong answers.
1077 (error (setq opoint funbeg)
1080 (case-fold-search nil)
1081 restart outer-loop-done inner-loop-done state ostate
1082 this-indent last-sexp
1083 at-else at-brace at-while
1084 last-depth this-point
1086 ;; If the braces don't match, get an error right away.
1089 ;; Realign the comment on the first line, even though we don't reindent it.
1091 (let ((beg (point)))
1092 (and (re-search-forward
1094 (save-excursion (end-of-line) (point)) t)
1095 ;; Make sure this isn't a comment alone on a line
1096 ;; (which should be indented like code instead).
1098 (goto-char (match-beginning 0))
1099 (skip-chars-backward " \t")
1101 ;; Make sure the comment starter we found
1102 ;; is not actually in a string or quoted.
1104 (parse-partial-sexp beg (point)
1106 (and (not (nth 3 new-state)) (not (nth 5 new-state))))
1107 (progn (indent-for-comment) (beginning-of-line)))))
1109 (setq outer-loop-done nil)
1110 (while (and (not (eobp))
1111 (if endpos (< (point) endpos)
1112 (not outer-loop-done)))
1113 (setq last-depth next-depth)
1114 ;; Compute how depth changes over this line
1115 ;; plus enough other lines to get to one that
1116 ;; does not end inside a comment or string.
1117 ;; Meanwhile, do appropriate indentation on comment lines.
1118 (setq inner-loop-done nil)
1119 (while (and (not inner-loop-done)
1120 (not (and (eobp) (setq outer-loop-done t))))
1122 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
1124 (setq next-depth (car state))
1125 (if (and (car (cdr (cdr state)))
1126 (>= (car (cdr (cdr state))) 0))
1127 (setq last-sexp (car (cdr (cdr state)))))
1128 ;; If this line started within a comment, indent it as such.
1129 (if (or (nth 4 ostate) (nth 7 ostate))
1131 ;; If it ends outside of comments or strings, exit the inner loop.
1132 ;; Otherwise move on to next line.
1133 (if (or (nth 3 state) (nth 4 state) (nth 7 state))
1135 (setq inner-loop-done t)))
1137 (while (< next-depth 0)
1138 (setq indent-stack (append indent-stack (list nil)))
1139 (setq contain-stack (append contain-stack (list nil)))
1140 (setq next-depth (1+ next-depth))
1141 (setq last-depth (1+ last-depth))
1142 (setcar (nthcdr 6 state) (1+ (nth 6 state)))))
1143 (setq outer-loop-done (and (not endpos) (<= next-depth 0)))
1146 ;; If this line had ..))) (((.. in it, pop out of the levels
1147 ;; that ended anywhere in this line, even if the final depth
1148 ;; doesn't indicate that they ended.
1149 (while (> last-depth (nth 6 state))
1150 (setq indent-stack (cdr indent-stack)
1151 contain-stack (cdr contain-stack)
1152 last-depth (1- last-depth)))
1153 (if (/= last-depth next-depth)
1154 (setq last-sexp nil))
1155 ;; Add levels for any parens that were started in this line.
1156 (while (< last-depth next-depth)
1157 (setq indent-stack (cons nil indent-stack)
1158 contain-stack (cons nil contain-stack)
1159 last-depth (1+ last-depth)))
1160 (if (null (car contain-stack))
1161 (setcar contain-stack (or (car (cdr state))
1162 (save-excursion (forward-sexp -1)
1165 (skip-chars-forward " \t")
1166 ;; Don't really reindent if the line is just whitespace,
1167 ;; or if it is past the endpos.
1168 ;; (The exit test in the outer while
1169 ;; does not exit until we have passed the first line
1170 ;; past the region.)
1171 (if (or (eolp) (and endpos (>= (point) endpos)))
1173 (if (and (car indent-stack)
1174 (>= (car indent-stack) 0))
1175 ;; Line is on an existing nesting level.
1176 ;; Lines inside parens are handled specially.
1177 (if (/= (char-after (car contain-stack)) ?{)
1178 (setq this-indent (car indent-stack))
1179 ;; Line is at statement level.
1180 ;; Is it a new statement? Is it an else?
1181 ;; Find last non-comment character before this line
1183 (setq this-point (point))
1184 (setq at-else (looking-at "else\\W"))
1185 (setq at-brace (= (following-char) ?{))
1186 (setq at-while (looking-at "while\\b"))
1187 (if (= (following-char) ?})
1188 (setq this-indent (car indent-stack))
1189 (c-backward-to-noncomment opoint)
1190 (if (not (memq (preceding-char) '(0 ?\, ?\; ?} ?: ?{)))
1191 ;; Preceding line did not end in comma or semi;
1192 ;; indent this line c-continued-statement-offset
1193 ;; more than previous.
1195 (c-backward-to-start-of-continued-exp (car contain-stack))
1197 (+ c-continued-statement-offset (current-column)
1198 (if at-brace c-continued-brace-offset 0))))
1199 ;; Preceding line ended in comma or semi;
1200 ;; use the standard indent for this level.
1201 (cond (at-else (progn (c-backward-to-start-of-if opoint)
1203 (current-indentation))))
1204 ((and at-while (c-backward-to-start-of-do opoint))
1205 (setq this-indent (current-indentation)))
1206 ((eq (preceding-char) ?\,)
1207 (goto-char this-point)
1208 (setq this-indent (calculate-c-indent)))
1209 (t (setq this-indent (car indent-stack))))))))
1210 ;; Just started a new nesting level.
1211 ;; Compute the standard indent for this level.
1212 (let ((val (calculate-c-indent
1213 (if (car indent-stack)
1214 (- (car indent-stack))
1216 ;; t means we are in a block comment and should
1217 ;; calculate accordingly.
1219 (setq val (calculate-c-indent-within-comment)))
1220 (setcar indent-stack
1221 (setq this-indent val))))
1222 ;; Adjust line indentation according to its contents
1223 (if (or (looking-at c-switch-label-regexp)
1224 (and (looking-at "[A-Za-z]")
1228 (setq this-indent (max 1 (+ this-indent c-label-offset))))
1229 (if (= (following-char) ?})
1230 (setq this-indent (- this-indent c-indent-level)))
1231 (if (= (following-char) ?{)
1232 ;; Don't move an open-brace in column 0.
1233 ;; This is good when constructs such as
1234 ;; `extern "C" {' surround a function definition
1235 ;; that should be indented as usual.
1236 ;; It is also good for nested functions.
1237 ;; It is bad when an open-brace is indented at column 0
1238 ;; and you want to fix that, but we can't win 'em all.
1239 (if (zerop (current-column))
1240 (setq this-indent 0)
1241 (setq this-indent (+ this-indent c-brace-offset))))
1242 ;; Don't leave indentation in empty lines.
1243 (if (eolp) (setq this-indent 0))
1244 ;; Put chosen indentation into effect.
1245 (or (= (current-column) this-indent)
1246 (= (following-char) ?\#)
1248 (delete-region (point) (progn (beginning-of-line) (point)))
1249 (indent-to this-indent)))
1250 ;; Indent any comment following the text.
1251 (or (looking-at comment-start-skip)
1252 (let ((beg (point)))
1253 (and (re-search-forward
1255 (save-excursion (end-of-line) (point)) t)
1256 ;; Make sure the comment starter we found
1257 ;; is not actually in a string or quoted.
1259 (parse-partial-sexp beg (point)
1261 (and (not (nth 3 new-state)) (not (nth 5 new-state))))
1262 (progn (indent-for-comment) (beginning-of-line)))))))))))
1264 ;; Look at all comment-start strings in the current line after point.
1265 ;; Return t if one of them starts a real comment.
1266 ;; This is not used yet, because indent-for-comment
1267 ;; isn't smart enough to handle the cases this can find.
1268 (defun indent-c-find-real-comment ()
1270 (while (and (not win)
1271 (re-search-forward comment-start-skip
1272 (save-excursion (end-of-line) (point))
1274 ;; Make sure the comment start is not quoted.
1277 (save-excursion (beginning-of-line) (point))
1278 (point) nil nil state)))
1279 (setq win (and (null (nth 3 state-1)) (null (nth 5 state-1))))))
1282 ;; Indent every line whose first char is between START and END inclusive.
1283 (defun c-indent-region (start end)
1286 ;; Advance to first nonblank line.
1287 (skip-chars-forward " \t\n")
1289 (let ((endmark (copy-marker end))
1290 (c-tab-always-indent t))
1291 (while (and (bolp) (not (eobp)) (< (point) endmark))
1292 ;; Indent one line as with TAB.
1293 (let ((shift-amt (c-indent-line))
1294 nextline sexpbeg sexpend)
1295 (if (save-excursion (beginning-of-line) (looking-at "[ \t]*#"))
1298 ;; Find beginning of following line.
1300 (forward-line 1) (setq nextline (point)))
1301 ;; Find first beginning-of-sexp for sexp extending past this line.
1303 (while (< (point) nextline)
1307 (setq sexpend (point-marker)))
1308 (error (setq sexpend nil)
1309 (goto-char nextline)))
1310 (skip-chars-forward " \t\n"))
1313 ;; Make sure the sexp we found really starts on the
1314 ;; current line and extends past it.
1317 (setq sexpbeg (point)))))
1318 ;; If that sexp ends within the region,
1319 ;; indent it all at once, fast.
1320 (if (and sexpend (> sexpend nextline) (<= sexpend endmark)
1321 (< sexpbeg nextline))
1324 (goto-char sexpend)))
1325 ;; Move to following line and try again.
1326 (and sexpend (set-marker sexpend nil))
1328 (set-marker endmark nil))))
1330 (defun set-c-style (style &optional global)
1331 "Set C-mode variables to use one of several different indentation styles.
1332 The arguments are a string representing the desired style
1333 and a flag which, if non-nil, means to set the style globally.
1334 \(Interactively, the flag comes from the prefix argument.)
1335 Available styles are GNU, K&R, BSD and Whitesmith."
1336 (interactive (list (completing-read "Use which C indentation style? "
1337 c-style-alist nil t)
1338 current-prefix-arg))
1339 (let ((vars (cdr (assoc style c-style-alist))))
1341 (error "Invalid C indentation style `%s'" style))
1344 (make-local-variable (car (car vars))))
1345 (set (car (car vars)) (cdr (car vars)))
1346 (setq vars (cdr vars)))))
1348 ;;; This page handles insertion and removal of backslashes for C macros.
1350 (defvar c-backslash-column 48
1351 "*Minimum column for end-of-line backslashes of macro definitions.")
1353 (defun c-backslash-region (from to delete-flag)
1354 "Insert, align, or delete end-of-line backslashes on the lines in the region.
1355 With no argument, inserts backslashes and aligns existing backslashes.
1356 With an argument, deletes the backslashes.
1358 This function does not modify the last line of the region if the region ends
1359 right at the start of the following line; it does not modify blank lines
1360 at the start of the region. So you can put the region around an entire macro
1361 definition and conveniently use this command."
1362 (interactive "r\nP")
1365 (let ((column c-backslash-column)
1366 (endmark (make-marker)))
1367 (move-marker endmark to)
1368 ;; Compute the smallest column number past the ends of all the lines.
1369 (if (not delete-flag)
1370 (while (< (point) to)
1372 (if (= (preceding-char) ?\\)
1373 (progn (forward-char -1)
1374 (skip-chars-backward " \t")))
1375 (setq column (max column (1+ (current-column))))
1377 ;; Adjust upward to a tab column, if that doesn't push past the margin.
1378 (if (> (% column tab-width) 0)
1379 (let ((adjusted (* (/ (+ column tab-width -1) tab-width) tab-width)))
1380 (if (< adjusted (window-width))
1381 (setq column adjusted))))
1382 ;; Don't modify blank lines at start of region.
1384 (while (and (< (point) endmark) (eolp))
1386 ;; Add or remove backslashes on all the lines.
1387 (while (and (< (point) endmark)
1388 ;; Don't backslashify the last line
1389 ;; if the region ends right at the start of the next line.
1392 (< (point) endmark)))
1393 (if (not delete-flag)
1394 (c-append-backslash column)
1395 (c-delete-backslash))
1397 (move-marker endmark nil))))
1399 (defun c-append-backslash (column)
1401 ;; Note that "\\\\" is needed to get one backslash.
1402 (if (= (preceding-char) ?\\)
1403 (progn (forward-char -1)
1404 (delete-horizontal-space)
1409 (defun c-delete-backslash ()
1414 (if (looking-at "\\\\")
1415 (delete-region (1+ (point))
1416 (progn (skip-chars-backward " \t") (point)))))))
1418 (defun c-up-conditional (count)
1419 "Move back to the containing preprocessor conditional, leaving mark behind.
1420 A prefix argument acts as a repeat count. With a negative argument,
1421 move forward to the end of the containing preprocessor conditional.
1422 When going backwards, `#elif' is treated like `#else' followed by `#if'.
1423 When going forwards, `#elif' is ignored."
1425 (c-forward-conditional (- count) t))
1427 (defun c-backward-conditional (count &optional up-flag)
1428 "Move back across a preprocessor conditional, leaving mark behind.
1429 A prefix argument acts as a repeat count. With a negative argument,
1430 move forward across a preprocessor conditional."
1432 (c-forward-conditional (- count) up-flag))
1434 (defun c-forward-conditional (count &optional up-flag)
1435 "Move forward across a preprocessor conditional, leaving mark behind.
1436 A prefix argument acts as a repeat count. With a negative argument,
1437 move backward across a preprocessor conditional."
1439 (let* ((forward (> count 0))
1440 (increment (if forward -1 1))
1441 (search-function (if forward 're-search-forward 're-search-backward))
1446 (let ((depth (if up-flag 0 -1)) found)
1448 ;; Find the "next" significant line in the proper direction.
1449 (while (and (not found)
1450 ;; Rather than searching for a # sign that comes
1451 ;; at the beginning of a line aside from whitespace,
1452 ;; search first for a string starting with # sign.
1453 ;; Then verify what precedes it.
1454 ;; This is faster on account of the fastmap feature of
1455 ;; the regexp matcher.
1456 (funcall search-function
1457 "#[ \t]*\\(if\\|elif\\|endif\\)"
1460 ;; Now verify it is really a preproc line.
1461 (if (looking-at "^[ \t]*#[ \t]*\\(if\\|elif\\|endif\\)")
1463 ;; Update depth according to what we found.
1465 (cond ((looking-at "[ \t]*#[ \t]*endif")
1466 (setq depth (+ depth increment)))
1467 ((looking-at "[ \t]*#[ \t]*elif")
1468 (if (and forward (= depth 0))
1469 (setq found (point))))
1470 (t (setq depth (- depth increment))))
1471 ;; If we are trying to move across, and we find
1472 ;; an end before we find a beginning, get an error.
1473 (if (and (< prev 0) (< depth prev))
1475 "No following conditional at this level"
1476 "No previous conditional at this level")))
1477 ;; When searching forward, start from next line
1478 ;; so that we don't find the same line again.
1479 (if forward (forward-line 1))
1480 ;; If this line exits a level of conditional, exit inner loop.
1482 (setq found (point)))))))
1484 (error "No containing preprocessor conditional"))
1485 (goto-char (setq new found)))
1486 (setq count (+ count increment))))
1490 ;;; c-mode.el ends here